summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-10 00:21:40 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-10 00:21:40 +0000
commit0215bc8009d7e10f884032e4dfa9cece73c14961 (patch)
treeac1a42a1e9ce3c897d04cb0c1d6a0bbb48adc54c
parent349fc660e796841a3d78b82bf4fa195a228da4c4 (diff)
downloadfreeipa-0215bc8009d7e10f884032e4dfa9cece73c14961.tar.gz
freeipa-0215bc8009d7e10f884032e4dfa9cece73c14961.tar.xz
freeipa-0215bc8009d7e10f884032e4dfa9cece73c14961.zip
276: Option.__init__(): doc is now 3rd kwarg instead of 2nd positional arg; updated unit tests and other affected code
-rw-r--r--ipalib/cli.py2
-rw-r--r--ipalib/public.py11
-rw-r--r--ipalib/tests/test_public.py42
3 files changed, 25 insertions, 30 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index b22514323..a6bc0f1fa 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -52,7 +52,7 @@ class help(public.Application):
'Display help on a command.'
takes_args = (
- public.Option('command', 'The doc', ipa_types.Unicode(),
+ public.Option('command', ipa_types.Unicode(),
required=True,
multivalue=True,
),
diff --git a/ipalib/public.py b/ipalib/public.py
index 003e0d728..fb7a80b93 100644
--- a/ipalib/public.py
+++ b/ipalib/public.py
@@ -86,7 +86,8 @@ class DefaultFrom(plugable.ReadOnly):
class Option(plugable.ReadOnly):
- def __init__(self, name, doc, type_,
+ def __init__(self, name, type_,
+ doc='',
required=False,
multivalue=False,
default=None,
@@ -190,10 +191,9 @@ class Option(plugable.ReadOnly):
return value
def __repr__(self):
- return '%s(%r, %r, %s)' % (
+ return '%s(%r, %s())' % (
self.__class__.__name__,
self.name,
- self.doc,
self.type.name,
)
@@ -228,7 +228,7 @@ class Command(plugable.Plugin):
multivalue = False
for arg in self.get_args():
if type(arg) is str:
- arg = Option(arg, '', ipa_types.Unicode(), required=True)
+ 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)
@@ -430,7 +430,8 @@ class Property(Attribute):
self.__rules_iter(),
key=lambda f: getattr(f, '__name__'),
))
- self.option = Option(self.attr_name, self.doc, self.type,
+ self.option = Option(self.attr_name, self.type,
+ doc=self.doc,
required=self.required,
multivalue=self.multivalue,
default=self.default,
diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py
index 2683e5dd7..73521e91c 100644
--- a/ipalib/tests/test_public.py
+++ b/ipalib/tests/test_public.py
@@ -125,13 +125,12 @@ class test_Option(ClassChecker):
Tests the `public.Option.__init__` method.
"""
name = 'sn'
- doc = 'Last Name'
type_ = ipa_types.Unicode()
- o = self.cls(name, doc, type_)
+ o = self.cls(name, type_)
assert o.__islocked__() is True
assert read_only(o, 'name') is name
- assert read_only(o, 'doc') is doc
assert read_only(o, 'type') is type_
+ assert read_only(o, 'doc') == ''
assert read_only(o, 'required') is False
assert read_only(o, 'multivalue') is False
assert read_only(o, 'default') is None
@@ -143,13 +142,12 @@ class test_Option(ClassChecker):
Tests the `public.Option.convert` method.
"""
name = 'some_number'
- doc = 'Some number'
type_ = ipa_types.Int()
okay = (7, 7L, 7.0, ' 7 ')
fail = ('7.0', '7L', 'whatever', object)
# Scenario 1: multivalue=False
- o = self.cls(name, doc, type_)
+ o = self.cls(name, type_)
e = raises(TypeError, o.convert, None)
assert str(e) == 'value cannot be None'
for value in okay:
@@ -164,7 +162,7 @@ class test_Option(ClassChecker):
assert e.index is None
# Scenario 2: multivalue=True
- o = self.cls(name, doc, type_, multivalue=True)
+ o = self.cls(name, type_, multivalue=True)
for none in [None, (7, None)]:
e = raises(TypeError, o.convert, none)
assert str(e) == 'value cannot be None'
@@ -189,32 +187,31 @@ class test_Option(ClassChecker):
Tests the `public.Option.normalize` method.
"""
name = 'sn'
- doc = 'User last name'
t = ipa_types.Unicode()
callback = lambda value: value.lower()
values = (None, u'Hello', (u'Hello',), 'hello', ['hello'])
# Scenario 1: multivalue=False, normalize=None
- o = self.cls(name, doc, t)
+ o = self.cls(name, t)
for v in values:
# When normalize=None, value is returned, no type checking:
assert o.normalize(v) is v
# Scenario 2: multivalue=False, normalize=callback
- o = self.cls(name, doc, t, normalize=callback)
+ o = self.cls(name, t, normalize=callback)
for v in (u'Hello', u'hello', 'Hello'): # Okay
assert o.normalize(v) == 'hello'
for v in [None, 42, (u'Hello',)]: # Not basestring
check_TypeError(v, basestring, 'value', o.normalize, v)
# Scenario 3: multivalue=True, normalize=None
- o = self.cls(name, doc, t, multivalue=True)
+ o = self.cls(name, t, multivalue=True)
for v in values:
# When normalize=None, value is returned, no type checking:
assert o.normalize(v) is v
# Scenario 4: multivalue=True, normalize=callback
- o = self.cls(name, doc, t, multivalue=True, normalize=callback)
+ o = self.cls(name, t, multivalue=True, normalize=callback)
for value in [(u'Hello',), (u'hello',), 'Hello', ['Hello']]: # Okay
assert o.normalize(value) == (u'hello',)
fail = 42 # Not basestring
@@ -226,7 +223,6 @@ class test_Option(ClassChecker):
Tests the `public.Option.validate` method.
"""
name = 'sn'
- doc = 'User last name'
type_ = ipa_types.Unicode()
def case_rule(value):
if not value.islower():
@@ -237,7 +233,7 @@ class test_Option(ClassChecker):
fail_type = 'whatever'
# Scenario 1: multivalue=False
- o = self.cls(name, doc, type_, rules=my_rules)
+ o = self.cls(name, type_, rules=my_rules)
assert o.rules == (type_.validate, case_rule)
o.validate(okay)
e = raises(errors.RuleError, o.validate, fail_case)
@@ -249,7 +245,7 @@ class test_Option(ClassChecker):
check_TypeError(fail_type, unicode, 'value', o.validate, fail_type)
## Scenario 2: multivalue=True
- o = self.cls(name, doc, type_, multivalue=True, rules=my_rules)
+ o = self.cls(name, type_, multivalue=True, rules=my_rules)
o.validate((okay,))
cnt = 5
for i in xrange(cnt):
@@ -272,7 +268,6 @@ class test_Option(ClassChecker):
Tests the `public.Option.get_default` method.
"""
name = 'greeting'
- doc = 'User greeting'
type_ = ipa_types.Unicode()
default = u'Hello, world!'
default_from = public.DefaultFrom(
@@ -281,7 +276,7 @@ class test_Option(ClassChecker):
)
# Scenario 1: multivalue=False
- o = self.cls(name, doc, type_,
+ o = self.cls(name, type_,
default=default,
default_from=default_from,
)
@@ -292,7 +287,7 @@ class test_Option(ClassChecker):
# Scenario 2: multivalue=True
default = (default,)
- o = self.cls(name, doc, type_,
+ o = self.cls(name, type_,
default=default,
default_from=default_from,
multivalue=True,
@@ -307,11 +302,10 @@ class test_Option(ClassChecker):
Tests the `public.Option.get_values` method.
"""
name = 'status'
- doc = 'Account status'
values = (u'Active', u'Inactive')
- o = self.cls(name, doc, ipa_types.Unicode())
+ o = self.cls(name, ipa_types.Unicode())
assert o.get_values() == tuple()
- o = self.cls(name, doc, ipa_types.Enum(*values))
+ o = self.cls(name, ipa_types.Enum(*values))
assert o.get_values() == values
@@ -339,12 +333,12 @@ class test_Command(ClassChecker):
class example(self.cls):
options = (
- public.Option('option0', 'Option zero', type_,
+ public.Option('option0', type_,
normalize=normalize,
default_from=default_from,
rules=(Rule('option0'),)
),
- public.Option('option1', 'Option one', type_,
+ public.Option('option1', type_,
normalize=normalize,
default_from=default_from,
rules=(Rule('option1'),),
@@ -652,8 +646,8 @@ class test_Method(ClassChecker):
type_ = ipa_types.Unicode()
class noun_verb(self.cls):
options= (
- public.Option('option0', 'Option zero', type_),
- public.Option('option1', 'Option one', type_),
+ public.Option('option0', type_),
+ public.Option('option1', type_),
)
obj = example_obj()
return noun_verb