Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius
diff options
context:
space:
mode:
authorVincent Vinet <vince.vinet@gmail.com>2009-03-05 04:48:05 (GMT)
committer Vincent Vinet <vince.vinet@gmail.com>2009-03-05 04:48:05 (GMT)
commit9341b97d9d8fdeb842efbb1abf402ba4f8ba28f5 (patch)
tree956fda6821f4229a29771f9517d7af4961668007 /src/sugar/tutorius
parent5cdfcba9e827c2acf7dbad7890e8fcea241714a8 (diff)
Add a test runner (no need to use it, but its fun!
Add OnceWrapper test
Diffstat (limited to 'src/sugar/tutorius')
-rw-r--r--src/sugar/tutorius/tests/coretests.py50
-rwxr-xr-xsrc/sugar/tutorius/tests/run-tests.py12
2 files changed, 59 insertions, 3 deletions
diff --git a/src/sugar/tutorius/tests/coretests.py b/src/sugar/tutorius/tests/coretests.py
index 8c9a194..4a089cc 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):
"""
@@ -132,6 +176,6 @@ class StateTest(unittest.TestCase):
assert event_filter._callback == None, "Event filter did not remove callback properly"
-
+
if __name__ == "__main__":
- unittest.main() \ No newline at end of file
+ unittest.main()
diff --git a/src/sugar/tutorius/tests/run-tests.py b/src/sugar/tutorius/tests/run-tests.py
new file mode 100755
index 0000000..74efd64
--- /dev/null
+++ b/src/sugar/tutorius/tests/run-tests.py
@@ -0,0 +1,12 @@
+#!/usr/bin/python
+# This is a dumb script to run tests on the sugar-jhbuild installed files
+# The path added is the default path for the jhbuild build
+
+import os, sys
+sys.path.insert(0,
+ os.path.abspath("../../../../../../install/lib/python2.5/site-packages/")
+)
+import unittest
+from coretests import *
+
+unittest.main()