From 3bf8fc151a2bd3366e3a46cf22a5b323c0c620e4 Mon Sep 17 00:00:00 2001 From: James Westman Date: Sun, 3 Nov 2024 14:36:51 -0600 Subject: [PATCH] tests: Ignore deprecation warnings Ignore deprecation warnings in the error handling tests, except in the test specifically for deprecations. This prevents them from breaking if libraries introduce new deprecations. Fixes #178. --- tests/sample_errors/legacy_template.err | 1 - tests/test_samples.py | 14 ++++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/sample_errors/legacy_template.err b/tests/sample_errors/legacy_template.err index 79ad519..876b0cf 100644 --- a/tests/sample_errors/legacy_template.err +++ b/tests/sample_errors/legacy_template.err @@ -1,3 +1,2 @@ 3,10,12,Use type syntax here (introduced in blueprint 0.8.0) -8,1,6,Gtk.Dialog is deprecated 9,18,12,Use 'template' instead of the class name (introduced in 0.8.0) \ No newline at end of file diff --git a/tests/test_samples.py b/tests/test_samples.py index 00ef72a..fe90774 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -130,18 +130,20 @@ class TestSamples(unittest.TestCase): if len(warnings): raise MultipleErrors(warnings) except PrintableError as e: + # Ignore deprecation warnings because new versions of libraries can introduce + # new deprecations, which would cause the tests to fail + errors = [ + error + for error in (e.errors if isinstance(e, MultipleErrors) else [e]) + if (name == "deprecations" or not isinstance(error, DeprecatedWarning)) + ] def error_str(error: CompileError): line, col = utils.idx_to_pos(error.range.start + 1, blueprint) len = error.range.length return ",".join([str(line + 1), str(col), str(len), error.message]) - if isinstance(e, CompileError): - actual = error_str(e) - elif isinstance(e, MultipleErrors): - actual = "\n".join([error_str(error) for error in e.errors]) - else: # pragma: no cover - raise AssertionError() + actual = "\n".join([error_str(error) for error in errors]) self.assertEqual(actual.strip(), expected.strip()) else: # pragma: no cover