From 0d3be2f421c3cd4044c4d7616d9426ac58a71ce8 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 10 Sep 2008 01:54:48 +0000 Subject: 278: Completed unit tests for Command.args instance attribute --- ipalib/tests/test_public.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'ipalib/tests/test_public.py') 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): """ -- cgit