1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
15 from yardstick.benchmark.runners import base
16 from yardstick.benchmark.runners import iteration
19 class ActionTestCase(unittest.TestCase):
21 @mock.patch("yardstick.benchmark.runners.base.subprocess")
22 def test__execute_shell_command(self, mock_subprocess):
23 mock_subprocess.check_output.side_effect = Exception()
25 self.assertEqual(base._execute_shell_command("")[0], -1)
27 @mock.patch("yardstick.benchmark.runners.base.subprocess")
28 def test__single_action(self, mock_subprocess):
29 mock_subprocess.check_output.side_effect = Exception()
31 base._single_action(0, "echo", mock.MagicMock())
33 @mock.patch("yardstick.benchmark.runners.base.subprocess")
34 def test__periodic_action(self, mock_subprocess):
35 mock_subprocess.check_output.side_effect = Exception()
37 base._periodic_action(0, "echo", mock.MagicMock())
40 class RunnerTestCase(unittest.TestCase):
43 self.runner = iteration.IterationRunner({})
45 @mock.patch("yardstick.benchmark.runners.iteration.multiprocessing")
46 def test_get_output(self, *args):
47 self.runner.output_queue.put({'case': 'opnfv_yardstick_tc002'})
48 self.runner.output_queue.put({'criteria': 'PASS'})
51 'case': 'opnfv_yardstick_tc002',
57 if not self.runner.output_queue.empty():
59 actual_result = self.runner.get_output()
60 self.assertEqual(idle_result, actual_result)
62 @mock.patch("yardstick.benchmark.runners.iteration.multiprocessing")
63 def test_get_result(self, *args):
64 self.runner.result_queue.put({'case': 'opnfv_yardstick_tc002'})
65 self.runner.result_queue.put({'criteria': 'PASS'})
68 {'case': 'opnfv_yardstick_tc002'},
74 if not self.runner.result_queue.empty():
76 actual_result = self.runner.get_result()
77 self.assertEqual(idle_result, actual_result)
79 def test__run_benchmark(self):
80 runner = base.Runner(mock.Mock())
82 with self.assertRaises(NotImplementedError):
83 runner._run_benchmark(mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock())
90 if __name__ == '__main__':