diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-10 01:54:48 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-10 01:54:48 +0000 |
commit | 0d3be2f421c3cd4044c4d7616d9426ac58a71ce8 (patch) | |
tree | 6f00d8e26dcc277d9b73a2931cfc1fd1afea265e /ipalib | |
parent | 51b639595858c8395f3beb01659ffe0ea69aaf8b (diff) | |
download | freeipa.git-0d3be2f421c3cd4044c4d7616d9426ac58a71ce8.tar.gz freeipa.git-0d3be2f421c3cd4044c4d7616d9426ac58a71ce8.tar.xz freeipa.git-0d3be2f421c3cd4044c4d7616d9426ac58a71ce8.zip |
278: Completed unit tests for Command.args instance attribute
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/public.py | 9 | ||||
-rw-r--r-- | ipalib/tests/test_public.py | 22 |
2 files changed, 28 insertions, 3 deletions
diff --git a/ipalib/public.py b/ipalib/public.py index 772490d0..99c51999 100644 --- a/ipalib/public.py +++ b/ipalib/public.py @@ -204,13 +204,16 @@ def generate_argument(name): """ if name.endswith('?'): kw = dict(required=False, multivalue=False) + name = name[:-1] elif name.endswith('*'): kw = dict(required=False, multivalue=True) + name = name[:-1] elif name.endswith('+'): kw = dict(required=True, multivalue=True) + name = name[:-1] else: kw = dict(required=True, multivalue=False) - return Option(name.rstrip('?*+'), ipa_types.Unicode(), **kw) + return Option(name, ipa_types.Unicode(), **kw) class Command(plugable.Plugin): @@ -223,7 +226,7 @@ class Command(plugable.Plugin): '__call__', 'smart_option_order', 'Option', - 'takes_args', + 'args', )) __Option = None options = tuple() @@ -243,7 +246,7 @@ class Command(plugable.Plugin): multivalue = False for arg in self.get_args(): if type(arg) is str: - arg = Option(arg, ipa_types.Unicode(), required=True) + arg = generate_argument(arg) elif not isinstance(arg, Option): raise TypeError( 'arg: need %r or %r; got %r' % (str, Option, arg) diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py index 3841d384..93331f94 100644 --- a/ipalib/tests/test_public.py +++ b/ipalib/tests/test_public.py @@ -374,6 +374,7 @@ class test_Command(ClassChecker): def test_class(self): assert self.cls.__bases__ == (plugable.Plugin,) assert self.cls.options == tuple() + assert self.cls.takes_args == tuple() def test_get_args(self): """ @@ -386,13 +387,34 @@ class test_Command(ClassChecker): o = example() assert o.get_args() is args + def __get_instance(self, args=tuple(), options=tuple()): + class example(self.cls): + takes_args = args + takes_options = options + return example() + def test_args(self): """ Tests the ``Command.args`` instance attribute. """ + assert 'args' in self.cls.__public__ # Public ns = self.cls().args assert type(ns) is plugable.NameSpace assert len(ns) == 0 + args = ('destination', 'source?') + ns = self.__get_instance(args=args).args + assert type(ns) is plugable.NameSpace + assert len(ns) == len(args) + assert list(ns) == ['destination', 'source'] + assert type(ns.destination) is public.Option + assert ns.destination.required is True + assert ns.destination.multivalue is False + assert ns.source.required is False + assert ns.source.multivalue is False + + # Test type error: + e = raises(TypeError, self.__get_instance, args=(u'whatever',)) + #assert str(e) == 'arg: need %r or %r; got %r' % (str, public.Option, def test_get_options(self): """ |