Merge "tg_rfc2544_ixia: use traffic id from JSON to update mac"
[yardstick.git] / tests / unit / benchmark / runner / test_base.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 from __future__ import print_function
13 from __future__ import absolute_import
14
15 import unittest
16 import time
17
18 from mock import mock
19
20 from yardstick.benchmark.runners.base import Runner
21 from yardstick.benchmark.runners.iteration import IterationRunner
22
23
24 class RunnerTestCase(unittest.TestCase):
25
26     @mock.patch("yardstick.benchmark.runners.iteration.multiprocessing")
27     def test_get_output(self, mock_process):
28         runner = IterationRunner({})
29         runner.output_queue.put({'case': 'opnfv_yardstick_tc002'})
30         runner.output_queue.put({'criteria': 'PASS'})
31
32         idle_result = {
33             'case': 'opnfv_yardstick_tc002',
34             'criteria': 'PASS'
35         }
36
37         for retries in range(1000):
38             time.sleep(0.01)
39             if not runner.output_queue.empty():
40                 break
41         actual_result = runner.get_output()
42         self.assertEqual(idle_result, actual_result)
43
44     def test__run_benchmark(self):
45         runner = Runner(mock.Mock())
46
47         with self.assertRaises(NotImplementedError):
48             runner._run_benchmark(mock.Mock(), mock.Mock(), mock.Mock(), mock.Mock())
49
50
51 def main():
52     unittest.main()
53
54
55 if __name__ == '__main__':
56     main()