diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-08 22:45:09 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-08 22:45:09 +0000 |
commit | 5a1223e94367c4370a94f271ef7e087dbdb02615 (patch) | |
tree | 353cbc374d224c6136c23f59f37fba4c72b30a71 /ipalib/tests/test_plugable.py | |
parent | 6f144fbaf062d9644af06fdd11020e3d5d349639 (diff) | |
download | freeipa.git-5a1223e94367c4370a94f271ef7e087dbdb02615.tar.gz freeipa.git-5a1223e94367c4370a94f271ef7e087dbdb02615.tar.xz freeipa.git-5a1223e94367c4370a94f271ef7e087dbdb02615.zip |
90: Renamed plugable.Abstract to ProxyTarget, which now subclasses from ReadOnly; updated unit tests
Diffstat (limited to 'ipalib/tests/test_plugable.py')
-rw-r--r-- | ipalib/tests/test_plugable.py | 155 |
1 files changed, 84 insertions, 71 deletions
diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py index 1f42aa85..c3245e77 100644 --- a/ipalib/tests/test_plugable.py +++ b/ipalib/tests/test_plugable.py @@ -26,6 +26,33 @@ from tstutil import ClassChecker from ipalib import plugable, errors +def test_valid_identifier(): + """ + Test the plugable.valid_identifier function. + """ + f = plugable.check_identifier + okay = [ + 'user_add', + 'stuff2junk', + 'sixty9', + ] + nope = [ + '_user_add', + '__user_add', + 'user_add_', + 'user_add__', + '_user_add_', + '__user_add__', + '60nine', + ] + for name in okay: + f(name) + for name in nope: + raises(errors.NameSpaceError, f, name) + for name in okay: + raises(errors.NameSpaceError, f, name.upper()) + + class test_ReadOnly(ClassChecker): """ Test the plugable.ReadOnly class @@ -34,6 +61,7 @@ class test_ReadOnly(ClassChecker): def test_class(self): assert self.cls.__bases__ == (object,) + assert callable(self.cls.__lock__) def test_when_unlocked(self): """ @@ -73,79 +101,64 @@ class test_ReadOnly(ClassChecker): assert read_only(obj, 'an_attribute') == 'Hello world!' +class test_ProxyTarget(ClassChecker): + """ + Test the plugable.ProxyTarget class. + """ + _cls = plugable.ProxyTarget -def test_valid_identifier(): - f = plugable.check_identifier - okay = [ - 'user_add', - 'stuff2junk', - 'sixty9', - ] - nope = [ - '_user_add', - '__user_add', - 'user_add_', - 'user_add__', - '_user_add_', - '__user_add__', - '60nine', - ] - for name in okay: - f(name) - for name in nope: - raises(errors.NameSpaceError, f, name) - for name in okay: - raises(errors.NameSpaceError, f, name.upper()) - - -def test_Abstract(): - cls = plugable.Abstract - - class example(cls): - __public__ = frozenset(( - 'some_method', - 'some_property', - )) - - # Test using str: - assert example.implements('some_method') - assert not example.implements('another_method') - - # Test using frozenset: - assert example.implements(frozenset(['some_method'])) - assert not example.implements( - frozenset(['some_method', 'another_method']) - ) - - # Test using another object/class with __public__ frozenset: - assert example.implements(example) - assert example().implements(example) - assert example.implements(example()) - assert example().implements(example()) - - class subset(cls): - __public__ = frozenset(( - 'some_property', - )) - assert example.implements(subset) - assert not subset.implements(example) - - class superset(cls): - __public__ = frozenset(( - 'some_method', - 'some_property', - 'another_property', - )) - assert not example.implements(superset) - assert superset.implements(example) + def test_class(self): + assert self.cls.__bases__ == (plugable.ReadOnly,) + assert self.cls.implements(frozenset()) - class any_object(object): - __public__ = frozenset(( - 'some_method', - 'some_property', - )) - assert example.implements(any_object) - assert example.implements(any_object()) + def test_implements(self): + """ + Test the implements() classmethod + """ + class example(self.cls): + __public__ = frozenset(( + 'some_method', + 'some_property', + )) + class superset(self.cls): + __public__ = frozenset(( + 'some_method', + 'some_property', + 'another_property', + )) + class subset(self.cls): + __public__ = frozenset(( + 'some_property', + )) + class any_object(object): + __public__ = frozenset(( + 'some_method', + 'some_property', + )) + + for ex in (example, example()): + # Test using str: + assert ex.implements('some_method') + assert not ex.implements('another_method') + + # Test using frozenset: + assert ex.implements(frozenset(['some_method'])) + assert not ex.implements( + frozenset(['some_method', 'another_method']) + ) + + # Test using another object/class with __public__ frozenset: + assert ex.implements(example) + assert ex.implements(example()) + + assert ex.implements(subset) + assert not subset.implements(ex) + + assert not ex.implements(superset) + assert superset.implements(ex) + + assert ex.implements(any_object) + assert ex.implements(any_object()) def test_Plugin(): |