21
21
from tools .build_api import prepare_toolchain , build_project , build_library ,\
22
22
scan_resources
23
23
from tools .toolchains import TOOLCHAINS
24
+ from tools .notifier .mock import MockNotifier
24
25
25
26
"""
26
27
Tests for build_api.py
27
28
"""
28
29
make_mock_target = namedtuple (
29
30
"Target" , "init_hooks name features core supported_toolchains" )
30
31
32
+
31
33
class BuildApiTests (unittest .TestCase ):
32
34
"""
33
35
Test cases for Build Api
@@ -61,19 +63,19 @@ def tearDown(self):
61
63
@patch ('tools.toolchains.mbedToolchain.dump_build_profile' )
62
64
@patch ('tools.utils.run_cmd' , return_value = (b'' , b'' , 0 ))
63
65
def test_always_complete_build (self , * _ ):
64
- with MagicMock () as notify :
65
- toolchain = prepare_toolchain (self .src_paths , self .build_path , self .target ,
66
- self .toolchain_name , notify = notify )
66
+ notify = MockNotifier ()
67
+ toolchain = prepare_toolchain (self .src_paths , self .build_path , self .target ,
68
+ self .toolchain_name , notify = notify )
67
69
68
- res = scan_resources (self .src_paths , toolchain )
70
+ res = scan_resources (self .src_paths , toolchain )
69
71
70
- toolchain .RESPONSE_FILES = False
71
- toolchain .config_processed = True
72
- toolchain .config_file = "junk"
73
- toolchain .compile_sources (res )
72
+ toolchain .RESPONSE_FILES = False
73
+ toolchain .config_processed = True
74
+ toolchain .config_file = "junk"
75
+ toolchain .compile_sources (res )
74
76
75
- assert any ('percent' in msg [ 0 ] and msg [ 0 ] ['percent' ] == 100.0
76
- for _ , msg , _ in notify .mock_calls if msg )
77
+ assert any ('percent' in msg and msg ['percent' ] == 100.0
78
+ for msg in notify .messages if msg )
77
79
78
80
79
81
@patch ('tools.build_api.Config' )
@@ -128,14 +130,15 @@ def test_build_project_app_config(self, mock_prepare_toolchain, mock_exists, _,
128
130
:param __: mock of function scan_resources (not tested)
129
131
:return:
130
132
"""
133
+ notify = MockNotifier ()
131
134
app_config = "app_config"
132
135
mock_exists .return_value = False
133
136
mock_prepare_toolchain ().link_program .return_value = 1 , 2
134
137
mock_prepare_toolchain ().config = namedtuple (
135
138
"Config" , "has_regions name lib_config_data" )(None , None , {})
136
139
137
140
build_project (self .src_paths , self .build_path , self .target ,
138
- self .toolchain_name , app_config = app_config )
141
+ self .toolchain_name , app_config = app_config , notify = notify )
139
142
140
143
args = mock_prepare_toolchain .call_args
141
144
self .assertTrue ('app_config' in args [1 ],
@@ -157,14 +160,15 @@ def test_build_project_no_app_config(self, mock_prepare_toolchain, mock_exists,
157
160
:param __: mock of function scan_resources (not tested)
158
161
:return:
159
162
"""
163
+ notify = MockNotifier ()
160
164
mock_exists .return_value = False
161
165
# Needed for the unpacking of the returned value
162
166
mock_prepare_toolchain ().link_program .return_value = 1 , 2
163
167
mock_prepare_toolchain ().config = namedtuple (
164
168
"Config" , "has_regions name lib_config_data" )(None , None , {})
165
169
166
170
build_project (self .src_paths , self .build_path , self .target ,
167
- self .toolchain_name )
171
+ self .toolchain_name , notify = notify )
168
172
169
173
args = mock_prepare_toolchain .call_args
170
174
self .assertTrue ('app_config' in args [1 ],
@@ -186,11 +190,12 @@ def test_build_library_app_config(self, mock_prepare_toolchain, mock_exists, _,
186
190
:param __: mock of function scan_resources (not tested)
187
191
:return:
188
192
"""
193
+ notify = MockNotifier ()
189
194
app_config = "app_config"
190
195
mock_exists .return_value = False
191
196
192
197
build_library (self .src_paths , self .build_path , self .target ,
193
- self .toolchain_name , app_config = app_config )
198
+ self .toolchain_name , app_config = app_config , notify = notify )
194
199
195
200
args = mock_prepare_toolchain .call_args
196
201
self .assertTrue ('app_config' in args [1 ],
@@ -212,10 +217,11 @@ def test_build_library_no_app_config(self, mock_prepare_toolchain, mock_exists,
212
217
:param __: mock of function scan_resources (not tested)
213
218
:return:
214
219
"""
220
+ notify = MockNotifier ()
215
221
mock_exists .return_value = False
216
222
217
223
build_library (self .src_paths , self .build_path , self .target ,
218
- self .toolchain_name )
224
+ self .toolchain_name , notify = notify )
219
225
220
226
args = mock_prepare_toolchain .call_args
221
227
self .assertTrue ('app_config' in args [1 ],
0 commit comments