mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-23 14:53:12 -06:00
46: plugable.API now takes allowed base class in __init__ and creates Registrar at API.register, thereby coupling the two; updated correspending unit tests
This commit is contained in:
parent
2b3c2238f6
commit
d134b48306
@ -289,9 +289,15 @@ class Registrar(object):
|
||||
|
||||
|
||||
class API(ReadOnly):
|
||||
def __init__(self, registrar):
|
||||
def __init__(self, *allowed):
|
||||
object.__setattr__(self, 'register', Registrar(*allowed))
|
||||
object.__setattr__(self, '_API__plugins', [])
|
||||
for (base, plugins) in registrar:
|
||||
|
||||
def __call__(self):
|
||||
"""
|
||||
Finalize the registration, instantiate the plugins.
|
||||
"""
|
||||
for (base, plugins) in self.register:
|
||||
ns = NameSpace(self.__plugin_iter(base, plugins))
|
||||
assert not hasattr(self, base.__name__)
|
||||
object.__setattr__(self, base.__name__, ns)
|
||||
|
@ -334,7 +334,10 @@ def test_API():
|
||||
def method(self, n):
|
||||
return n + 1
|
||||
|
||||
r = plugable.Registrar(base0, base1)
|
||||
api = plugable.API(base0, base1)
|
||||
r = api.register
|
||||
assert isinstance(r, plugable.Registrar)
|
||||
assert read_only(api, 'register') is r
|
||||
|
||||
class base0_plugin0(base0):
|
||||
pass
|
||||
@ -360,10 +363,8 @@ def test_API():
|
||||
pass
|
||||
r(base1_plugin2)
|
||||
|
||||
registrants = tuple(r)
|
||||
|
||||
# Test API instance:
|
||||
api = plugable.API(r)
|
||||
api() # Calling instance performs finalization
|
||||
|
||||
def get_base(b):
|
||||
return 'base%d' % b
|
||||
|
Loading…
Reference in New Issue
Block a user