Skip to content

Commit 79fbf94

Browse files
authored
Merge pull request #2893 from theotherjimmy/toolchain-test-cleanup
[Tests] Prevent garbage generation from toolchain api test
2 parents 5a55b39 + 6209aff commit 79fbf94

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

tools/test/toolchains/api.py

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
from string import printable
55
from copy import deepcopy
6-
from mock import MagicMock
6+
from mock import MagicMock, patch
77
from hypothesis import given
88
from hypothesis.strategies import text, lists, fixed_dictionaries
99

@@ -37,16 +37,17 @@ def test_toolchain_profile_c(profile, source_file):
3737
filename = deepcopy(source_file)
3838
filename[-1] += ".c"
3939
to_compile = os.path.join(*filename)
40-
for _, tc_class in TOOLCHAIN_CLASSES.items():
41-
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
42-
toolchain.inc_md5 = ""
43-
toolchain.build_dir = ""
44-
compile_command = toolchain.compile_command(to_compile,
45-
to_compile + ".o", [])
46-
for parameter in profile['c'] + profile['common']:
47-
assert any(parameter in cmd for cmd in compile_command), \
48-
"Toolchain %s did not propigate arg %s" % (toolchain.name,
49-
parameter)
40+
with patch('os.mkdir') as _mkdir:
41+
for _, tc_class in TOOLCHAIN_CLASSES.items():
42+
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
43+
toolchain.inc_md5 = ""
44+
toolchain.build_dir = ""
45+
compile_command = toolchain.compile_command(to_compile,
46+
to_compile + ".o", [])
47+
for parameter in profile['c'] + profile['common']:
48+
assert any(parameter in cmd for cmd in compile_command), \
49+
"Toolchain %s did not propigate arg %s" % (toolchain.name,
50+
parameter)
5051

5152
@given(fixed_dictionaries({
5253
'common': lists(text()),
@@ -61,16 +62,17 @@ def test_toolchain_profile_cpp(profile, source_file):
6162
filename = deepcopy(source_file)
6263
filename[-1] += ".cpp"
6364
to_compile = os.path.join(*filename)
64-
for _, tc_class in TOOLCHAIN_CLASSES.items():
65-
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
66-
toolchain.inc_md5 = ""
67-
toolchain.build_dir = ""
68-
compile_command = toolchain.compile_command(to_compile,
69-
to_compile + ".o", [])
70-
for parameter in profile['cxx'] + profile['common']:
71-
assert any(parameter in cmd for cmd in compile_command), \
72-
"Toolchain %s did not propigate arg %s" % (toolchain.name,
73-
parameter)
65+
with patch('os.mkdir') as _mkdir:
66+
for _, tc_class in TOOLCHAIN_CLASSES.items():
67+
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
68+
toolchain.inc_md5 = ""
69+
toolchain.build_dir = ""
70+
compile_command = toolchain.compile_command(to_compile,
71+
to_compile + ".o", [])
72+
for parameter in profile['cxx'] + profile['common']:
73+
assert any(parameter in cmd for cmd in compile_command), \
74+
"Toolchain %s did not propigate arg %s" % (toolchain.name,
75+
parameter)
7476

7577
@given(fixed_dictionaries({
7678
'common': lists(text()),
@@ -85,18 +87,19 @@ def test_toolchain_profile_asm(profile, source_file):
8587
filename = deepcopy(source_file)
8688
filename[-1] += ".s"
8789
to_compile = os.path.join(*filename)
88-
for _, tc_class in TOOLCHAIN_CLASSES.items():
89-
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
90-
toolchain.inc_md5 = ""
91-
toolchain.build_dir = ""
92-
compile_command = toolchain.compile_command(to_compile,
93-
to_compile + ".o", [])
94-
if not compile_command:
95-
assert compile_command, to_compile
96-
for parameter in profile['asm']:
97-
assert any(parameter in cmd for cmd in compile_command), \
98-
"Toolchain %s did not propigate arg %s" % (toolchain.name,
99-
parameter)
90+
with patch('os.mkdir') as _mkdir:
91+
for _, tc_class in TOOLCHAIN_CLASSES.items():
92+
toolchain = tc_class(TARGET_MAP["K64F"], build_profile=profile)
93+
toolchain.inc_md5 = ""
94+
toolchain.build_dir = ""
95+
compile_command = toolchain.compile_command(to_compile,
96+
to_compile + ".o", [])
97+
if not compile_command:
98+
assert compile_command, to_compile
99+
for parameter in profile['asm']:
100+
assert any(parameter in cmd for cmd in compile_command), \
101+
"Toolchain %s did not propigate arg %s" % (toolchain.name,
102+
parameter)
100103

101104
for name, Class in TOOLCHAIN_CLASSES.items():
102105
CLS = Class(TARGET_MAP["K64F"])

0 commit comments

Comments
 (0)