fix: add lists param for load_entry_points() function
wuttasync needs to let various projects define import/export handlers using the same key, so it needs a way to discover them all without this logic auto-discarding duplicate keys
This commit is contained in:
parent
17efdb9572
commit
35a0897b21
4 changed files with 74 additions and 14 deletions
|
|
@ -184,6 +184,46 @@ class TestLoadEntryPoints(TestCase):
|
|||
entry_points.select.assert_called_once_with(group="wuttatest.thingers")
|
||||
entry_point.load.assert_called_once_with()
|
||||
|
||||
def test_duplicate_key(self):
|
||||
|
||||
# two entry points, with same name
|
||||
ep1 = MagicMock()
|
||||
ep2 = MagicMock()
|
||||
ep1.name = "not-quite-unique-key"
|
||||
ep2.name = "not-quite-unique-key"
|
||||
ep1.load.return_value = ep1
|
||||
ep2.load.return_value = ep2
|
||||
|
||||
# they both are included for "all" entry points
|
||||
entry_points = MagicMock()
|
||||
entry_points.select.return_value = [ep1, ep2]
|
||||
importlib = MagicMock()
|
||||
importlib.metadata.entry_points.return_value = entry_points
|
||||
with patch.dict("sys.modules", **{"importlib": importlib}):
|
||||
|
||||
# but only the 2nd entry point is returned
|
||||
result = mod.load_entry_points("console_scripts")
|
||||
self.assertIsInstance(result, dict)
|
||||
self.assertGreaterEqual(len(result), 1)
|
||||
self.assertIn("not-quite-unique-key", result)
|
||||
self.assertIs(result["not-quite-unique-key"], ep2)
|
||||
|
||||
def test_lists(self):
|
||||
|
||||
# classic behvaior
|
||||
result = mod.load_entry_points("console_scripts", lists=False)
|
||||
self.assertIsInstance(result, dict)
|
||||
self.assertIn("pip", result)
|
||||
self.assertTrue(callable(result["pip"]))
|
||||
|
||||
# lists behavior
|
||||
result = mod.load_entry_points("console_scripts", lists=True)
|
||||
self.assertIsInstance(result, dict)
|
||||
self.assertIn("pip", result)
|
||||
self.assertIsInstance(result["pip"], list)
|
||||
self.assertEqual(len(result["pip"]), 1)
|
||||
self.assertTrue(callable(result["pip"][0]))
|
||||
|
||||
|
||||
class TestLoadObject(TestCase):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue