|
15 | 15 | limitations under the License.
|
16 | 16 | """
|
17 | 17 |
|
18 |
| -import unittest |
| 18 | +import pytest |
19 | 19 | from mock import patch
|
| 20 | +from tools.targets import set_targets_json_location |
20 | 21 | from tools.test_api import find_tests, build_tests
|
21 | 22 |
|
22 | 23 | """
|
23 | 24 | Tests for test_api.py
|
24 | 25 | """
|
25 | 26 |
|
26 |
| -class TestApiTests(unittest.TestCase): |
| 27 | +def setUp(self): |
27 | 28 | """
|
28 |
| - Test cases for Test Api |
| 29 | + Called before each test case |
| 30 | +
|
| 31 | + :return: |
| 32 | + """ |
| 33 | + self.base_dir = 'base_dir' |
| 34 | + self.target = "K64F" |
| 35 | + self.toolchain_name = "ARM" |
| 36 | + |
| 37 | +@pytest.mark.parametrize("base_dir", ["base_dir"]) |
| 38 | +@pytest.mark.parametrize("target", ["K64F"]) |
| 39 | +@pytest.mark.parametrize("toolchain_name", ["ARM"]) |
| 40 | +@pytest.mark.parametrize("app_config", ["app_config", None]) |
| 41 | +def test_find_tests_app_config(base_dir, target, toolchain_name, app_config): |
29 | 42 | """
|
| 43 | + Test find_tests for correct use of app_config |
30 | 44 |
|
31 |
| - def setUp(self): |
32 |
| - """ |
33 |
| - Called before each test case |
34 |
| -
|
35 |
| - :return: |
36 |
| - """ |
37 |
| - self.base_dir = 'base_dir' |
38 |
| - self.target = "K64F" |
39 |
| - self.toolchain_name = "ARM" |
40 |
| - |
41 |
| - def tearDown(self): |
42 |
| - """ |
43 |
| - Called after each test case |
44 |
| -
|
45 |
| - :return: |
46 |
| - """ |
47 |
| - pass |
48 |
| - |
49 |
| - @patch('tools.test_api.scan_resources') |
50 |
| - @patch('tools.test_api.prepare_toolchain') |
51 |
| - def test_find_tests_app_config(self, mock_prepare_toolchain, mock_scan_resources): |
52 |
| - """ |
53 |
| - Test find_tests for correct use of app_config |
54 |
| -
|
55 |
| - :param mock_prepare_toolchain: mock of function prepare_toolchain |
56 |
| - :param mock_scan_resources: mock of function scan_resources |
57 |
| - :return: |
58 |
| - """ |
59 |
| - app_config = "app_config" |
| 45 | + :param mock_prepare_toolchain: mock of function prepare_toolchain |
| 46 | + :param mock_scan_resources: mock of function scan_resources |
| 47 | + :return: |
| 48 | + """ |
| 49 | + set_targets_json_location() |
| 50 | + with patch('tools.test_api.scan_resources') as mock_scan_resources,\ |
| 51 | + patch('tools.test_api.prepare_toolchain') as mock_prepare_toolchain: |
60 | 52 | mock_scan_resources().inc_dirs.return_value = []
|
61 | 53 |
|
62 |
| - find_tests(self.base_dir, self.target, self.toolchain_name, app_config=app_config) |
| 54 | + find_tests(base_dir, target, toolchain_name, app_config=app_config) |
63 | 55 |
|
64 | 56 | args = mock_prepare_toolchain.call_args
|
65 |
| - self.assertTrue('app_config' in args[1], |
66 |
| - "prepare_toolchain was not called with app_config") |
67 |
| - self.assertEqual(args[1]['app_config'], app_config, |
68 |
| - "prepare_toolchain was called with an incorrect app_config") |
69 |
| - |
70 |
| - @patch('tools.test_api.scan_resources') |
71 |
| - @patch('tools.test_api.prepare_toolchain') |
72 |
| - def test_find_tests_no_app_config(self, mock_prepare_toolchain, mock_scan_resources): |
73 |
| - """ |
74 |
| - Test find_tests correctly deals with no app_config |
75 |
| -
|
76 |
| - :param mock_prepare_toolchain: mock of function prepare_toolchain |
77 |
| - :param mock_scan_resources: mock of function scan_resources |
78 |
| - :return: |
79 |
| - """ |
80 |
| - mock_scan_resources().inc_dirs.return_value = [] |
| 57 | + assert 'app_config' in args[1],\ |
| 58 | + "prepare_toolchain was not called with app_config" |
| 59 | + assert args[1]['app_config'] == app_config,\ |
| 60 | + "prepare_toolchain was called with an incorrect app_config" |
81 | 61 |
|
82 |
| - find_tests(self.base_dir, self.target, self.toolchain_name) |
83 | 62 |
|
84 |
| - args = mock_prepare_toolchain.call_args |
85 |
| - self.assertTrue('app_config' in args[1], |
86 |
| - "prepare_toolchain was not called with app_config") |
87 |
| - self.assertEqual(args[1]['app_config'], None, |
88 |
| - "prepare_toolchain was called with an incorrect app_config") |
89 |
| - |
90 |
| - @patch('tools.test_api.scan_resources') |
91 |
| - @patch('tools.test_api.build_project') |
92 |
| - def test_build_tests_app_config(self, mock_build_project, mock_scan_resources): |
93 |
| - """ |
94 |
| - Test build_tests for correct use of app_config |
95 |
| -
|
96 |
| - :param mock_prepare_toolchain: mock of function prepare_toolchain |
97 |
| - :param mock_scan_resources: mock of function scan_resources |
98 |
| - :return: |
99 |
| - """ |
100 |
| - tests = {'test1': 'test1_path','test2': 'test2_path'} |
101 |
| - src_paths = ['.'] |
102 |
| - build_path = "build_path" |
103 |
| - app_config = "app_config" |
104 |
| - mock_build_project.return_value = "build_project" |
105 |
| - |
106 |
| - build_tests(tests, src_paths, build_path, self.target, self.toolchain_name, |
107 |
| - app_config=app_config) |
| 63 | +@pytest.mark.parametrize("build_path", ["build_path"]) |
| 64 | +@pytest.mark.parametrize("target", ["K64F"]) |
| 65 | +@pytest.mark.parametrize("toolchain_name", ["ARM"]) |
| 66 | +@pytest.mark.parametrize("app_config", ["app_config", None]) |
| 67 | +def test_find_tests_app_config(build_path, target, toolchain_name, app_config): |
| 68 | + """ |
| 69 | + Test find_tests for correct use of app_config |
108 | 70 |
|
109 |
| - arg_list = mock_build_project.call_args_list |
110 |
| - for args in arg_list: |
111 |
| - self.assertTrue('app_config' in args[1], |
112 |
| - "build_tests was not called with app_config") |
113 |
| - self.assertEqual(args[1]['app_config'], app_config, |
114 |
| - "build_tests was called with an incorrect app_config") |
115 |
| - |
116 |
| - @patch('tools.test_api.scan_resources') |
117 |
| - @patch('tools.test_api.build_project') |
118 |
| - def test_build_tests_no_app_config(self, mock_build_project, mock_scan_resources): |
119 |
| - """ |
120 |
| - Test build_tests correctly deals with no app_config |
121 |
| -
|
122 |
| - :param mock_prepare_toolchain: mock of function prepare_toolchain |
123 |
| - :param mock_scan_resources: mock of function scan_resources |
124 |
| - :return: |
125 |
| - """ |
126 |
| - tests = {'test1': 'test1_path', 'test2': 'test2_path'} |
127 |
| - src_paths = ['.'] |
128 |
| - build_path = "build_path" |
| 71 | + :param mock_prepare_toolchain: mock of function prepare_toolchain |
| 72 | + :param mock_scan_resources: mock of function scan_resources |
| 73 | + :return: |
| 74 | + """ |
| 75 | + tests = {'test1': 'test1_path','test2': 'test2_path'} |
| 76 | + src_paths = ['.'] |
| 77 | + set_targets_json_location() |
| 78 | + with patch('tools.test_api.scan_resources') as mock_scan_resources,\ |
| 79 | + patch('tools.test_api.build_project') as mock_build_project: |
129 | 80 | mock_build_project.return_value = "build_project"
|
| 81 | + mock_scan_resources().inc_dirs.return_value = [] |
130 | 82 |
|
131 |
| - build_tests(tests, src_paths, build_path, self.target, self.toolchain_name) |
| 83 | + build_tests(tests, src_paths, build_path, target, toolchain_name, |
| 84 | + app_config=app_config) |
132 | 85 |
|
133 | 86 | arg_list = mock_build_project.call_args_list
|
134 | 87 | for args in arg_list:
|
135 |
| - self.assertTrue('app_config' in args[1], |
136 |
| - "build_tests was not called with app_config") |
137 |
| - self.assertEqual(args[1]['app_config'], None, |
138 |
| - "build_tests was called with an incorrect app_config") |
139 |
| - |
140 |
| -if __name__ == '__main__': |
141 |
| - unittest.main() |
| 88 | + assert 'app_config' in args[1],\ |
| 89 | + "build_tests was not called with app_config" |
| 90 | + assert args[1]['app_config'] == app_config,\ |
| 91 | + "build_tests was called with an incorrect app_config" |
0 commit comments