From 9341b97d9d8fdeb842efbb1abf402ba4f8ba28f5 Mon Sep 17 00:00:00 2001 From: Vincent Vinet Date: Thu, 05 Mar 2009 04:48:05 +0000 Subject: Add a test runner (no need to use it, but its fun! Add OnceWrapper test --- (limited to 'src/sugar/tutorius') 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() -- cgit v0.9.1