Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-04-06 02:49:50 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-04-06 02:49:50 (GMT)
commit39a9a7030a774257d7398661edec9f50f6135974 (patch)
treec95ca2be1e92b584bce66d5fc58763c79b0f61af /src/sugar
parent524e2de6d7369f26075e7af184f932ef876ea4f9 (diff)
parent3e92e7a3ab862901e473e5f3a05d08d9af185f68 (diff)
Merge branch 'lp353185'
Conflicts: source/external/source/sugar-toolkit/src/sugar/tutorius/tests/actiontests.py
Diffstat (limited to 'src/sugar')
-rw-r--r--src/sugar/tutorius/actions.py15
-rw-r--r--src/sugar/tutorius/tests/actiontests.py80
2 files changed, 53 insertions, 42 deletions
diff --git a/src/sugar/tutorius/actions.py b/src/sugar/tutorius/actions.py
index 60ccd8b..7681dea 100644
--- a/src/sugar/tutorius/actions.py
+++ b/src/sugar/tutorius/actions.py
@@ -213,4 +213,19 @@ class WidgetIdentifyAction(Action):
if self._dialog:
self._dialog.destroy()
+class ChainAction(Action):
+ """Utility class to allow executing actions in a specific order"""
+ def __init__(self, *actions):
+ """ChainAction(action1, ... ) builds a chain of actions"""
+ self._actions = actions
+
+ def do(self,**kwargs):
+ """do() each action in the chain"""
+ for act in self._actions:
+ act.do(**kwargs)
+
+ def undo(self):
+ """undo() each action in the chain, starting with the last"""
+ for act in reversed(self._actions):
+ act.undo()
diff --git a/src/sugar/tutorius/tests/actiontests.py b/src/sugar/tutorius/tests/actiontests.py
index 5fb3d0f..a1ec4ba 100644
--- a/src/sugar/tutorius/tests/actiontests.py
+++ b/src/sugar/tutorius/tests/actiontests.py
@@ -22,10 +22,7 @@ The behavior of the actions must be tested here.
"""
import unittest
-import gtk
-
-from sugar.tutorius.actions import Action, OnceWrapper
-from sugar.tutorius.services import ObjectStore
+from sugar.tutorius.actions import *
class PropertyAction(Action):
def __init__(self, na):
@@ -54,56 +51,55 @@ class CountAction(Action):
self.do_count = 0
self.undo_count = 0
- def do(self):
- self.do_count += 1
-
- def undo(self):
- self.undo_count += 1
+class ChainTester(Action):
+ def __init__(self, witness):
+ self._witness = witness
+ def do(self, **kwargs):
+ self._witness.append([self,"do"])
-class BaseActionTests(unittest.TestCase):
- def test_do_unimplemented(self):
- act = Action()
- try:
- act.do()
- assert False, "do() should trigger a NotImplemented"
- except NotImplementedError:
- assert True, "do() should trigger a NotImplemented"
+ def undo(self):
+ self._witness.append([self,"undo"])
- def test_undo(self):
- act = Action()
- act.undo()
- assert True, "undo() should never fail on the base action"
+class ChainActionTest(unittest.TestCase):
+ """Tester for ChainAction"""
+ def test_empty(self):
+ """If the expected empty behavior (do nothing) changes
+ and starts throwing exceptions, this will flag it"""
+ a = ChainAction()
+ a.do()
+ a.undo()
+ def test_order(self):
+ witness = []
+ first = ChainTester(witness)
+ second = ChainTester(witness)
-class OnceWrapperTests(unittest.TestCase):
- def test_onceaction_toggle(self):
- """
- Validate that the OnceWrapper wrapper works properly using the
- CountAction
- """
- act = CountAction()
- wrap = OnceWrapper(act)
+ c = ChainAction(first, second)
+ assert witness == [], "Actions should not be triggered on init"""
+ c.do()
- assert act.do_count == 0, "do() should not have been called in __init__()"
- assert act.undo_count == 0, "undo() should not have been called in __init__()"
+ assert witness[0][0] is first, "First triggered action must be 'first'"
+ assert witness[0][1] is "do", "Action do() should be triggered"
- wrap.undo()
+ assert witness[1][0] is second, "second triggered action must be 'second'"
+ assert witness[1][1] is "do", "Action do() should be triggered"
- assert act.undo_count == 0, "undo() should not be called if do() has not been called"
+ assert len(witness) is 2, "Two actions should give 2 do's"
- wrap.do()
- assert act.do_count == 1, "do() should have been called once"
+ #empty the witness list
+ while len(witness):
+ rm = witness.pop()
- wrap.do()
- assert act.do_count == 1, "do() should have been called only once"
+ c.undo()
+ assert witness[1][0] is first, "second triggered action must be 'first'"
+ assert witness[1][1] is "undo", "Action undo() should be triggered"
- wrap.undo()
- assert act.undo_count == 1, "undo() should have been called once"
+ assert witness[0][0] is second, "first triggered action must be 'second'"
+ assert witness[0][1] is "undo", "Action undo() should be triggered"
- wrap.undo()
- assert act.undo_count == 1, "undo() should have been called only once"
+ assert len(witness) is 2, "Two actions should give 2 undo's"
+
if __name__ == "__main__":
unittest.main()
-