Skip to content

Commit 89e400a

Browse files
committed
Ensure that tests can run everywhere
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 11583a9 commit 89e400a

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

tests/data/pinned-requirements.txt-expected.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"tool_homepageurl": "https://github.com/nexB/python-inspector",
55
"tool_version": "0.5.0",
66
"options": [
7-
"--requirement /home/pombreda/w421/python-inspector/tests/data/pinned-requirements.txt",
87
"--index-url https://pypi.org/simple",
98
"--python-version 38",
109
"--operating-system linux",

tests/test_cli.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,24 @@ def check_requirements_resolution(
119119
)
120120

121121

122-
def check_json_results(result_file, expected_file, regen=REGEN_TEST_FIXTURES):
122+
def check_json_results(result_file, expected_file, clean=True, regen=REGEN_TEST_FIXTURES):
123123
"""
124124
Check the ``result_file`` JSON results against the ``expected_file``
125125
expected JSON results.
126126
127+
If ``clean`` is True, remove headers data that can change across runs to
128+
provide stable test resultys.
129+
127130
If ``regen`` is True the expected_file WILL BE overwritten with the new
128131
results from ``results_file``. This is convenient for updating tests
129132
expectations.
130133
"""
131134
with open(result_file) as res:
132135
results = json.load(res)
133136

137+
if clean:
138+
clean_results(results)
139+
134140
if regen:
135141
with open(expected_file, "w") as reg:
136142
json.dump(results, reg, indent=2, separators=(",", ": "))
@@ -139,9 +145,23 @@ def check_json_results(result_file, expected_file, regen=REGEN_TEST_FIXTURES):
139145
with open(expected_file) as res:
140146
expected = json.load(res)
141147

148+
if clean:
149+
clean_results(expected)
150+
142151
assert results == expected
143152

144153

154+
def clean_results(results):
155+
"""
156+
Return cleaned results removing transient values that can change across test
157+
runs.
158+
"""
159+
headers = results.get("headers", {})
160+
options = headers.get("options", [])
161+
headers["options"] = [o for o in options if not o.startswith("--requirement")]
162+
return results
163+
164+
145165
def run_cli(options, cli=resolve_dependencies, expected_rc=0, env=None):
146166
"""
147167
Run a command line resolution. Return a click.testing.Result object.

0 commit comments

Comments
 (0)