1#!/usr/bin/env python3
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
17"""Unittests for vts_tf_test_runner."""
18
19# pylint: disable=line-too-long
20
21import unittest
22
23from unittest import mock
24
25from test_runners import vts_tf_test_runner
26
27# pylint: disable=protected-access
28class VtsTradefedTestRunnerUnittests(unittest.TestCase):
29    """Unit tests for vts_tf_test_runner.py"""
30
31    def setUp(self):
32        self.vts_tr = vts_tf_test_runner.VtsTradefedTestRunner(results_dir='')
33
34    def tearDown(self):
35        mock.patch.stopall()
36
37    @mock.patch('subprocess.Popen')
38    @mock.patch.object(vts_tf_test_runner.VtsTradefedTestRunner, 'run')
39    @mock.patch.object(vts_tf_test_runner.VtsTradefedTestRunner,
40                       'generate_run_commands')
41    def test_run_tests(self, _mock_gen_cmd, _mock_run, _mock_popen):
42        """Test run_tests method."""
43        test_infos = []
44        extra_args = []
45        mock_reporter = mock.Mock()
46        _mock_gen_cmd.return_value = ["cmd1", "cmd2"]
47        # Test Build Pass
48        _mock_popen.return_value.returncode = 0
49        self.assertEqual(
50            0,
51            self.vts_tr.run_tests(test_infos, extra_args, mock_reporter))
52
53        # Test Build Pass
54        _mock_popen.return_value.returncode = 1
55        self.assertNotEqual(
56            0,
57            self.vts_tr.run_tests(test_infos, extra_args, mock_reporter))
58
59
60if __name__ == '__main__':
61    unittest.main()
62