Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius/tests/coretests.py
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-03-06 16:54:16 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-03-06 16:54:16 (GMT)
commit510e50936c9fe10edf369e3e51fc5768cb6f3b96 (patch)
tree42a9d015199d3c5e0a49ed6ce4cce63bb44ba5cf /src/sugar/tutorius/tests/coretests.py
parent37e224a7301ab8a5845bb688e452a6c186403ba7 (diff)
parentd828a9f7ec6f678d02a0a84943e3e7ec1daaa8b0 (diff)
Merge commit 'origin/mike' into mike
Conflicts: source/activities/Writus.activity/TAbiWordActivity.py source/external/source/sugar-toolkit/src/sugar/tutorius/tests/coretests.py
Diffstat (limited to 'src/sugar/tutorius/tests/coretests.py')
-rw-r--r--src/sugar/tutorius/tests/coretests.py48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/sugar/tutorius/tests/coretests.py b/src/sugar/tutorius/tests/coretests.py
index 7d4b5a6..ed5a7c0 100644
--- a/src/sugar/tutorius/tests/coretests.py
+++ b/src/sugar/tutorius/tests/coretests.py
@@ -26,7 +26,7 @@ related elements and interfaces are tested here.
import unittest
import logging
-from sugar.tutorius.actions import Action
+from sugar.tutorius.actions import Action, OnceWrapper
from sugar.tutorius.core import *
from sugar.tutorius.filters import *
@@ -59,6 +59,21 @@ class TrueWhileActiveAction(Action):
def undo(self):
self.active = False
+
+class CountAction(Action):
+ """
+ This action counts how many times it's do and undo methods get called
+ """
+ def __init__(self):
+ self.do_count = 0
+ self.undo_count = 0
+
+ def do(self):
+ self.do_count += 1
+
+ def undo(self):
+ self.undo_count += 1
+
class TriggerEventFilter(EventFilter):
"""
This event filter can be triggered by simply calling its execute function.
@@ -78,6 +93,35 @@ class TriggerEventFilter(EventFilter):
def _inner_cb(self, event_filter):
self.toggle_on_callback = not self.toggle_on_callback
+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 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__()"
+
+ wrap.undo()
+
+ assert act.undo_count == 0, "undo() should not be called if do() has not been called"
+
+ wrap.do()
+ assert act.do_count == 1, "do() should have been called once"
+
+ 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"
+
+
# State testing class
class StateTest(unittest.TestCase):
"""
@@ -150,4 +194,4 @@ class StateTest(unittest.TestCase):
if __name__ == "__main__":
- unittest.main() \ No newline at end of file
+ unittest.main()