From 2b01bdc1121bf7dee1296bc3b8bdf8443d54d202 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 28 Aug 2008 01:38:29 +0000 Subject: 209: Added Type.__call__() method; fleshed out Type.convert() method; added corresponding unit tests --- ipalib/tests/test_ipa_types.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'ipalib/tests') diff --git a/ipalib/tests/test_ipa_types.py b/ipalib/tests/test_ipa_types.py index 71d8d6f3..657a99bd 100644 --- a/ipalib/tests/test_ipa_types.py +++ b/ipalib/tests/test_ipa_types.py @@ -122,6 +122,36 @@ class test_Int(ClassChecker): 'min_value > max_value: min_value=%d, max_value=%d' % (l, h) ) + + def test_call(self): + o = self.cls() + + # Test calling with None + e = raises(TypeError, o, None) + assert str(e) == 'value cannot be None' + + # Test with values that can be converted: + okay = [ + 3, + '3', + ' 3 ', + 3L, + 3.0, + ] + for value in okay: + assert o(value) == 3 + + # Test with values that cannot be converted: + fail = [ + object, + '3.0', + '3L', + 'whatever', + ] + for value in fail: + assert o(value) is None + + def test_validate(self): o = self.cls(min_value=2, max_value=7) assert o.validate(2) is None -- cgit