tests: Use assertEqual instead of custom diff code

This commit is contained in:
James Westman 2023-09-28 17:13:02 -05:00
parent 3d5a5521aa
commit 7c072c0a32

View file

@ -18,7 +18,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later # SPDX-License-Identifier: LGPL-3.0-or-later
import difflib # I love Python
import unittest import unittest
from pathlib import Path from pathlib import Path
@ -41,6 +40,10 @@ from blueprintcompiler.tokenizer import Token, TokenType, tokenize
class TestSamples(unittest.TestCase): class TestSamples(unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.maxDiff = None
def assert_ast_doesnt_crash(self, text, tokens, ast): def assert_ast_doesnt_crash(self, text, tokens, ast):
for i in range(len(text)): for i in range(len(text)):
ast.get_docs(i) ast.get_docs(i)
@ -74,10 +77,7 @@ class TestSamples(unittest.TestCase):
xml = XmlOutput() xml = XmlOutput()
actual = xml.emit(ast) actual = xml.emit(ast)
if actual.strip() != expected.strip(): # pragma: no cover self.assertEqual(actual.strip(), expected.strip())
diff = difflib.unified_diff(expected.splitlines(), actual.splitlines())
print("\n".join(diff))
raise AssertionError()
self.assert_ast_doesnt_crash(blueprint, tokens, ast) self.assert_ast_doesnt_crash(blueprint, tokens, ast)
except PrintableError as e: # pragma: no cover except PrintableError as e: # pragma: no cover
@ -126,10 +126,7 @@ class TestSamples(unittest.TestCase):
else: # pragma: no cover else: # pragma: no cover
raise AssertionError() raise AssertionError()
if actual.strip() != expected.strip(): # pragma: no cover self.assertEqual(actual.strip(), expected.strip())
diff = difflib.unified_diff(expected.splitlines(), actual.splitlines())
print("\n".join(diff))
raise AssertionError()
else: # pragma: no cover else: # pragma: no cover
raise AssertionError("Expected a compiler error, but none was emitted") raise AssertionError("Expected a compiler error, but none was emitted")
@ -144,10 +141,7 @@ class TestSamples(unittest.TestCase):
actual = decompiler.decompile(ui_path) actual = decompiler.decompile(ui_path)
if actual.strip() != expected.strip(): # pragma: no cover self.assertEqual(actual.strip(), expected.strip())
diff = difflib.unified_diff(expected.splitlines(), actual.splitlines())
print("\n".join(diff))
raise AssertionError()
except PrintableError as e: # pragma: no cover except PrintableError as e: # pragma: no cover
e.pretty_print(name + ".blp", blueprint) e.pretty_print(name + ".blp", blueprint)
raise AssertionError() raise AssertionError()