• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright 2018, The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16"""Unittests for vts_tf_test_runner."""
17
18import unittest
19import mock
20
21# pylint: disable=import-error
22from test_runners import vts_tf_test_runner
23
24# pylint: disable=protected-access
25class VtsTradefedTestRunnerUnittests(unittest.TestCase):
26    """Unit tests for vts_tf_test_runner.py"""
27
28    def setUp(self):
29        self.vts_tr = vts_tf_test_runner.VtsTradefedTestRunner(results_dir='')
30
31    def tearDown(self):
32        mock.patch.stopall()
33
34    @mock.patch('subprocess.Popen')
35    @mock.patch.object(vts_tf_test_runner.VtsTradefedTestRunner, 'run')
36    @mock.patch.object(vts_tf_test_runner.VtsTradefedTestRunner,
37                       'generate_run_commands')
38    def test_run_tests(self, _mock_gen_cmd, _mock_run, _mock_popen):
39        """Test run_tests method."""
40        test_infos = []
41        extra_args = []
42        mock_reporter = mock.Mock()
43        _mock_gen_cmd.return_value = ["cmd1", "cmd2"]
44        # Test Build Pass
45        _mock_popen.return_value.returncode = 0
46        self.assertEqual(
47            0,
48            self.vts_tr.run_tests(test_infos, extra_args, mock_reporter))
49
50        # Test Build Pass
51        _mock_popen.return_value.returncode = 1
52        self.assertNotEqual(
53            0,
54            self.vts_tr.run_tests(test_infos, extra_args, mock_reporter))
55
56
57if __name__ == '__main__':
58    unittest.main()
59