16
16
"""
17
17
18
18
import unittest
19
- from mock import patch
20
- from tools .build_api import prepare_toolchain , build_project , build_library
19
+ from collections import namedtuple
20
+ from mock import patch , MagicMock
21
+ from tools .build_api import prepare_toolchain , build_project , build_library ,\
22
+ scan_resources
21
23
22
24
"""
23
25
Tests for build_api.py
@@ -47,7 +49,30 @@ def tearDown(self):
47
49
"""
48
50
pass
49
51
50
- @patch ('tools.config.Config.__init__' )
52
+ @patch ('tools.toolchains.arm.ARM_STD.parse_dependencies' ,
53
+ return_value = ["foo" ])
54
+ @patch ('tools.toolchains.mbedToolchain.need_update' ,
55
+ side_effect = [i % 2 for i in range (3000 )])
56
+ @patch ('os.mkdir' )
57
+ @patch ('tools.toolchains.exists' , return_value = True )
58
+ @patch ('tools.utils.run_cmd' , return_value = ("" , "" , 0 ))
59
+ def test_always_complete_build (self , * _ ):
60
+ with MagicMock () as notify :
61
+ toolchain = prepare_toolchain (self .src_paths , self .target ,
62
+ self .toolchain_name , notify = notify )
63
+
64
+ res = scan_resources (self .src_paths , toolchain )
65
+
66
+ toolchain .RESPONSE_FILES = False
67
+ toolchain .config_processed = True
68
+ toolchain .config_file = "junk"
69
+ toolchain .compile_sources (res , self .build_path )
70
+
71
+ assert any ('percent' in msg [0 ] and msg [0 ]['percent' ] == 100.0
72
+ for _ , msg , _ in notify .mock_calls if msg )
73
+
74
+
75
+ @patch ('tools.build_api.Config' )
51
76
def test_prepare_toolchain_app_config (self , mock_config_init ):
52
77
"""
53
78
Test that prepare_toolchain uses app_config correctly
@@ -56,28 +81,34 @@ def test_prepare_toolchain_app_config(self, mock_config_init):
56
81
:return:
57
82
"""
58
83
app_config = "app_config"
59
- mock_config_init .return_value = None
84
+ mock_config_init .return_value = namedtuple ("Config" , "target" )(
85
+ namedtuple ("Target" ,
86
+ "init_hooks name features core" )(lambda _ , __ : None ,
87
+ "Junk" , [], "Cortex-M3" ))
60
88
61
89
prepare_toolchain (self .src_paths , self .target , self .toolchain_name ,
62
90
app_config = app_config )
63
91
64
- mock_config_init .assert_called_with (self .target , self .src_paths ,
65
- app_config = app_config )
92
+ mock_config_init .assert_called_once_with (self .target , self .src_paths ,
93
+ app_config = app_config )
66
94
67
- @patch ('tools.config .Config.__init__ ' )
95
+ @patch ('tools.build_api .Config' )
68
96
def test_prepare_toolchain_no_app_config (self , mock_config_init ):
69
97
"""
70
98
Test that prepare_toolchain correctly deals with no app_config
71
99
72
100
:param mock_config_init: mock of Config __init__
73
101
:return:
74
102
"""
75
- mock_config_init .return_value = None
103
+ mock_config_init .return_value = namedtuple ("Config" , "target" )(
104
+ namedtuple ("Target" ,
105
+ "init_hooks name features core" )(lambda _ , __ : None ,
106
+ "Junk" , [], "Cortex-M3" ))
76
107
77
108
prepare_toolchain (self .src_paths , self .target , self .toolchain_name )
78
109
79
- mock_config_init .assert_called_with (self .target , self .src_paths ,
80
- app_config = None )
110
+ mock_config_init .assert_called_once_with (self .target , self .src_paths ,
111
+ app_config = None )
81
112
82
113
@patch ('tools.build_api.scan_resources' )
83
114
@patch ('tools.build_api.mkdir' )
0 commit comments