diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-27 22:26:35 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-27 22:26:35 +0000 |
commit | 2984041d00f509b34a6ba7f0f0f79135ba6842a3 (patch) | |
tree | f0c4d47fa09fd1a3877e0c07c8459804b6e35743 /ipalib/tests | |
parent | e6cecfdcf299db564a9055ad69b1c0bc75d4af31 (diff) | |
download | freeipa.git-2984041d00f509b34a6ba7f0f0f79135ba6842a3.tar.gz freeipa.git-2984041d00f509b34a6ba7f0f0f79135ba6842a3.tar.xz freeipa.git-2984041d00f509b34a6ba7f0f0f79135ba6842a3.zip |
205: Continued work on Unicode.__init__() and corresponding unit tests
Diffstat (limited to 'ipalib/tests')
-rw-r--r-- | ipalib/tests/test_ipa_types.py | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/ipalib/tests/test_ipa_types.py b/ipalib/tests/test_ipa_types.py index 03346684..8e4f379f 100644 --- a/ipalib/tests/test_ipa_types.py +++ b/ipalib/tests/test_ipa_types.py @@ -117,7 +117,10 @@ class test_Int(ClassChecker): (-5, -10), ] for (l, h) in fail_value: - raises(ValueError, self.cls, min_value=l, max_value=h) + e = raises(ValueError, self.cls, min_value=l, max_value=h) + assert str(e) == ( + 'min_value > max_value: min_value=%d, max_value=%d' % (l, h) + ) def test_validate(self): o = self.cls(min_value=2, max_value=7) @@ -141,9 +144,47 @@ class test_Unicode(ClassChecker): assert o.pattern is None assert o.regex is None + # Test min_length, max_length: okay = ( - (0, 5, r'(hello|world)'), - (8, 8, r'\d{4}'), + (0, 1), + (8, 8), ) - for (l, h, pat) in okay: - o = self.cls(min_length=l, max_length=h, pattern=pat) + for (l, h) in okay: + o = self.cls(min_length=l, max_length=h) + assert o.min_length == l + assert o.max_length == h + + fail_type = [ + '10', + 10.0, + 10L, + True, + False, + object, + ] + for value in fail_type: + e = raises(TypeError, self.cls, min_length=value) + assert str(e) == ( + 'min_length must be an int or None, got: %r' % value + ) + e = raises(TypeError, self.cls, max_length=value) + assert str(e) == ( + 'max_length must be an int or None, got: %r' % value + ) + + fail_value = [ + (10, 5), + (5, -5), + (0, -10), + ] + for (l, h) in fail_value: + e = raises(ValueError, self.cls, min_length=l, max_length=h) + assert str(e) == ( + 'min_length > max_length: min_length=%d, max_length=%d' % (l, h) + ) + + for (key, lower) in [('min_length', 0), ('max_length', 1)]: + value = lower - 1 + kw = {key: value} + e = raises(ValueError, self.cls, **kw) + assert str(e) == '%s must be >= %d, got: %d' % (key, lower, value) |