summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-19 00:00:54 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-19 00:00:54 +0000
commit1ec4f379f5eb0b77e6ca90c777e2e976c28ddfca (patch)
treec07cc9e9c87380e8903f9e27ac1eb0d3aeebd656 /ipalib
parentf29c827d06cb455709d3b07baf727913381709ca (diff)
downloadfreeipa-1ec4f379f5eb0b77e6ca90c777e2e976c28ddfca.tar.gz
freeipa-1ec4f379f5eb0b77e6ca90c777e2e976c28ddfca.tar.xz
freeipa-1ec4f379f5eb0b77e6ca90c777e2e976c28ddfca.zip
302: Removed depreciated Command.group_args() method
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/public.py36
-rw-r--r--ipalib/tests/test_public.py36
2 files changed, 4 insertions, 68 deletions
diff --git a/ipalib/public.py b/ipalib/public.py
index 967f88ce3..a8397a545 100644
--- a/ipalib/public.py
+++ b/ipalib/public.py
@@ -227,7 +227,8 @@ class Command(plugable.Plugin):
'smart_option_order',
'args',
'options',
- 'group_args',
+ 'args_to_kw',
+ 'kw_to_args',
))
takes_options = tuple()
takes_args = tuple()
@@ -354,39 +355,6 @@ class Command(plugable.Plugin):
for option in sorted(self.options(), key=get_key):
yield option
- def group_args(self, *values):
- args = tuple(self.args())
- if len(args) == 0:
- if len(values) > 0:
- raise errors.ArgumentError(self, 'takes no arguments')
- else:
- return tuple()
- if len(values) > len(args) and not args[-1].multivalue:
- if len(args) == 1:
- error = 'takes at most 1 argument'
- else:
- error = 'takes at most %d arguments' % len(args)
- raise errors.ArgumentError(self, error)
- min_args = sum(int(a.required) for a in args)
- if len(values) < min_args:
- if min_args == 1:
- error = 'takes at least 1 argument'
- else:
- error = 'takes at least %d arguments' % min_args
- raise errors.ArgumentError(self, error)
- return tuple(self.__group_args_iter(values, args))
-
- def __group_args_iter(self, values, args):
- for (i, arg) in enumerate(args):
- if len(values) > i:
- if arg.multivalue:
- yield values[i:]
- else:
- yield values[i]
- else:
- assert not arg.required
- yield None
-
def args_to_kw(self, *values):
if self.max_args is not None and len(values) > self.max_args:
if self.max_args == 0:
diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py
index 939d59e8e..f45d1abea 100644
--- a/ipalib/tests/test_public.py
+++ b/ipalib/tests/test_public.py
@@ -565,44 +565,11 @@ class test_Command(ClassChecker):
"""
assert 'execute' in self.cls.__public__ # Public
- def test_group_args(self):
- o = self.get_instance(args=('one', 'two?'))
- assert o.group_args(1) == (1, None)
- assert o.group_args(1, 2) == (1, 2)
-
- o = self.get_instance(args=('one', 'two*'))
- assert o.group_args(1) == (1, None)
- assert o.group_args(1, 2) == (1, (2,))
- assert o.group_args(1, 2, 3) == (1, (2, 3))
-
- o = self.get_instance(args=('one', 'two+'))
- assert o.group_args(1, 2) == (1, (2,))
- assert o.group_args(1, 2, 3) == (1, (2, 3))
-
- o = self.get_instance()
- e = raises(errors.ArgumentError, o.group_args, 1)
- assert str(e) == 'example takes no arguments'
-
- o = self.get_instance(args=('one?',))
- e = raises(errors.ArgumentError, o.group_args, 1, 2)
- assert str(e) == 'example takes at most 1 argument'
-
- o = self.get_instance(args=('one', 'two?'))
- e = raises(errors.ArgumentError, o.group_args, 1, 2, 3)
- assert str(e) == 'example takes at most 2 arguments'
-
- o = self.get_instance(args=('one', 'two?'))
- e = raises(errors.ArgumentError, o.group_args)
- assert str(e) == 'example takes at least 1 argument'
-
- o = self.get_instance(args=('one', 'two', 'three?'))
- e = raises(errors.ArgumentError, o.group_args, 1)
- assert str(e) == 'example takes at least 2 arguments'
-
def test_args_to_kw(self):
"""
Test the `public.Command.args_to_kw` method.
"""
+ assert 'args_to_kw' in self.cls.__public__ # Public
o = self.get_instance(args=('one', 'two?'))
assert o.args_to_kw(1) == dict(one=1)
assert o.args_to_kw(1, 2) == dict(one=1, two=2)
@@ -633,6 +600,7 @@ class test_Command(ClassChecker):
"""
Tests the `public.Command.kw_to_args` method.
"""
+ assert 'kw_to_args' in self.cls.__public__ # Public
o = self.get_instance(args=('one', 'two?'))
assert o.kw_to_args() == (None, None)
assert o.kw_to_args(whatever='hello') == (None, None)