TST: add test of plugin registry options
from ..plugin_registry import PluginRegistry
+from typing import Callable
-class RegistryTest(PluginRegistry):
+class TypedCallableRegistry(PluginRegistry[Callable[[int], int]]):
+ pass
+
+
+class GeneralCallableRegistry(PluginRegistry):
pass
def test_plugin_registry():
- plugins = RegistryTest()
+ plugins = TypedCallableRegistry()
assert plugins.names() == []
assert plugins.active == ''
assert plugins.get() is None
- assert repr(plugins) == "RegistryTest(active='', registered=[])"
+ assert repr(plugins) == "TypedCallableRegistry(active='', registered=[])"
plugins.register('new_plugin', lambda x: x ** 2)
assert plugins.names() == ['new_plugin']
assert plugins.active == ''
assert plugins.get() is None
- assert repr(plugins) == ("RegistryTest(active='', "
+ assert repr(plugins) == ("TypedCallableRegistry(active='', "
"registered=['new_plugin'])")
plugins.enable('new_plugin')
assert plugins.names() == ['new_plugin']
assert plugins.active == 'new_plugin'
assert plugins.get()(3) == 9
- assert repr(plugins) == ("RegistryTest(active='new_plugin', "
+ assert repr(plugins) == ("TypedCallableRegistry(active='new_plugin', "
"registered=['new_plugin'])")
+
+
+def test_plugin_registry_extra_options():
+ plugins = GeneralCallableRegistry()
+
+ plugins.register('metadata_plugin', lambda x, p=2: x ** p)
+ plugins.enable('metadata_plugin')
+ assert plugins.get()(3) == 9
+
+ plugins.enable('metadata_plugin', p=3)
+ assert plugins.get()(3) == 27
