From ecf64a4f82c5d4c10974bce4d3f75f7563d6170b Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Sun, 6 Feb 2022 14:39:05 +0100 Subject: [PATCH] python pre 3.9 compatibily --- tests/plugins/test_plugins.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/plugins/test_plugins.py b/tests/plugins/test_plugins.py index 284421e9..4b1223f2 100644 --- a/tests/plugins/test_plugins.py +++ b/tests/plugins/test_plugins.py @@ -40,6 +40,14 @@ def _verify_module(module, plugin_module_name): _verify_module(obj, plugin_module_name) +def removesuffix(self: str, suffix: str) -> str: + # compatibility for pre 3.9 + if suffix and self.endswith(suffix): + return self[: -len(suffix)] + else: + return self[:] + + def test_plugins_correct_has_attr(): module = amqtt.plugins for file in glob(join(dirname(module.__file__), "**/*.py"), recursive=True): @@ -47,7 +55,8 @@ def test_plugins_correct_has_attr(): continue name = file.replace("/", ".") - name = name[name.find(module.__name__) : -3].removesuffix(".__init__") + name = name[name.find(module.__name__) : -3] + name = removesuffix(name, ".__init__") __import__(name)