mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
tests: Use assertEqual instead of custom diff code
This commit is contained in:
parent
3d5a5521aa
commit
7c072c0a32
1 changed files with 7 additions and 13 deletions
|
@ -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()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue