Skip to content

Simplify TestCase.assertExpected() #2815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions test/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def remove_prefix_suffix(text, prefix, suffix):
expected_file += "_" + subname
subname_output = " ({})".format(subname)
expected_file += "_expect.pkl"
expected = None

def accept_output(update_type):
print("Accepting {} for {}{}:\n\n{}".format(update_type, munged_id, subname_output, output))
Expand All @@ -142,21 +141,19 @@ def accept_output(update_type):
if e.errno != errno.ENOENT:
raise
elif ACCEPT:
return accept_output("output")
accept_output("output")
return
else:
raise RuntimeError(
("I got this output for {}{}:\n\n{}\n\n"
"No expect file exists; to accept the current output, run:\n"
"python {} {} --accept").format(munged_id, subname_output, output, __main__.__file__, munged_id))

if ACCEPT:
equal = False
try:
equal = self.assertEqual(output, expected, prec=prec)
self.assertEqual(output, expected, prec=prec)
except Exception:
equal = False
if not equal:
return accept_output("updated output")
accept_output("updated output")
else:
self.assertEqual(output, expected, prec=prec)

Expand Down