From a7fb172f8f1d62ad46795df60d9327e890e86f4c Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 25 Mar 2009 19:20:30 +0000 Subject: TutoriusV2 : Added interface validation for Actions --- (limited to 'src/sugar/tutorius/tests/actiontests.py') diff --git a/src/sugar/tutorius/tests/actiontests.py b/src/sugar/tutorius/tests/actiontests.py index ab9cdba..8eb7a89 100644 --- a/src/sugar/tutorius/tests/actiontests.py +++ b/src/sugar/tutorius/tests/actiontests.py @@ -38,7 +38,15 @@ class PropertyAction(Action): return self._a a = property(fget=get_a, fset=set_a) - + +def has_function(obj, function_name): + """ + Checks whether the object has a function by that name. + """ + if hasattr(obj, function_name) and hasattr(obj.__getattribute__(function_name), "__call__"): + return True + return False + class PropsTest(unittest.TestCase): def test_get_properties(self): @@ -46,8 +54,33 @@ class PropsTest(unittest.TestCase): assert prop.get_properties() == ['a'], "Action does not contain property 'a'" + def validate_wrapper(self, wrapper_instance): + """ + Ensures that a given instance of a wrapper implements the Action + interface. + """ + assert has_function(wrapper_instance, "do"),\ + "The wrapper does not have the 'do' function" + + assert has_function(wrapper_instance, "undo"),\ + "The wrapper does not have the 'undo' function." + + assert has_function(wrapper_instance, "get_properties"),\ + "The wrapper does not have the 'get_properties' function." + + def test_once_wrapper(self): + """ + Tests that the interface of the OnceWrapper actually conforms to the of + the Action. + """ + prop = PropertyAction(7) + + onceWrap = OnceWrapper(prop) + + self.validate_wrapper(onceWrap) + class CountAction(Action): - """ + """ This action counts how many times it's do and undo methods get called """ def __init__(self): -- cgit v0.9.1