mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-23 23:03:19 -06:00
49: Added public.PublicAPI class; added some basic unit tests for same
This commit is contained in:
parent
907107001b
commit
f193dcba27
@ -26,25 +26,32 @@ import re
|
|||||||
import plugable
|
import plugable
|
||||||
|
|
||||||
|
|
||||||
class cmd_proxy(plugable.Proxy):
|
class generic_proxy(plugable.Proxy):
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
'get_label',
|
'get_label',
|
||||||
'get_summary',
|
)
|
||||||
'get_help',
|
|
||||||
'get_options',
|
|
||||||
|
class cmd_proxy(plugable.Proxy):
|
||||||
|
__slots__ = (
|
||||||
|
'__call__',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class cmd(plugable.Plugin):
|
class cmd(plugable.Plugin):
|
||||||
proxy = cmd_proxy
|
proxy = cmd_proxy
|
||||||
|
|
||||||
|
def __call__(self, *args, **kw):
|
||||||
|
print repr(self)
|
||||||
|
|
||||||
|
|
||||||
class obj(plugable.Plugin):
|
class obj(plugable.Plugin):
|
||||||
pass
|
proxy = generic_proxy
|
||||||
|
|
||||||
|
|
||||||
class attr(plugable.Plugin):
|
class attr(plugable.Plugin):
|
||||||
__obj = None
|
__obj = None
|
||||||
|
proxy = generic_proxy
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
m = re.match('^([a-z]+)_([a-z]+)$', self.__class__.__name__)
|
m = re.match('^([a-z]+)_([a-z]+)$', self.__class__.__name__)
|
||||||
@ -74,8 +81,13 @@ class attr(plugable.Plugin):
|
|||||||
|
|
||||||
|
|
||||||
class mthd(attr, cmd):
|
class mthd(attr, cmd):
|
||||||
pass
|
proxy = generic_proxy
|
||||||
|
|
||||||
|
|
||||||
class prop(attr):
|
class prop(attr):
|
||||||
pass
|
proxy = generic_proxy
|
||||||
|
|
||||||
|
|
||||||
|
class PublicAPI(plugable.API):
|
||||||
|
def __init__(self):
|
||||||
|
super(PublicAPI, self).__init__(cmd, obj, prop)
|
||||||
|
@ -22,7 +22,7 @@ Standard run-time instances of importard classes. This is where plugins
|
|||||||
should access the registration API.
|
should access the registration API.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base
|
import public
|
||||||
|
|
||||||
# The standard API instance
|
# The standard API instance
|
||||||
api = base.API()
|
api = public.PublicAPI()
|
||||||
|
@ -64,3 +64,20 @@ def test_mthd():
|
|||||||
def test_prop():
|
def test_prop():
|
||||||
cls = public.prop
|
cls = public.prop
|
||||||
assert issubclass(cls, public.attr)
|
assert issubclass(cls, public.attr)
|
||||||
|
|
||||||
|
|
||||||
|
def test_PublicAPI():
|
||||||
|
cls = public.PublicAPI
|
||||||
|
assert issubclass(cls, plugable.API)
|
||||||
|
|
||||||
|
api = cls()
|
||||||
|
|
||||||
|
class cmd1(public.cmd):
|
||||||
|
pass
|
||||||
|
api.register(cmd1)
|
||||||
|
|
||||||
|
class cmd2(public.cmd):
|
||||||
|
pass
|
||||||
|
api.register(cmd2)
|
||||||
|
|
||||||
|
api()
|
||||||
|
Loading…
Reference in New Issue
Block a user