From d229a764749b37aded48ed6eec230df9105a62b0 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Thu, 14 Aug 2008 20:32:35 +0000 Subject: 165: Added unit tests for plugable.lock() function; replaced occurances of 'self.__lock__()' with 'lock(self)' in plugable.py --- ipalib/tests/test_plugable.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'ipalib/tests') diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py index b64cf305..839451b5 100644 --- a/ipalib/tests/test_plugable.py +++ b/ipalib/tests/test_plugable.py @@ -88,6 +88,35 @@ class test_ReadOnly(ClassChecker): assert read_only(obj, 'an_attribute') == 'Hello world!' +def test_lock(): + """ + Tests the `plugable.lock` function. + """ + f = plugable.lock + + # Test on a ReadOnly instance: + o = plugable.ReadOnly() + assert not o.__islocked__() + assert f(o) is o + assert o.__islocked__() + + # Test on something not subclassed from ReadOnly: + class not_subclass(object): + def __lock__(self): + pass + def __islocked__(self): + return True + o = not_subclass() + raises(ValueError, f, o) + + # Test that it checks __islocked__(): + class subclass(plugable.ReadOnly): + def __islocked__(self): + return False + o = subclass() + raises(AssertionError, f, o) + + class test_Plugin(ClassChecker): """ Tests the `plugable.Plugin` class. -- cgit