mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
275: Added Command.__check_args(); added basic unit tests for Command.args instance attribute
This commit is contained in:
parent
0453aa465f
commit
349fc660e7
@ -214,12 +214,39 @@ class Command(plugable.Plugin):
|
|||||||
options = tuple()
|
options = tuple()
|
||||||
takes_args = tuple()
|
takes_args = tuple()
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.args = plugable.NameSpace(self.__check_args(), sort=False)
|
||||||
|
|
||||||
def get_args(self):
|
def get_args(self):
|
||||||
return self.takes_args
|
return self.takes_args
|
||||||
|
|
||||||
def get_options(self):
|
def get_options(self):
|
||||||
return self.options
|
return self.options
|
||||||
|
|
||||||
|
def __check_args(self):
|
||||||
|
optional = False
|
||||||
|
multivalue = False
|
||||||
|
for arg in self.get_args():
|
||||||
|
if type(arg) is str:
|
||||||
|
arg = Option(arg, '', ipa_types.Unicode(), required=True)
|
||||||
|
elif not isinstance(arg, Option):
|
||||||
|
raise TypeError(
|
||||||
|
'arg: need %r or %r; got %r' % (str, Option, arg)
|
||||||
|
)
|
||||||
|
if optional and arg.required:
|
||||||
|
raise ValueError(
|
||||||
|
'%s: required argument after optional' % arg.name
|
||||||
|
)
|
||||||
|
if multivalue:
|
||||||
|
raise ValueError(
|
||||||
|
'%s: only final argument can be multivalue' % arg.name
|
||||||
|
)
|
||||||
|
if not arg.required:
|
||||||
|
optional = True
|
||||||
|
if arg.multivalue:
|
||||||
|
multivalue = True
|
||||||
|
yield arg
|
||||||
|
|
||||||
def __get_Option(self):
|
def __get_Option(self):
|
||||||
"""
|
"""
|
||||||
Returns the NameSpace containing the Option instances.
|
Returns the NameSpace containing the Option instances.
|
||||||
|
@ -368,6 +368,14 @@ class test_Command(ClassChecker):
|
|||||||
o = example()
|
o = example()
|
||||||
assert o.get_args() is args
|
assert o.get_args() is args
|
||||||
|
|
||||||
|
def test_args(self):
|
||||||
|
"""
|
||||||
|
Tests the ``Command.args`` instance attribute.
|
||||||
|
"""
|
||||||
|
ns = self.cls().args
|
||||||
|
assert type(ns) is plugable.NameSpace
|
||||||
|
assert len(ns) == 0
|
||||||
|
|
||||||
def test_get_options(self):
|
def test_get_options(self):
|
||||||
"""
|
"""
|
||||||
Tests the `public.Command.get_options` method.
|
Tests the `public.Command.get_options` method.
|
||||||
|
Loading…
Reference in New Issue
Block a user