diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-07 03:38:49 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-07 03:38:49 +0000 |
commit | fadbae642053565be1d10bc5d6b40b151a97ff16 (patch) | |
tree | 1ae0cd72ef0b97ca5ffc6419545efd510256782b /ipalib/tests | |
parent | f904cb0422194dc55cf74366145b2cf20299b657 (diff) | |
download | freeipa.git-fadbae642053565be1d10bc5d6b40b151a97ff16.tar.gz freeipa.git-fadbae642053565be1d10bc5d6b40b151a97ff16.tar.xz freeipa.git-fadbae642053565be1d10bc5d6b40b151a97ff16.zip |
72: Started work on public.opt class; added corresponding unit tests
Diffstat (limited to 'ipalib/tests')
-rw-r--r-- | ipalib/tests/test_public.py | 36 | ||||
-rw-r--r-- | ipalib/tests/tstutil.py | 9 |
2 files changed, 44 insertions, 1 deletions
diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py index 0985658e..faffd02e 100644 --- a/ipalib/tests/test_public.py +++ b/ipalib/tests/test_public.py @@ -25,6 +25,41 @@ from tstutil import raises, getitem, no_set, no_del, read_only from ipalib import public, plugable, errors +def test_opt(): + cls = public.opt + assert issubclass(cls, plugable.ReadOnly) + + class int_opt(cls): + type = int + + i = int_opt() + + # Test with values that can't be converted: + nope = ( + '7.0' + 'whatever', + object, + None, + ) + for val in nope: + e = raises(errors.NormalizationError, i.normalize, val) + assert isinstance(e, errors.ValidationError) + assert e.name == 'int_opt' + assert e.value == val + assert e.error == "not <type 'int'>" + assert e.type is int + # Test with values that can be converted: + okay = ( + 7, + 7.0, + 7.2, + 7L, + '7', + ' 7 ', + ) + for val in okay: + assert i.normalize(val) == 7 + def test_cmd(): cls = public.cmd assert issubclass(cls, plugable.Plugin) @@ -35,6 +70,7 @@ def test_obj(): assert issubclass(cls, plugable.Plugin) + def test_attr(): cls = public.attr assert issubclass(cls, plugable.Plugin) diff --git a/ipalib/tests/tstutil.py b/ipalib/tests/tstutil.py index 12ca119d..cdac4547 100644 --- a/ipalib/tests/tstutil.py +++ b/ipalib/tests/tstutil.py @@ -43,10 +43,11 @@ def raises(exception, callback, *args, **kw): raised = False try: callback(*args, **kw) - except exception: + except exception, e: raised = True if not raised: raise ExceptionNotRaised(exception) + return e def getitem(obj, key): @@ -83,3 +84,9 @@ def read_only(obj, name, value='some_new_obj'): # Return the attribute return getattr(obj, name) + + +class ClassChecker(object): + + def new(self, *args, **kw): + return self.cls(*args, **kw) |