diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-10 15:14:26 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-10 15:14:26 +0000 |
commit | 7de450363bc56a747a495803d56cc7c4d1323293 (patch) | |
tree | 4c56e2cebf46e761ec73705bf135d699754b6bc8 | |
parent | 2d85a6daa3798ee5feda1b2bda33300b73bed615 (diff) | |
download | freeipa.git-7de450363bc56a747a495803d56cc7c4d1323293.tar.gz freeipa.git-7de450363bc56a747a495803d56cc7c4d1323293.tar.xz freeipa.git-7de450363bc56a747a495803d56cc7c4d1323293.zip |
282: Added Command.__check_options() method; added unit tests for Command.options instance attribute
-rw-r--r-- | ipalib/public.py | 12 | ||||
-rw-r--r-- | ipalib/tests/test_public.py | 21 |
2 files changed, 33 insertions, 0 deletions
diff --git a/ipalib/public.py b/ipalib/public.py index 7f1929f4..7dfcd176 100644 --- a/ipalib/public.py +++ b/ipalib/public.py @@ -227,6 +227,7 @@ class Command(plugable.Plugin): 'smart_option_order', 'Option', 'args', + 'options', )) __Option = None takes_options = tuple() @@ -234,6 +235,7 @@ class Command(plugable.Plugin): def __init__(self): self.args = plugable.NameSpace(self.__check_args(), sort=False) + self.options = plugable.NameSpace(self.__check_options(), sort=False) def get_args(self): return self.takes_args @@ -265,6 +267,16 @@ class Command(plugable.Plugin): multivalue = True yield arg + def __check_options(self): + for option in self.get_options(): + if type(option) is str: + option = generate_argument(option) + elif not isinstance(option, Option): + raise TypeError( + 'option: need %r or %r; got %r' % (str, Option, option) + ) + yield option + def __get_Option(self): """ Returns the NameSpace containing the Option instances. diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py index 7c9a0244..1f2efe4b 100644 --- a/ipalib/tests/test_public.py +++ b/ipalib/tests/test_public.py @@ -417,6 +417,7 @@ class test_Command(ClassChecker): assert len(ns) == len(args) assert list(ns) == ['destination', 'source'] assert type(ns.destination) is public.Option + assert type(ns.source) is public.Option assert ns.destination.required is True assert ns.destination.multivalue is False assert ns.source.required is False @@ -435,6 +436,26 @@ class test_Command(ClassChecker): e = raises(ValueError, self.__get_instance, args=('arg1+', 'arg2')) assert str(e) == 'arg2: only final argument can be multivalue' + def test_options(self): + """ + Tests the ``Command.options`` instance attribute. + """ + assert 'options' in self.cls.__public__ # Public + ns = self.cls().options + assert type(ns) is plugable.NameSpace + assert len(ns) == 0 + options = ('target', 'files*') + ns = self.__get_instance(options=options).options + assert type(ns) is plugable.NameSpace + assert len(ns) == len(options) + assert list(ns) == ['target', 'files'] + assert type(ns.target) is public.Option + assert type(ns.files) is public.Option + assert ns.target.required is True + assert ns.target.multivalue is False + assert ns.files.required is False + assert ns.files.multivalue is True + def test_Option(self): """ Tests the `public.Command.Option` property. |