Unverified Commit 16ef312e authored by Vasilis Vryniotis's avatar Vasilis Vryniotis Committed by GitHub
Browse files

Simplify TestCase.assertExpected() (#2815)



* Removing unnecessary variable.

* Refactoring common_utils.py to remove unused vars.

* Removing unused value and changing use of accept_output.
Co-authored-by: default avatarvfdev <vfdev.5@gmail.com>
Co-authored-by: default avatarFrancisco Massa <fvsmassa@gmail.com>
parent 73de9abe
...@@ -127,7 +127,6 @@ class TestCase(unittest.TestCase): ...@@ -127,7 +127,6 @@ class TestCase(unittest.TestCase):
expected_file += "_" + subname expected_file += "_" + subname
subname_output = " ({})".format(subname) subname_output = " ({})".format(subname)
expected_file += "_expect.pkl" expected_file += "_expect.pkl"
expected = None
def accept_output(update_type): def accept_output(update_type):
print("Accepting {} for {}{}:\n\n{}".format(update_type, munged_id, subname_output, output)) print("Accepting {} for {}{}:\n\n{}".format(update_type, munged_id, subname_output, output))
...@@ -142,7 +141,8 @@ class TestCase(unittest.TestCase): ...@@ -142,7 +141,8 @@ class TestCase(unittest.TestCase):
if e.errno != errno.ENOENT: if e.errno != errno.ENOENT:
raise raise
elif ACCEPT: elif ACCEPT:
return accept_output("output") accept_output("output")
return
else: else:
raise RuntimeError( raise RuntimeError(
("I got this output for {}{}:\n\n{}\n\n" ("I got this output for {}{}:\n\n{}\n\n"
...@@ -150,13 +150,10 @@ class TestCase(unittest.TestCase): ...@@ -150,13 +150,10 @@ class TestCase(unittest.TestCase):
"python {} {} --accept").format(munged_id, subname_output, output, __main__.__file__, munged_id)) "python {} {} --accept").format(munged_id, subname_output, output, __main__.__file__, munged_id))
if ACCEPT: if ACCEPT:
equal = False
try: try:
equal = self.assertEqual(output, expected, prec=prec) self.assertEqual(output, expected, prec=prec)
except Exception: except Exception:
equal = False accept_output("updated output")
if not equal:
return accept_output("updated output")
else: else:
self.assertEqual(output, expected, prec=prec) self.assertEqual(output, expected, prec=prec)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment