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