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