diff options
Diffstat (limited to 'tests/test_scripts')
| -rw-r--r-- | tests/test_scripts/dummy.py | 20 | ||||
| -rw-r--r-- | tests/test_scripts/test_pdistreport.py | 34 | ||||
| -rw-r--r-- | tests/test_scripts/test_pshell.py | 38 |
3 files changed, 54 insertions, 38 deletions
diff --git a/tests/test_scripts/dummy.py b/tests/test_scripts/dummy.py index 5768f071e..758d3c9fd 100644 --- a/tests/test_scripts/dummy.py +++ b/tests/test_scripts/dummy.py @@ -154,26 +154,6 @@ class DummyBootstrap: } -class DummyEntryPoint: - def __init__(self, name, module): - self.name = name - self.module = module - - def load(self): - return self.module - - -class DummyPkgResources: - def __init__(self, entry_point_values): - self.entry_points = [] - - for name, module in entry_point_values.items(): - self.entry_points.append(DummyEntryPoint(name, module)) - - def iter_entry_points(self, name): - return self.entry_points - - class dummy_setup_logging: def __call__(self, config_uri, global_conf): self.config_uri = config_uri diff --git a/tests/test_scripts/test_pdistreport.py b/tests/test_scripts/test_pdistreport.py index 079722734..2bcaad0b3 100644 --- a/tests/test_scripts/test_pdistreport.py +++ b/tests/test_scripts/test_pdistreport.py @@ -1,3 +1,4 @@ +import email.message import unittest @@ -12,14 +13,14 @@ class TestPDistReportCommand(unittest.TestCase): def platform(): return 'myplatform' - pkg_resources = DummyPkgResources() + importlib_metadata = DummyImportlibMetadata() L = [] def out(*args): L.extend(args) result = self._callFUT( - pkg_resources=pkg_resources, platform=platform, out=out + importlib_metadata=importlib_metadata, platform=platform, out=out ) self.assertEqual(result, None) self.assertEqual( @@ -32,14 +33,14 @@ class TestPDistReportCommand(unittest.TestCase): return 'myplatform' working_set = (DummyDistribution('abc'), DummyDistribution('def')) - pkg_resources = DummyPkgResources(working_set) + importlib_metadata = DummyImportlibMetadata(working_set) L = [] def out(*args): L.extend(args) result = self._callFUT( - pkg_resources=pkg_resources, platform=platform, out=out + importlib_metadata=importlib_metadata, platform=platform, out=out ) self.assertEqual(result, None) self.assertEqual( @@ -54,31 +55,30 @@ class TestPDistReportCommand(unittest.TestCase): 'abc', '1', ' ', - '/projects/abc', + 'summary for name=\'abc\'', ' ', 'def', '1', ' ', - '/projects/def', + 'summary for name=\'def\'', ], ) -class DummyPkgResources: - def __init__(self, working_set=()): - self.working_set = working_set +class DummyImportlibMetadata: + def __init__(self, distributions=()): + self._distributions = distributions - def get_distribution(self, name): - return Version('1') + def distribution(self, name): + return DummyDistribution(name) - -class Version: - def __init__(self, version): - self.version = version + def distributions(self): + return iter(self._distributions) class DummyDistribution: def __init__(self, name): - self.project_name = name self.version = '1' - self.location = '/projects/%s' % name + self.metadata = email.message.Message() + self.metadata['Name'] = name + self.metadata['Summary'] = f'summary for {name=}' diff --git a/tests/test_scripts/test_pshell.py b/tests/test_scripts/test_pshell.py index de7e17496..a5eeee045 100644 --- a/tests/test_scripts/test_pshell.py +++ b/tests/test_scripts/test_pshell.py @@ -1,4 +1,5 @@ import os +import sys import unittest from . import dummy @@ -50,7 +51,10 @@ class TestPShellCommand(unittest.TestCase): return cmd def _makeEntryPoints(self, command, shells): - command.pkg_resources = dummy.DummyPkgResources(shells) + entry_points = [ + DummyEntryPoint(name, value) for name, value in shells.items() + ] + command.importlib_metadata = DummyImportlibMetadata(entry_points) def test_command_loads_default_shell(self): command = self._makeOne() @@ -430,3 +434,35 @@ class Test_main(unittest.TestCase): def test_it(self): result = self._callFUT(['pshell']) self.assertEqual(result, 2) + + +class DummyImportlibMetadata: + def __init__(self, entry_points): + self._entry_points = entry_points + + def entry_points(self): + return DummyEntryPoints(self._entry_points) + + +class DummyEntryPoints: + def __init__(self, entry_points): + self._entry_points = entry_points + + if sys.version_info >= (3, 10): + + def select(self, **kw): + return iter(self._entry_points) + + else: # pragma no cover + + def get(self, key): + return list(self._entry_points) + + +class DummyEntryPoint: + def __init__(self, name, value): + self.name = name + self.value = value + + def load(self): + return self.value |
