Skip to content

Commit 725935b

Browse files
committed
Add test capturing failure. Ref #110.
1 parent bf25257 commit 725935b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

importlib_metadata/tests/fixtures.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ def tempdir_as_cwd():
4747
yield tmp
4848

4949

50+
@contextlib.contextmanager
51+
def install_finder(finder):
52+
sys.meta_path.append(finder)
53+
try:
54+
yield
55+
finally:
56+
sys.meta_path.remove(finder)
57+
58+
5059
class Fixtures:
5160
def setUp(self):
5261
self.fixtures = ExitStack()
@@ -203,3 +212,8 @@ def build_files(file_defs, prefix=pathlib.Path()):
203212
def DALS(str):
204213
"Dedent and left-strip"
205214
return textwrap.dedent(str).lstrip()
215+
216+
217+
class NullFinder:
218+
def find_module(self, name):
219+
pass

importlib_metadata/tests/test_integration.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from . import fixtures
66
from .. import version
7+
from .. import _compat
78

89

910
class IntegrationTests(fixtures.DistInfoPkg, unittest.TestCase):
@@ -20,3 +21,20 @@ def is_installed(package_spec):
2021
assert is_installed('distinfo-pkg==1.0')
2122
assert is_installed('distinfo-pkg>=1.0,<2.0')
2223
assert not is_installed('distinfo-pkg<1.0')
24+
25+
26+
class FinderTests(fixtures.Fixtures, unittest.TestCase):
27+
28+
def test_finder_without_module(self):
29+
class ModuleFreeFinder(fixtures.NullFinder):
30+
"""
31+
A finder without an __module__ attribute
32+
"""
33+
def __getattribute__(self, name):
34+
if name == '__module__':
35+
raise AttributeError(name)
36+
return super().__getattribute__(name)
37+
38+
self.fixtures.enter_context(
39+
fixtures.install_finder(ModuleFreeFinder()))
40+
_compat.disable_stdlib_finder()

0 commit comments

Comments
 (0)