diff options
author | Vincent 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) |
commit | 9341b97d9d8fdeb842efbb1abf402ba4f8ba28f5 (patch) | |
tree | 956fda6821f4229a29771f9517d7af4961668007 /src/sugar/tutorius/tests/coretests.py | |
parent | 5cdfcba9e827c2acf7dbad7890e8fcea241714a8 (diff) |
Add a test runner (no need to use it, but its fun!
Add OnceWrapper test
Diffstat (limited to 'src/sugar/tutorius/tests/coretests.py')
-rw-r--r-- | src/sugar/tutorius/tests/coretests.py | 50 |
1 files changed, 47 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() |