Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Vinet <vince.vinet@gmail.com>2009-03-10 18:04:09 (GMT)
committer Vincent Vinet <vince.vinet@gmail.com>2009-03-10 18:04:09 (GMT)
commitadd05c487de3aec42801d39220a8f1f969e7c38a (patch)
tree62aa13cc5d3a9226606227b965d3acae9a2c15db
parentc2455bf46d36f3ed39c7bdc97a56514cb7b7587f (diff)
Add a test runner (no need to use it, but its fun!
Add OnceWrapper test Conflicts: source/external/source/sugar-toolkit/src/sugar/tutorius/tests/coretests.py
-rw-r--r--src/sugar/tutorius/tests/coretests.py48
-rwxr-xr-xsrc/sugar/tutorius/tests/run-tests.py12
2 files changed, 58 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()
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()