Skip to content

Commit 33e930f

Browse files
committed
tests: do more thorough API arg comparisons
Don't just compare the last dict(), compart all of args tuple() Signed-off-by: Cole Robinson <[email protected]>
1 parent 737e15b commit 33e930f

10 files changed

Lines changed: 62 additions & 38 deletions
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
{'content_type': 'text/plain',
2-
'file_name': 'bz-attach-get1.txt',
3-
'ids': [123456],
4-
'is_private': True,
5-
'summary': 'some desc'}
1+
('STRIPPED-BY-TESTSUITE',
2+
{'content_type': 'text/plain',
3+
'file_name': 'bz-attach-get1.txt',
4+
'ids': [123456],
5+
'is_private': True,
6+
'summary': 'some desc'})
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
{'comment': 'some comment to go with it',
2-
'content_type': 'text/x-patch',
3-
'file_name': 'bz-attach-get1.txt',
4-
'ids': ['123456'],
5-
'is_patch': True,
6-
'is_private': True,
7-
'summary': 'bz-attach-get1.txt'}
1+
('STRIPPED-BY-TESTSUITE',
2+
{'comment': 'some comment to go with it',
3+
'content_type': 'text/x-patch',
4+
'file_name': 'bz-attach-get1.txt',
5+
'ids': ['123456'],
6+
'is_patch': True,
7+
'is_private': True,
8+
'summary': 'bz-attach-get1.txt'})
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{'content_type': 'text/plain',
2-
'file_name': 'fake-file-name.txt',
3-
'ids': ['123456'],
4-
'summary': 'Some attachment description'}
1+
('STRIPPED-BY-TESTSUITE',
2+
{'content_type': 'text/plain',
3+
'file_name': 'fake-file-name.txt',
4+
'ids': ['123456'],
5+
'summary': 'Some attachment description'})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
(['112233'], {})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
(['663674'], {})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
(502352, {})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{'exclude_fields': ['bar'], 'include_fields': ['foo']}
1+
([123456], {'exclude_fields': ['bar'], 'include_fields': ['foo']})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
([663674], {})

tests/mockbackend.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,22 @@ def __helper(self, args):
3030
if isinstance(func_return, BaseException):
3131
raise func_return
3232

33-
if isinstance(func_args, dict):
34-
assert func_args == args[-1]
35-
elif func_args is not None:
36-
tests.utils.diff_compare(args[-1], func_args)
33+
filename = None
34+
expect_out = func_args
35+
if isinstance(func_args, str):
36+
filename = func_args
37+
expect_out = None
38+
39+
# Hack to strip out attachment content from the generated
40+
# test output, because it doesn't play well with the test
41+
# suite running on python2
42+
if "content-disposition" in str(args):
43+
largs = list(args)
44+
largs[0] = "STRIPPED-BY-TESTSUITE"
45+
args = tuple(largs)
46+
47+
if filename or expect_out:
48+
tests.utils.diff_compare(args, filename, expect_out)
3749

3850
if isinstance(func_return, dict):
3951
return func_return

tests/utils.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,32 @@ def fake_request(*args, **kwargs):
6464
return bz
6565

6666

67-
def diff_compare(inputdata, filename):
67+
def diff_compare(inputdata, filename, expect_out=None):
6868
"""Compare passed string output to contents of filename"""
69-
filename = tests_path(filename)
70-
71-
actual_out = inputdata
72-
if isinstance(inputdata, dict):
73-
actual_out = pprint.pformat(inputdata, width=81)
74-
if not actual_out.endswith("\n"):
75-
actual_out += "\n"
76-
77-
if not os.path.exists(filename) or tests.CLICONFIG.REGENERATE_OUTPUT:
78-
open(filename, "w").write(actual_out)
79-
expect_out = open(filename).read()
69+
def _process(data):
70+
if isinstance(data, tuple) and len(data) == 1:
71+
data = data[0]
72+
if isinstance(data, (dict, tuple)):
73+
out = pprint.pformat(data, width=81)
74+
else:
75+
out = str(data)
76+
if not out.endswith("\n"):
77+
out += "\n"
78+
return out
79+
80+
actual_out = _process(inputdata)
81+
82+
if filename:
83+
filename = tests_path(filename)
84+
if not os.path.exists(filename) or tests.CLICONFIG.REGENERATE_OUTPUT:
85+
open(filename, "w").write(actual_out)
86+
expect_out = open(filename).read()
87+
else:
88+
expect_out = _process(expect_out)
8089

8190
diff = "".join(difflib.unified_diff(expect_out.splitlines(1),
8291
actual_out.splitlines(1),
83-
fromfile=filename or '',
92+
fromfile=filename or "Manual input",
8493
tofile="Generated Output"))
8594
if diff:
8695
raise AssertionError("Conversion outputs did not match.\n%s" % diff)

0 commit comments

Comments
 (0)