summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-18 23:15:34 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-18 23:15:34 +0000
commite0b900894fcc884fbde26ba78fa61aedec3843e9 (patch)
tree36074e07ffdc9fbbd06e31f75b7834f8d686228a
parentef0d7a71abe0d026b1b79b6dc32d17793a8d7806 (diff)
downloadfreeipa-e0b900894fcc884fbde26ba78fa61aedec3843e9.tar.gz
freeipa-e0b900894fcc884fbde26ba78fa61aedec3843e9.tar.xz
freeipa-e0b900894fcc884fbde26ba78fa61aedec3843e9.zip
300: Added Command.max_args instance attribute; added corresponding unit tests
-rw-r--r--ipalib/public.py5
-rw-r--r--ipalib/tests/test_public.py25
2 files changed, 24 insertions, 6 deletions
diff --git a/ipalib/public.py b/ipalib/public.py
index f3626fdf..c2624f67 100644
--- a/ipalib/public.py
+++ b/ipalib/public.py
@@ -229,12 +229,15 @@ class Command(plugable.Plugin):
'options',
'group_args',
))
- __Option = None
takes_options = tuple()
takes_args = tuple()
def __init__(self):
self.args = plugable.NameSpace(self.__check_args(), sort=False)
+ if len(self.args) == 0 or not self.args[-1].multivalue:
+ self.max_args = len(self.args)
+ else:
+ self.max_args = None
self.options = plugable.NameSpace(self.__check_options(), sort=False)
self.params = plugable.NameSpace(
tuple(self.args()) + tuple(self.options()), sort=False
diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py
index 29531d69..80151fa0 100644
--- a/ipalib/tests/test_public.py
+++ b/ipalib/tests/test_public.py
@@ -371,11 +371,6 @@ class test_Command(ClassChecker):
)
return example
- def test_class(self):
- assert self.cls.__bases__ == (plugable.Plugin,)
- assert self.cls.takes_options == tuple()
- assert self.cls.takes_args == tuple()
-
def get_instance(self, args=tuple(), options=tuple()):
"""
Helper method used to test args and options.
@@ -385,6 +380,11 @@ class test_Command(ClassChecker):
takes_options = options
return example()
+ def test_class(self):
+ assert self.cls.__bases__ == (plugable.Plugin,)
+ assert self.cls.takes_options == tuple()
+ assert self.cls.takes_args == tuple()
+
def test_get_args(self):
"""
Tests the `public.Command.get_args` method.
@@ -436,6 +436,21 @@ 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_max_args(self):
+ """
+ Test the ``Command.max_args`` instance attribute.
+ """
+ o = self.get_instance()
+ assert o.max_args == 0
+ o = self.get_instance(args=('one?',))
+ assert o.max_args == 1
+ o = self.get_instance(args=('one', 'two?'))
+ assert o.max_args == 2
+ o = self.get_instance(args=('one', 'multi+',))
+ assert o.max_args is None
+ o = self.get_instance(args=('one', 'multi*',))
+ assert o.max_args is None
+
def test_options(self):
"""
Tests the ``Command.options`` instance attribute.