mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
302: Removed depreciated Command.group_args() method
This commit is contained in:
@@ -227,7 +227,8 @@ class Command(plugable.Plugin):
|
|||||||
'smart_option_order',
|
'smart_option_order',
|
||||||
'args',
|
'args',
|
||||||
'options',
|
'options',
|
||||||
'group_args',
|
'args_to_kw',
|
||||||
|
'kw_to_args',
|
||||||
))
|
))
|
||||||
takes_options = tuple()
|
takes_options = tuple()
|
||||||
takes_args = tuple()
|
takes_args = tuple()
|
||||||
@@ -354,39 +355,6 @@ class Command(plugable.Plugin):
|
|||||||
for option in sorted(self.options(), key=get_key):
|
for option in sorted(self.options(), key=get_key):
|
||||||
yield option
|
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):
|
def args_to_kw(self, *values):
|
||||||
if self.max_args is not None and len(values) > self.max_args:
|
if self.max_args is not None and len(values) > self.max_args:
|
||||||
if self.max_args == 0:
|
if self.max_args == 0:
|
||||||
|
|||||||
@@ -565,44 +565,11 @@ class test_Command(ClassChecker):
|
|||||||
"""
|
"""
|
||||||
assert 'execute' in self.cls.__public__ # Public
|
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):
|
def test_args_to_kw(self):
|
||||||
"""
|
"""
|
||||||
Test the `public.Command.args_to_kw` method.
|
Test the `public.Command.args_to_kw` method.
|
||||||
"""
|
"""
|
||||||
|
assert 'args_to_kw' in self.cls.__public__ # Public
|
||||||
o = self.get_instance(args=('one', 'two?'))
|
o = self.get_instance(args=('one', 'two?'))
|
||||||
assert o.args_to_kw(1) == dict(one=1)
|
assert o.args_to_kw(1) == dict(one=1)
|
||||||
assert o.args_to_kw(1, 2) == dict(one=1, two=2)
|
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.
|
Tests the `public.Command.kw_to_args` method.
|
||||||
"""
|
"""
|
||||||
|
assert 'kw_to_args' in self.cls.__public__ # Public
|
||||||
o = self.get_instance(args=('one', 'two?'))
|
o = self.get_instance(args=('one', 'two?'))
|
||||||
assert o.kw_to_args() == (None, None)
|
assert o.kw_to_args() == (None, None)
|
||||||
assert o.kw_to_args(whatever='hello') == (None, None)
|
assert o.kw_to_args(whatever='hello') == (None, None)
|
||||||
|
|||||||
Reference in New Issue
Block a user