Skip to content

Commit f738351

Browse files
authored
Merge pull request #2859 from theotherjimmy/print-percent
Correct percent printing
2 parents 20756cb + 860ba3a commit f738351

File tree

4 files changed

+45
-11
lines changed

4 files changed

+45
-11
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ python:
33

44
script:
55
- PYTHONPATH=. python tools/test/config_test/config_test.py
6+
- PYTHONPATH=. python tools/test/build_api/build_api_test.py
67
- python tools/test/pylint.py
78
- py.test tools/test/toolchains/api.py
89
- python tools/test/memap/memap_test.py
@@ -21,3 +22,4 @@ install:
2122
- sudo pip install pytest
2223
- sudo pip install pylint
2324
- sudo pip install hypothesis
25+
- sudo pip install mock

tools/build_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def prepare_toolchain(src_paths, target, toolchain_name,
303303
src_paths = [src_paths[0]] + list(set(src_paths[1:]))
304304

305305
# If the configuration object was not yet created, create it now
306-
config = config or Config(target, src_paths)
306+
config = config or Config(target, src_paths, app_config=app_config)
307307
target = config.target
308308

309309
# Toolchain instance

tools/test/build_api/build_api_test.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
"""
1717

1818
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
2123

2224
"""
2325
Tests for build_api.py
@@ -47,7 +49,30 @@ def tearDown(self):
4749
"""
4850
pass
4951

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')
5176
def test_prepare_toolchain_app_config(self, mock_config_init):
5277
"""
5378
Test that prepare_toolchain uses app_config correctly
@@ -56,28 +81,34 @@ def test_prepare_toolchain_app_config(self, mock_config_init):
5681
:return:
5782
"""
5883
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"))
6088

6189
prepare_toolchain(self.src_paths, self.target, self.toolchain_name,
6290
app_config=app_config)
6391

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)
6694

67-
@patch('tools.config.Config.__init__')
95+
@patch('tools.build_api.Config')
6896
def test_prepare_toolchain_no_app_config(self, mock_config_init):
6997
"""
7098
Test that prepare_toolchain correctly deals with no app_config
7199
72100
:param mock_config_init: mock of Config __init__
73101
:return:
74102
"""
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"))
76107

77108
prepare_toolchain(self.src_paths, self.target, self.toolchain_name)
78109

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)
81112

82113
@patch('tools.build_api.scan_resources')
83114
@patch('tools.build_api.mkdir')

tools/toolchains/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ def compile_sources(self, resources, build_path, inc_dirs=None):
760760
'chroot': self.CHROOT
761761
})
762762
else:
763+
self.compiled += 1
763764
objects.append(object)
764765

765766
# Use queues/multiprocessing if cpu count is higher than setting

0 commit comments

Comments
 (0)