Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/sugar/tutorius/tests')
-rw-r--r--src/sugar/tutorius/tests/actiontests.py80
1 files changed, 42 insertions, 38 deletions
diff --git a/src/sugar/tutorius/tests/actiontests.py b/src/sugar/tutorius/tests/actiontests.py
index a1ec4ba..5fb3d0f 100644
--- a/src/sugar/tutorius/tests/actiontests.py
+++ b/src/sugar/tutorius/tests/actiontests.py
@@ -22,7 +22,10 @@ The behavior of the actions must be tested here.
"""
import unittest
-from sugar.tutorius.actions import *
+import gtk
+
+from sugar.tutorius.actions import Action, OnceWrapper
+from sugar.tutorius.services import ObjectStore
class PropertyAction(Action):
def __init__(self, na):
@@ -51,55 +54,56 @@ class CountAction(Action):
self.do_count = 0
self.undo_count = 0
-class ChainTester(Action):
- def __init__(self, witness):
- self._witness = witness
-
- def do(self, **kwargs):
- self._witness.append([self,"do"])
+ def do(self):
+ self.do_count += 1
def undo(self):
- self._witness.append([self,"undo"])
+ self.undo_count += 1
-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 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"
- c = ChainAction(first, second)
- assert witness == [], "Actions should not be triggered on init"""
- c.do()
+ def test_undo(self):
+ act = Action()
+ act.undo()
+ assert True, "undo() should never fail on the base action"
- assert witness[0][0] is first, "First triggered action must be 'first'"
- assert witness[0][1] is "do", "Action do() should be triggered"
- assert witness[1][0] is second, "second triggered action must be 'second'"
- assert witness[1][1] is "do", "Action do() should be triggered"
+class OnceWrapperTests(unittest.TestCase):
+ def test_onceaction_toggle(self):
+ """
+ Validate that the OnceWrapper wrapper works properly using the
+ CountAction
+ """
+ act = CountAction()
+ wrap = OnceWrapper(act)
- assert len(witness) is 2, "Two actions should give 2 do's"
+ 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__()"
- #empty the witness list
- while len(witness):
- rm = witness.pop()
+ wrap.undo()
- 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"
+ assert act.undo_count == 0, "undo() should not be called if do() has not been called"
- assert witness[0][0] is second, "first triggered action must be 'second'"
- assert witness[0][1] is "undo", "Action undo() should be triggered"
+ wrap.do()
+ assert act.do_count == 1, "do() should have been called once"
- assert len(witness) is 2, "Two actions should give 2 undo's"
+ wrap.do()
+ assert act.do_count == 1, "do() should have been called only once"
+
+ wrap.undo()
+ assert act.undo_count == 1, "undo() should have been called once"
+
+ wrap.undo()
+ assert act.undo_count == 1, "undo() should have been called only once"
-
if __name__ == "__main__":
unittest.main()
+