Skip to content

Commit

Permalink
Produce expected output during tests
Browse files Browse the repository at this point in the history
pkg_req.extras and pkg_req.specs are stored in Sets and thus ordering
can't be predicted.
  • Loading branch information
ticosax committed Jul 7, 2017
1 parent 659c4af commit 44812d9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
4 changes: 2 additions & 2 deletions tests/reqfiles/extras_1.expected
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"editable": false,
"uri": null,
"extras": [
"foo",
"bar"
"bar",
"foo"
],
"vcs": null,
"path": null,
Expand Down
8 changes: 4 additions & 4 deletions tests/reqfiles/illustrative_requirements.expected
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
"hash_name": null,
"hash": null,
"specs": [
[
">=",
"1.5"
],
[
"<",
"1.6"
],
[
">=",
"1.5"
]
],
"revision": null
Expand Down
25 changes: 5 additions & 20 deletions tests/reqfiles/specs_1.expected
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,11 @@
"hash_name": null,
"hash": null,
"specs": [
[
"<",
"1.6"
],
[
">",
"1.9"
],
[
"!=",
"1.9.6"
],
[
"<",
"2.0a0"
],
[
"==",
"2.4c1"
]
["!=", "1.9.6"],
["<", "1.6"],
["<", "2.0a0"],
["==", "2.4c1"],
[">", "1.9"]
],
"revision": null
}
Expand Down
14 changes: 9 additions & 5 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ def listify(iterable):
out = []
for item in iterable:
if isinstance(item, dict):
for key in item:
if isinstance(item[key], tuple) or isinstance(item[key], list):
item[key] = listify(item[key])
elif isinstance(item, tuple) or isinstance(item, list):
for key, value in item.items():
if isinstance(item[key], (tuple, list)):
if key in ('extras', 'specs'):
# enforce predictability
item[key] = sorted(listify(value))
else:
item[key] = listify(value)
elif isinstance(item, (tuple, list)):
item = listify(item)
out.append(item)
return out
Expand All @@ -38,7 +42,7 @@ def check_fail(s):
def check(s, expected):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
assert_equal(listify([dict(r) for r in parse(s)]), expected)
assert_equal(listify(dict(r) for r in parse(s)), expected)

fp = os.path.join(REQFILE_DIR, fn)

Expand Down

0 comments on commit 44812d9

Please sign in to comment.