From 18974784806dda99d00156b78e8ad892a5dfc62c Mon Sep 17 00:00:00 2001 From: James Westman Date: Thu, 13 Jan 2022 00:02:41 -0600 Subject: [PATCH] tests: Exclude lines from coverage Exclude things like "raise NotImplementedError" and compiler bug handlers. --- .coveragerc | 6 ++++++ blueprintcompiler/errors.py | 2 +- tests/test_samples.py | 14 +++++++------- tests/test_tokenizer.py | 5 +---- 4 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..86fa04f --- /dev/null +++ b/.coveragerc @@ -0,0 +1,6 @@ +[report] +exclude_lines = + pragma: no cover + raise AssertionError + raise NotImplementedError + raise CompilerBugError diff --git a/blueprintcompiler/errors.py b/blueprintcompiler/errors.py index b5e8632..4ca73be 100644 --- a/blueprintcompiler/errors.py +++ b/blueprintcompiler/errors.py @@ -121,7 +121,7 @@ def assert_true(truth: bool, message:str=None): raise CompilerBugError(message) -def report_bug(): +def report_bug(): # pragma: no cover """ Report an error and ask people to report it. """ print(traceback.format_exc()) diff --git a/tests/test_samples.py b/tests/test_samples.py index 70553b4..94d0d99 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -46,11 +46,11 @@ class TestSamples(unittest.TestCase): raise MultipleErrors(ast.errors) actual = ast.generate() - if actual.strip() != expected.strip(): + if actual.strip() != expected.strip(): # pragma: no cover diff = difflib.unified_diff(expected.splitlines(), actual.splitlines()) print("\n".join(diff)) raise AssertionError() - except PrintableError as e: + except PrintableError as e: # pragma: no cover e.pretty_print(name + ".blp", blueprint) raise AssertionError() @@ -79,14 +79,14 @@ class TestSamples(unittest.TestCase): actual = error_str(e) elif isinstance(e, MultipleErrors): actual = "\n".join([error_str(error) for error in e.errors]) - else: + else: # pragma: no cover raise AssertionError() - if actual.strip() != expected.strip(): + if actual.strip() != expected.strip(): # pragma: no cover diff = difflib.unified_diff(expected.splitlines(), actual.splitlines()) print("\n".join(diff)) raise AssertionError() - else: + else: # pragma: no cover # Expected a compiler error but there wasn't one raise AssertionError() @@ -101,11 +101,11 @@ class TestSamples(unittest.TestCase): actual = decompiler.decompile(ui_path) - if actual.strip() != expected.strip(): + if actual.strip() != expected.strip(): # pragma: no cover diff = difflib.unified_diff(expected.splitlines(), actual.splitlines()) print("\n".join(diff)) raise AssertionError() - except PrintableError as e: + except PrintableError as e: # pragma: no cover e.pretty_print(name + ".blp", blueprint) raise AssertionError() diff --git a/tests/test_tokenizer.py b/tests/test_tokenizer.py index 67f9994..1dcb87b 100644 --- a/tests/test_tokenizer.py +++ b/tests/test_tokenizer.py @@ -32,7 +32,7 @@ class TestTokenizer(unittest.TestCase): for token, (type, token_str) in zip(tokens, expect): self.assertEqual(token.type, type) self.assertEqual(str(token), token_str) - except PrintableError as e: + except PrintableError as e: # pragma: no cover e.pretty_print("", string) raise e @@ -71,6 +71,3 @@ class TestTokenizer(unittest.TestCase): (TokenType.EOF, ""), ]) - -if __name__ == "__main__": - unittest.main()