diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-11 00:21:12 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-11 00:21:12 +0000 |
commit | 879133d28a2da2d675d72a3f4e178f5bc4c82594 (patch) | |
tree | 4117f9be6bf86371c6fd15faa62f11b6515dca8c /ipalib | |
parent | f6b69a590500cf8c141545a1f95d59817eb5a27e (diff) | |
download | freeipa.git-879133d28a2da2d675d72a3f4e178f5bc4c82594.tar.gz freeipa.git-879133d28a2da2d675d72a3f4e178f5bc4c82594.tar.xz freeipa.git-879133d28a2da2d675d72a3f4e178f5bc4c82594.zip |
105: Added a default implementation of cmd.get_options; added corresponding unit tests
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/public.py | 22 | ||||
-rw-r--r-- | ipalib/tests/test_public.py | 33 |
2 files changed, 43 insertions, 12 deletions
diff --git a/ipalib/public.py b/ipalib/public.py index 92dc77af..baa1496a 100644 --- a/ipalib/public.py +++ b/ipalib/public.py @@ -23,6 +23,7 @@ and UI all use. """ import re +import inspect import plugable import errors @@ -134,7 +135,8 @@ class cmd(plugable.Plugin): 'opt', )) - __opt = None + __options = None + option_classes = tuple() def get_doc(self, _): """ @@ -149,19 +151,21 @@ class cmd(plugable.Plugin): def get_options(self): """ - Returns iterable with opt_proxy objects used to create the opt - NameSpace when __get_opt() is called. + Returns iterable with option proxy objects used to create the option + NameSpace when __get_option() is called. """ - raise NotImplementedError('%s.get_options()' % self.name) + for cls in self.option_classes: + assert inspect.isclass(cls) + yield plugable.Proxy(option, cls()) - def __get_opt(self): + def __get_options(self): """ - Returns the NameSpace containing opt_proxy objects. + Returns the NameSpace containing the option proxy objects. """ - if self.__opt is None: - self.__opt = plugable.NameSpace(self.get_options()) + if self.__options is None: + self.__options = plugable.NameSpace(self.get_options()) return self.__opt - opt = property(__get_opt) + options = property(__get_options) def normalize_iter(self, kw): for (key, value) in kw.items(): diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py index 68f25567..91d1f724 100644 --- a/ipalib/tests/test_public.py +++ b/ipalib/tests/test_public.py @@ -157,9 +157,36 @@ class test_option(ClassChecker): assert self.cls().default() is None -def test_cmd(): - cls = public.cmd - assert issubclass(cls, plugable.Plugin) +class test_cmd(ClassChecker): + """ + Tests the `cmd` class. + """ + _cls = public.cmd + + def get_subcls(self): + class option0(public.option): + pass + class option1(public.option): + pass + class example(self.cls): + option_classes = (option0, option1) + return example + + def test_class(self): + assert self.cls.__bases__ == (plugable.Plugin,) + assert type(self.cls.options) == property + + def test_get_options(self): + """ + Tests the `get_options` method. + """ + assert list(self.cls().get_options()) == [] + sub = self.subcls() + for (i, proxy) in enumerate(sub.get_options()): + assert isinstance(proxy, plugable.Proxy) + assert read_only(proxy, 'name') == 'option%d' % i + assert proxy.implements(public.option) + assert i == 1 def test_obj(): |