Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sugar/tutorius/tests/actiontests.py37
1 files changed, 35 insertions, 2 deletions
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):