diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-27 21:20:19 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-27 21:20:19 +0000 |
commit | 89ea3acd0add73049a9ff7e73a0fdd646c7c9894 (patch) | |
tree | aa7e6c5e69e4f3657fe9aa3bf46332991c92d6be /ipalib/tests | |
parent | 6b214cbccf5211078e3c2b3386c036d50c262f94 (diff) | |
download | freeipa.git-89ea3acd0add73049a9ff7e73a0fdd646c7c9894.tar.gz freeipa.git-89ea3acd0add73049a9ff7e73a0fdd646c7c9894.tar.xz freeipa.git-89ea3acd0add73049a9ff7e73a0fdd646c7c9894.zip |
203: Finished ipa_types.check_min_max() function; added corresponding unit tests; ipa_types.Int now uses check_min_max()
Diffstat (limited to 'ipalib/tests')
-rw-r--r-- | ipalib/tests/test_ipa_types.py | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/ipalib/tests/test_ipa_types.py b/ipalib/tests/test_ipa_types.py index 6ecef2a5..87063ef6 100644 --- a/ipalib/tests/test_ipa_types.py +++ b/ipalib/tests/test_ipa_types.py @@ -30,6 +30,13 @@ def test_check_min_max(): Tests the `ipa_types.check_min_max` function. """ f = ipa_types.check_min_max + okay = [ + (None, -5), + (-20, None), + (-20, -5), + ] + for (l, h) in okay: + assert f(l, h, 'low', 'high') is None fail_type = [ '10', 10.0, @@ -39,11 +46,18 @@ def test_check_min_max(): object, ] for value in fail_type: - e = raises(TypeError, f, 'low', value, 'high', None) - assert str(e) == 'low must be an int or None, got: %r' % value - e = raises(TypeError, f, 'low', None, 'high', value) - assert str(e) == 'high must be an int or None, got: %r' % value - + e = raises(TypeError, f, value, None, 'low', 'high') + assert str(e) == '`low` must be an int or None, got: %r' % value + e = raises(TypeError, f, None, value, 'low', 'high') + assert str(e) == '`high` must be an int or None, got: %r' % value + fail_value = [ + (10, 5), + (-5, -10), + (5, -10), + ] + for (l, h) in fail_value: + e = raises(ValueError, f, l, h, 'low', 'high') + assert str(e) == 'high > low: low=%r, high=%r' % (l, h) class test_Type(ClassChecker): @@ -56,36 +70,52 @@ class test_Type(ClassChecker): assert self.cls.__bases__ == (plugable.ReadOnly,) - class test_Int(ClassChecker): _cls = ipa_types.Int + def test_class(self): + assert self.cls.__bases__ == (ipa_types.Type,) + assert self.cls.type is int + def test_init(self): o = self.cls() + assert o.name == 'Int' assert o.min_value is None assert o.max_value is None + okay = [ (None, -5), (-20, None), (-20, -5), ] + for (l, h) in okay: + o = self.cls(min_value=l, max_value=h) + assert o.min_value is l + assert o.max_value is h + fail_type = [ - (None, 10L), - (5L, None), - (None, '10'), - ('5', None), + '10', + 10.0, + 10L, + True, + False, + object, ] + for value in fail_type: + e = raises(TypeError, self.cls, min_value=value) + assert str(e) == ( + '`min_value` must be an int or None, got: %r' % value + ) + e = raises(TypeError, self.cls, max_value=value) + assert str(e) == ( + '`max_value` must be an int or None, got: %r' % value + ) + fail_value = [ (10, 5), (5, -5), (-5, -10), ] - for (l, h) in okay: - o = self.cls(min_value=l, max_value=h) - assert o.min_value is l - assert o.max_value is h - for (l, h) in fail_type: - raises(TypeError, self.cls, min_value=l, max_value=h) for (l, h) in fail_value: raises(ValueError, self.cls, min_value=l, max_value=h) |