diff options
author | mike <michael.jmontcalm@gmail.com> | 2009-04-06 02:41:41 (GMT) |
---|---|---|
committer | mike <michael.jmontcalm@gmail.com> | 2009-04-06 02:41:41 (GMT) |
commit | 3e92e7a3ab862901e473e5f3a05d08d9af185f68 (patch) | |
tree | b85dcde72fee5ba9f8144458cc7339895aa597de /src/sugar/tutorius/tests/actiontests.py | |
parent | 7f030fd302c0be7ca7dc38863e1d9250df00ca31 (diff) |
Create chain action
Diffstat (limited to 'src/sugar/tutorius/tests/actiontests.py')
-rw-r--r-- | src/sugar/tutorius/tests/actiontests.py | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/src/sugar/tutorius/tests/actiontests.py b/src/sugar/tutorius/tests/actiontests.py index 2a60a65..76a6655 100644 --- a/src/sugar/tutorius/tests/actiontests.py +++ b/src/sugar/tutorius/tests/actiontests.py @@ -41,5 +41,57 @@ class PropsTest(unittest.TestCase): assert prop.get_properties() == ['a'], "Action does not contain property 'a'" +from sugar.tutorius.actions import ChainAction + +class ChainTester(Action): + def __init__(self, witness): + self._witness = witness + + def do(self, **kwargs): + self._witness.append([self,"do"]) + + def undo(self): + self._witness.append([self,"undo"]) + +class ChainActionTest(unittest.TestCase): + """Tester for ChainAction""" + def test_empty(self): + """If the expected empty behavior (do nothing) changes + and starts throwing exceptions, this will flag it""" + a = ChainAction() + a.do() + a.undo() + + def test_order(self): + witness = [] + first = ChainTester(witness) + second = ChainTester(witness) + + c = ChainAction(first, second) + assert witness == [], "Actions should not be triggered on init""" + c.do() + + assert witness[0][0] is first, "First triggered action must be 'first'" + assert witness[0][1] is "do", "Action do() should be triggered" + + assert witness[1][0] is second, "second triggered action must be 'second'" + assert witness[1][1] is "do", "Action do() should be triggered" + + assert len(witness) is 2, "Two actions should give 2 do's" + + #empty the witness list + while len(witness): + rm = witness.pop() + + c.undo() + assert witness[1][0] is first, "second triggered action must be 'first'" + assert witness[1][1] is "undo", "Action undo() should be triggered" + + assert witness[0][0] is second, "first triggered action must be 'second'" + assert witness[0][1] is "undo", "Action undo() should be triggered" + + assert len(witness) is 2, "Two actions should give 2 undo's" + + if __name__ == "__main__": - unittest.main()
\ No newline at end of file + unittest.main() |