diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-13 02:17:16 -0700 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-13 02:17:16 -0700 |
commit | 10747103fa3748677e6e1948977de1313fe25bc9 (patch) | |
tree | 66bcc764e8a4129a863f99177b52a638341f69c5 /tests | |
parent | c2b0d03f82f16debcc55d34ac44197e0bc97e0e8 (diff) | |
download | freeipa-10747103fa3748677e6e1948977de1313fe25bc9.tar.gz freeipa-10747103fa3748677e6e1948977de1313fe25bc9.tar.xz freeipa-10747103fa3748677e6e1948977de1313fe25bc9.zip |
New Param: implemented a base Param._convert_scalar() method; added Param.type_error attribute for ConversionError message
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_ipalib/test_parameter.py | 29 | ||||
-rw-r--r-- | tests/util.py | 9 |
2 files changed, 31 insertions, 7 deletions
diff --git a/tests/test_ipalib/test_parameter.py b/tests/test_ipalib/test_parameter.py index 3a0bd0c1e..27d348b99 100644 --- a/tests/test_ipalib/test_parameter.py +++ b/tests/test_ipalib/test_parameter.py @@ -22,6 +22,7 @@ Test the `ipalib.parameter` module. """ from types import NoneType +from inspect import isclass from tests.util import raises, ClassChecker, read_only from tests.util import dummy_ugettext, assert_equal from tests.data import binary_bytes, utf8_bytes, unicode_str @@ -315,14 +316,14 @@ class test_Param(ClassChecker): """ Test the `ipalib.parameter.Param._convert_scalar` method. """ + dummy = dummy_ugettext() + + # Test with correct type: o = self.cls('my_param') - e = raises(NotImplementedError, o._convert_scalar, 'some value') - assert str(e) == 'Param._convert_scalar()' - class Subclass(self.cls): - pass - o = Subclass('my_param') - e = raises(NotImplementedError, o._convert_scalar, 'some value') - assert str(e) == 'Subclass._convert_scalar()' + assert o._convert_scalar(None) is None + assert dummy.called() is False + # Test with incorrect type + e = raises(errors2.ConversionError, o._convert_scalar, 'hello', index=17) def test_validate(self): """ @@ -782,3 +783,17 @@ def test_create_param(): e = raises(TypeError, f, spec) assert str(e) == \ TYPE_ERROR % ('spec', (str, parameter.Param), spec, type(spec)) + + +def test_messages(): + """ + Test module level message in `ipalib.parameter`. + """ + for name in dir(parameter): + if name.startswith('_'): + continue + attr = getattr(parameter, name) + if not (isclass(attr) and issubclass(attr, parameter.Param)): + continue + assert type(attr.type_error) is str + assert attr.type_error in parameter.__messages diff --git a/tests/util.py b/tests/util.py index c1480840d..af4c23934 100644 --- a/tests/util.py +++ b/tests/util.py @@ -28,6 +28,7 @@ import tempfile import shutil import ipalib from ipalib.plugable import Plugin +from ipalib.request import context @@ -202,6 +203,14 @@ class ClassChecker(object): 'get_subcls()' ) + def tearDown(self): + """ + nose tear-down fixture. + """ + for name in ('ugettext', 'ungettext'): + if hasattr(context, name): + delattr(context, name) + |