New function to find component config checking entry points
authorKarl O. Pinc <kop@karlpinc.com>
Fri, 28 Aug 2020 21:40:20 +0000 (16:40 -0500)
committerKarl O. Pinc <kop@karlpinc.com>
Fri, 28 Aug 2020 21:40:20 +0000 (16:40 -0500)
src/pgwui_common/plugin.py
tests/test_plugin.py

index d5b97a75b25c444df0b3b6402295a0eec563a632..9a88175ecdf0ca0dd50ec97f0d5bf283cdafc8ba 100644 (file)
@@ -32,6 +32,17 @@ def find_pgwui_components():
             pkg_resources.iter_entry_points('pgwui.components')]
 
 
+def find_pgwui_check_settings():
+    '''Return dict of all pgwui.check_setting entry points, keyed by
+    component
+    '''
+    check_settings = dict()
+    for entry_point in pkg_resources.iter_entry_points('pgwui.check_settings'):
+        callable = entry_point.resolve()
+        check_settings[callable.__name__] = callable
+    return check_settings
+
+
 def component_to_key(component):
     '''Convert the component to a key used in an ini file's declaration
     '''
index 5521436cf98c33785a1e47216ff105c224980a1a..077f9256c86ed77cfe746e069bd081debf53def3 100644 (file)
 from pgwui_common import plugin
 
 
+# Helper classes
+class MockEntryPoint():
+    def __init__(self, val):
+        self.__name__ = val
+
+    def resolve(self):
+        return self
+
+
+class MockPkgResources():
+    def __init__(self, entry_points):
+        self.entry_points = entry_points
+
+    def iter_entry_points(self, *args):
+        return [MockEntryPoint(name) for name in self.entry_points]
+
+
 # find_pgwui_components()
 
 def test_find_pgwui_components(monkeypatch):
@@ -29,23 +46,27 @@ def test_find_pgwui_components(monkeypatch):
     '''
     entry_points = ['a', 'b', 'c']
 
-    class MockEntryPoint():
-        def __init__(self, val):
-            self.__name__ = val
+    monkeypatch.setattr(
+        plugin, 'pkg_resources', MockPkgResources(entry_points))
 
-        def resolve(self):
-            return self
+    result = plugin.find_pgwui_components()
+
+    assert result == entry_points
 
-    class MockPkgResources():
-        def iter_entry_points(*args):
-            return [MockEntryPoint(name) for name in entry_points]
+
+# find_pgwui_check_settings
+def test_find_pgwui_check_settings(monkeypatch):
+    '''Returns a dict, keyed by name, of entry points
+    '''
+    entry_points = ['a', 'b', 'c']
 
     monkeypatch.setattr(
-        plugin, 'pkg_resources', MockPkgResources())
+        plugin, 'pkg_resources', MockPkgResources(entry_points))
 
-    result = plugin.find_pgwui_components()
+    result = plugin.find_pgwui_check_settings()
 
-    assert result == entry_points
+    assert isinstance(result, dict)
+    assert list(result.keys()).sort() == entry_points.sort()
 
 
 # component_to_key()