diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:24:48 +0000 |
commit | cca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch) | |
tree | 146f39ded1c938019e1ed42d30923c2ac9e86789 /share/extensions/tests/test_inkex_deprecated.py | |
parent | Initial commit. (diff) | |
download | inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip |
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | share/extensions/tests/test_inkex_deprecated.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/share/extensions/tests/test_inkex_deprecated.py b/share/extensions/tests/test_inkex_deprecated.py new file mode 100644 index 0000000..3ec1258 --- /dev/null +++ b/share/extensions/tests/test_inkex_deprecated.py @@ -0,0 +1,42 @@ +# coding=utf-8 +"""Test base inkex module functionality""" +from __future__ import absolute_import, print_function, unicode_literals +from pathlib import Path +import warnings + +from inkex.deprecated import _deprecated +from inkex.tester import TestCase + + +class DeprecatedTests(TestCase): + """Test ways in which we deprecate code""" + + maxDiff = 10000 + + def assertDeprecated( + self, call, msg, *args, **kwargs + ): # pylint: disable=invalid-name + """Catch deprecation warnings and test their output""" + with warnings.catch_warnings(record=True) as warns: + warnings.simplefilter("always") + call(*args, **kwargs) + if msg is None: + self.assertFalse(warns, "Expected no warnings, got warnings!") + else: + self.assertTrue(warns, "No warning was returned, expected warning!") + if msg is not False: + self.assertEqual( + str(warns[0].category.__name__), "DeprecationWarning" + ) + return warns[0] + + def test_warning(self): + """What happens when we deprecate things""" + self.assertDeprecated(_deprecated, None, "", stack=0, level=0) + self.assertDeprecated(_deprecated, "FOO", "FOO", stack=0, level=1) + + def test_traceback(self): + """Traceback is possible for deprecation warnings""" + warn = self.assertDeprecated(_deprecated, False, "BAR", stack=0, level=2) + self.assertIn(str(Path("inkex") / "deprecated"), str(warn.message)) + self.assertIn("test_inkex_deprecated.py", str(warn.message)) |