From 2a1c6d6fbcb60c44d8690add635260faf243dcd6 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 26 Apr 2009 21:42:20 +0000 Subject: (LP 352437) Core : Completed basic serializer interactions with core (actions, event filters) - needs tests Also, merged branch 'mike' into jc_support Conflicts: source/external/source/sugar-toolkit/src/sugar/tutorius/actions.py source/external/source/sugar-toolkit/src/sugar/tutorius/bundler.py source/external/source/sugar-toolkit/src/sugar/tutorius/tests/run-tests.py source/external/source/sugar-toolkit/src/sugar/tutorius/tests/serializertests.py --- (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..6001ec7 100644 --- a/src/sugar/tutorius/tests/actiontests.py +++ b/src/sugar/tutorius/tests/actiontests.py @@ -27,24 +27,83 @@ import gtk from sugar.tutorius.actions import * from sugar.tutorius.services import ObjectStore +test_props = {"prop_a":8, "prop_b":3, "prop_c":"Hi"} + class PropertyAction(Action): def __init__(self, na): - self._a = na + Action.__init__(self) + self.prop_a = TIntProperty(test_props["prop_a"]) + self.prop_b = TIntProperty(test_props["prop_b"]) + self.prop_c = TStringProperty(test_props["prop_c"]) + +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): + act = PropertyAction(8) + + assert act.get_properties() == test_props.keys(), "Action does not contain property 'a'" + + for prop_name in act.get_properties(): + assert act.properties[prop_name].value == test_props[prop_name], "Wrong initial value for property %s : %s"%(prop_name,str(act.properties[prop_name])) + - def set_a(self, na): - self._a = na +class OnceWrapperTests(unittest.TestCase): + 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_interface(self): + """ + Tests that the interface of the OnceWrapper actually conforms to the of + the Action. + """ + prop = PropertyAction(7) - def get_a(self): - return self._a + onceWrap = OnceWrapper(prop) + + self.validate_wrapper(onceWrap) + + assert onceWrap.get_properties() == test_props.keys(), "OnceWrapper should give access to properties of the contained action" - a = property(fget=get_a, fset=set_a) +class DialogMessageTest(unittest.TestCase): + def setUp(self): + self.dial = DialogMessage("Message text", [200, 300]) -class PropsTest(unittest.TestCase): + def test_properties(self): + assert self.dial.message.value == "Message text", "Wrong start value for the message" + + assert self.dial.position.value == [200, 300], "Wrong start value for the position" - def test_get_properties(self): - prop = PropertyAction(8) +class BubbleMessageTest(unittest.TestCase): + def setUp(self): + self.bubble = BubbleMessage(message="Message text", pos=[200, 300], tailpos=[-15, -25]) + + def test_properties(self): + props = self.bubble.get_properties() + + assert "message" in props, 'No message property of BubbleMessage' + + assert "position" in props, 'No position property in BubbleMessage' + + assert "tail_pos" in props, 'No tail position property in BubbleMessage' - assert prop.get_properties() == ['a'], "Action does not contain property 'a'" class CountAction(Action): """ -- cgit v0.9.1