From 5edd0d6ea258aab0cb8d4c72896c8822eea7b518 Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Mon, 26 Sep 2022 13:09:59 +0300 Subject: move `DemandLoadTargets` to tests Used only in tests, which test `mixins.PythonNamespaceWalker`, meaning I can't just remove it. Signed-off-by: Arthur Zamarin --- src/snakeoil/test/demandload.py | 30 ------------------------------ tests/test_demandload_usage.py | 32 +++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 33 deletions(-) delete mode 100644 src/snakeoil/test/demandload.py diff --git a/src/snakeoil/test/demandload.py b/src/snakeoil/test/demandload.py deleted file mode 100644 index 9ce8f5d..0000000 --- a/src/snakeoil/test/demandload.py +++ /dev/null @@ -1,30 +0,0 @@ -from . import mixins - - -class DemandLoadTargets(mixins.PythonNamespaceWalker): - - target_namespace = 'snakeoil' - ignore_all_import_failures = False - - def setup_method(self, method): - self._failures = [] - - def teardown_method(self, method): - msg = "\n".join(sorted(f"{target}: error {e}" for target, e in self._failures)) - assert not self._failures, "bad demandload targets:\n" + msg - - def test_demandload_targets(self): - for x in self.walk_namespace( - self.target_namespace, - ignore_failed_imports=self.ignore_all_import_failures): - self.check_space(x) - - def check_space(self, mod): - for attr in dir(mod): - try: - obj = getattr(mod, attr) - # force __getattribute__ to fire - getattr(obj, "__class__", None) - except ImportError as ie: - # hit one. - self._failures.append((f"{mod.__name__}: target {attr}", ie)) diff --git a/tests/test_demandload_usage.py b/tests/test_demandload_usage.py index bf0d188..79ccfe0 100644 --- a/tests/test_demandload_usage.py +++ b/tests/test_demandload_usage.py @@ -1,5 +1,31 @@ -from snakeoil.test.demandload import DemandLoadTargets +import pytest +from snakeoil.test import mixins -class TestDemandLoadTargets(DemandLoadTargets): - pass +class TestDemandLoadTargets(mixins.PythonNamespaceWalker): + + target_namespace = 'snakeoil' + ignore_all_import_failures = False + + @pytest.fixture(autouse=True) + def _setup(self): + self._failures = [] + yield + msg = "\n".join(sorted(f"{target}: error {e}" for target, e in self._failures)) + assert not self._failures, "bad demandload targets:\n" + msg + + def test_demandload_targets(self): + for x in self.walk_namespace( + self.target_namespace, + ignore_failed_imports=self.ignore_all_import_failures): + self.check_space(x) + + def check_space(self, mod): + for attr in dir(mod): + try: + obj = getattr(mod, attr) + # force __getattribute__ to fire + getattr(obj, "__class__", None) + except ImportError as ie: + # hit one. + self._failures.append((f"{mod.__name__}: target {attr}", ie)) -- cgit v1.2.3-65-gdbad