49: Added public.PublicAPI class; added some basic unit tests for same

This commit is contained in:
Jason Gerard DeRose committed 2008-08-05 21:10:49 +00:00
1 parent 907107001b
commit f193dcba27
3 files changed
+38 -9

No files matched your search

+19 -7
View File
@@ -26,25 +26,32 @@ import re
import plugable
class cmd_proxy(plugable.Proxy):
class generic_proxy(plugable.Proxy):
__slots__ = (
'get_label',
'get_summary',
'get_help',
'get_options',
)
class cmd_proxy(plugable.Proxy):
__slots__ = (
'__call__',
)
class cmd(plugable.Plugin):
proxy = cmd_proxy
def __call__(self, *args, **kw):
print repr(self)
class obj(plugable.Plugin):
pass
proxy = generic_proxy
class attr(plugable.Plugin):
__obj = None
proxy = generic_proxy
def __init__(self):
m = re.match('^([a-z]+)_([a-z]+)$', self.__class__.__name__)
@@ -74,8 +81,13 @@ class attr(plugable.Plugin):
class mthd(attr, cmd):
pass
proxy = generic_proxy
class prop(attr):
pass
proxy = generic_proxy
class PublicAPI(plugable.API):
def __init__(self):
super(PublicAPI, self).__init__(cmd, obj, prop)
+2 -2
View File
@@ -22,7 +22,7 @@ Standard run-time instances of importard classes. This is where plugins
should access the registration API.
"""
import base
import public
# The standard API instance
api = base.API()
api = public.PublicAPI()
+17
View File
@@ -64,3 +64,20 @@ def test_mthd():
def test_prop():
cls = public.prop
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()