From add05c487de3aec42801d39220a8f1f969e7c38a Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Tue, 10 Mar 2009 18:04:09 +0000 Subject: 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 --- 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() -- cgit v0.9.1