summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-03 21:53:15 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-03 21:53:15 +0000
commit6f739bcf671ee3028ffeab736e7ea1ff16489907 (patch)
tree772964f2614922c76d357365d55ebb36dfa2b453
parent390c1aa4ba9d2c54ac4c737c128f0561d14b58ab (diff)
downloadfreeipa.git-6f739bcf671ee3028ffeab736e7ea1ff16489907.tar.gz
freeipa.git-6f739bcf671ee3028ffeab736e7ea1ff16489907.tar.xz
freeipa.git-6f739bcf671ee3028ffeab736e7ea1ff16489907.zip
244: Added unit tests for errors.ConversionError
-rw-r--r--ipalib/errors.py12
-rw-r--r--ipalib/tests/test_errors.py30
2 files changed, 38 insertions, 4 deletions
diff --git a/ipalib/errors.py b/ipalib/errors.py
index cf213d70..6f0941e2 100644
--- a/ipalib/errors.py
+++ b/ipalib/errors.py
@@ -129,11 +129,15 @@ class ValidationError(IPAError):
class ConversionError(ValidationError):
- def __init__(self, name, value, type_, position):
- self.type = type_
- self.position = position
- ValidationError.__init__(self, name, value, type_.conversion_error)
+ """
+ Raised when a value cannot be converted to the correct type.
+ """
+ def __init__(self, name, value, type_, index=None):
+ self.type = type_
+ ValidationError.__init__(self, name, value, type_.conversion_error,
+ index=index,
+ )
class NormalizationError(ValidationError):
diff --git a/ipalib/tests/test_errors.py b/ipalib/tests/test_errors.py
index 83dc6e6e..3b89c7ed 100644
--- a/ipalib/tests/test_errors.py
+++ b/ipalib/tests/test_errors.py
@@ -193,3 +193,33 @@ class test_ValidationError(ClassChecker):
raises(AssertionError, self.cls, name, value, error, index=5.0)
# Check negative index raises AssertionError:
raises(AssertionError, self.cls, name, value, error, index=-2)
+
+
+class test_ConversionError(ClassChecker):
+ """
+ Tests the `errors.ConversionError` exception.
+ """
+ _cls = errors.ConversionError
+
+ def test_class(self):
+ assert self.cls.__bases__ == (errors.ValidationError,)
+
+ def test_init(self):
+ """
+ Tests the `errors.ConversionError.__init__` method.
+ """
+ name = 'some_arg'
+ value = '42.0'
+ class type_(object):
+ conversion_error = 'Not an integer'
+ for index in (None, 7):
+ e = self.cls(name, value, type_, index=index)
+ assert e.name is name
+ assert e.value is value
+ assert e.type is type_
+ assert e.error is type_.conversion_error
+ assert e.index is index
+ assert str(e) == 'invalid %r value %r: %s' % (name, value,
+ type_.conversion_error)
+ # Check that index default is None:
+ assert self.cls(name, value, type_).index is None