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.
This commit is contained in:
James Westman 2024-11-03 14:36:51 -06:00
parent a529a61955
commit 3bf8fc151a
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
2 changed files with 8 additions and 7 deletions

View file

@ -1,3 +1,2 @@
3,10,12,Use type syntax here (introduced in blueprint 0.8.0) 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) 9,18,12,Use 'template' instead of the class name (introduced in 0.8.0)

View file

@ -130,18 +130,20 @@ class TestSamples(unittest.TestCase):
if len(warnings): if len(warnings):
raise MultipleErrors(warnings) raise MultipleErrors(warnings)
except PrintableError as e: 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): def error_str(error: CompileError):
line, col = utils.idx_to_pos(error.range.start + 1, blueprint) line, col = utils.idx_to_pos(error.range.start + 1, blueprint)
len = error.range.length len = error.range.length
return ",".join([str(line + 1), str(col), str(len), error.message]) return ",".join([str(line + 1), str(col), str(len), error.message])
if isinstance(e, CompileError): actual = "\n".join([error_str(error) for error in errors])
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()
self.assertEqual(actual.strip(), expected.strip()) self.assertEqual(actual.strip(), expected.strip())
else: # pragma: no cover else: # pragma: no cover