mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 07:33:27 -06:00
106: Fixed some typos in cmd.__get_options(); added unit tests for cmd.options and cmd.normalize()
This commit is contained in:
parent
879133d28a
commit
8aee8e060c
@ -53,7 +53,8 @@ class option(plugable.Plugin):
|
||||
))
|
||||
__rules = None
|
||||
|
||||
# type = unicode, int, float # Set in subclass
|
||||
type = unicode
|
||||
required = False
|
||||
|
||||
def normalize(self, value):
|
||||
"""
|
||||
@ -132,7 +133,7 @@ class cmd(plugable.Plugin):
|
||||
'autofill',
|
||||
'__call__',
|
||||
'get_doc',
|
||||
'opt',
|
||||
'options',
|
||||
|
||||
))
|
||||
__options = None
|
||||
@ -156,7 +157,9 @@ class cmd(plugable.Plugin):
|
||||
"""
|
||||
for cls in self.option_classes:
|
||||
assert inspect.isclass(cls)
|
||||
yield plugable.Proxy(option, cls())
|
||||
o = cls()
|
||||
o.__lock__()
|
||||
yield plugable.Proxy(option, o)
|
||||
|
||||
def __get_options(self):
|
||||
"""
|
||||
@ -164,7 +167,7 @@ class cmd(plugable.Plugin):
|
||||
"""
|
||||
if self.__options is None:
|
||||
self.__options = plugable.NameSpace(self.get_options())
|
||||
return self.__opt
|
||||
return self.__options
|
||||
options = property(__get_options)
|
||||
|
||||
def normalize_iter(self, kw):
|
||||
|
@ -164,9 +164,12 @@ class test_cmd(ClassChecker):
|
||||
_cls = public.cmd
|
||||
|
||||
def get_subcls(self):
|
||||
class option0(public.option):
|
||||
class my_option(public.option):
|
||||
def normalize(self, value):
|
||||
return super(my_option, self).normalize(value).lower()
|
||||
class option0(my_option):
|
||||
pass
|
||||
class option1(public.option):
|
||||
class option1(my_option):
|
||||
pass
|
||||
class example(self.cls):
|
||||
option_classes = (option0, option1)
|
||||
@ -188,6 +191,36 @@ class test_cmd(ClassChecker):
|
||||
assert proxy.implements(public.option)
|
||||
assert i == 1
|
||||
|
||||
def test_options(self):
|
||||
"""
|
||||
Tests the `options` property.
|
||||
"""
|
||||
assert 'options' in self.cls.__public__ # Public
|
||||
sub = self.subcls()
|
||||
options = sub.options
|
||||
assert type(options) == plugable.NameSpace
|
||||
assert len(options) == 2
|
||||
for name in ('option0', 'option1'):
|
||||
assert name in options
|
||||
proxy = options[name]
|
||||
assert getattr(options, name) is proxy
|
||||
assert isinstance(proxy, plugable.Proxy)
|
||||
assert proxy.name == name
|
||||
|
||||
def test_normalize(self):
|
||||
"""
|
||||
Tests the `normalize` method.
|
||||
"""
|
||||
assert 'normalize' in self.cls.__public__ # Public
|
||||
kw = dict(
|
||||
option0='OPTION0',
|
||||
option1='OPTION1',
|
||||
option2='option2',
|
||||
)
|
||||
norm = dict((k, v.lower()) for (k, v) in kw.items())
|
||||
sub = self.subcls()
|
||||
assert sub.normalize(**kw) == norm
|
||||
|
||||
|
||||
def test_obj():
|
||||
cls = public.obj
|
||||
|
Loading…
Reference in New Issue
Block a user