313: Added Object.params instance attribute

This commit is contained in:
Jason Gerard DeRose 2008-09-22 00:37:01 +00:00
parent cbcadb89e4
commit 49c1c29df1
2 changed files with 29 additions and 1 deletions

View File

@ -394,9 +394,20 @@ class Object(plugable.Plugin):
__public__ = frozenset((
'Method',
'Property',
'params'
))
__Method = None
__Property = None
takes_params = tuple()
def __init__(self):
self.params = plugable.NameSpace(
(create_param(p) for p in self.takes_params), sort=False
)
def __create_params(self):
for param in self.takes_params:
yield create_param(param)
def __get_Method(self):
return self.__Method
@ -411,7 +422,6 @@ class Object(plugable.Plugin):
self.__Method = self.__create_namespace('Method')
self.__Property = self.__create_namespace('Property')
def __create_namespace(self, name):
return plugable.NameSpace(self.__filter_members(name))

View File

@ -702,6 +702,24 @@ class test_Object(ClassChecker):
assert attr.attr_name == attr_name
assert attr.name == attr_name
def test_params(self):
"""
Test the ``public.Object.params`` instance attribute.
"""
ns = self.cls().params
assert type(ns) is plugable.NameSpace
assert len(ns) == 0
class example(self.cls):
takes_params = ('banana', 'apple')
ns = example().params
assert type(ns) is plugable.NameSpace
assert len(ns) == 2, repr(ns)
assert list(ns) == ['banana', 'apple']
for p in ns():
assert type(p) is public.Param
assert p.required is True
assert p.multivalue is False
class test_Attribute(ClassChecker):
"""