summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-12-18 01:57:39 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-12-18 01:57:39 -0700
commitcb2f294cfef9b47e03b82c85cf1db7e7bc3574ef (patch)
tree253bcded0fed49d3f71c8041d71ab808fcce1304
parent99363131df63f3b1d22bf325282eee5671eff924 (diff)
downloadfreeipa-cb2f294cfef9b47e03b82c85cf1db7e7bc3574ef.tar.gz
freeipa-cb2f294cfef9b47e03b82c85cf1db7e7bc3574ef.tar.xz
freeipa-cb2f294cfef9b47e03b82c85cf1db7e7bc3574ef.zip
New Param: added missing unit tests for TypeError and ValueError cases in parse_param_spec()
-rw-r--r--ipalib/constants.py2
-rw-r--r--ipalib/parameter.py6
-rw-r--r--tests/test_ipalib/test_parameter.py9
3 files changed, 14 insertions, 3 deletions
diff --git a/ipalib/constants.py b/ipalib/constants.py
index d028a0013..ad1e3f7cb 100644
--- a/ipalib/constants.py
+++ b/ipalib/constants.py
@@ -26,7 +26,7 @@ All constants centralised in one file.
NULLS = (None, '', u'', tuple(), [])
-TYPE_ERROR = '%s: need a %r; got %r (a %r)'
+TYPE_ERROR = '%s: need a %r; got %r (which is a %r)'
CALLABLE_ERROR = '%s: need a callable; got %r (a %r)'
diff --git a/ipalib/parameter.py b/ipalib/parameter.py
index a80c43c4d..ca578cd98 100644
--- a/ipalib/parameter.py
+++ b/ipalib/parameter.py
@@ -161,10 +161,12 @@ def parse_param_spec(spec):
:param spec: A spec string.
"""
if type(spec) is not str:
- raise_TypeError(spec, str, 'spec')
+ raise TypeError(
+ TYPE_ERROR % ('spec', str, spec, type(spec))
+ )
if len(spec) < 2:
raise ValueError(
- 'param spec must be at least 2 characters; got %r' % spec
+ 'spec must be at least 2 characters; got %r' % spec
)
_map = {
'?': dict(required=False, multivalue=False),
diff --git a/tests/test_ipalib/test_parameter.py b/tests/test_ipalib/test_parameter.py
index 5ee9e8caf..4fc9a0e78 100644
--- a/tests/test_ipalib/test_parameter.py
+++ b/tests/test_ipalib/test_parameter.py
@@ -92,9 +92,18 @@ def test_parse_param_spec():
assert f('name?') == ('name', dict(required=False, multivalue=False))
assert f('name*') == ('name', dict(required=False, multivalue=True))
assert f('name+') == ('name', dict(required=True, multivalue=True))
+
# Make sure other "funny" endings are *not* treated special:
assert f('name^') == ('name^', dict(required=True, multivalue=False))
+ # Test that TypeError is raised if spec isn't an str:
+ e = raises(TypeError, f, u'name?')
+ assert str(e) == TYPE_ERROR % ('spec', str, u'name?', unicode)
+
+ # Test that ValueError is raised if len(spec) < 2:
+ e = raises(ValueError, f, 'n')
+ assert str(e) == "spec must be at least 2 characters; got 'n'"
+
class test_Param(ClassChecker):
"""