def testUndoDo(self): """ Test an undo() do() sequence. """ state = {"actions": 2} class Action(UndoableAction): def do(self): state["actions"] += 1 def undo(self): state["actions"] -= 1 stack = UndoableActionStack("meh") action1 = Action() action2 = Action() stack.push(action1) stack.push(action2) stack.undo() self.assertEqual(state["actions"], 0) stack.do() self.assertEqual(state["actions"], 2)
def testUndoDo(self): """ Test an undo() do() sequence. """ state = {"done": True, "actions": 2} def doneCb(action, value): state["done"] = value state["done"] = 2 class Action(UndoableAction): def do(self): state["actions"] += 1 self._done() def undo(self): state["actions"] -= 1 self._undone() stack = UndoableActionStack("meh") stack.connect("done", doneCb, True) stack.connect("undone", doneCb, False) action1 = Action() action2 = Action() stack.push(action1) stack.push(action2) stack.undo() self.assertEqual(state["actions"], 0) self.assertFalse(state["done"]) stack.do() self.assertEqual(state["actions"], 2) self.assertTrue(state["done"])
def testDoUndoEmpty(self): """ Undo an empty stack. """ state = {"done": True} def doneCb(action, value): state["done"] = value stack = UndoableActionStack("meh") stack.connect("done", doneCb, True) stack.connect("undone", doneCb, False) stack.undo() self.assertFalse(state["done"]) stack.do() self.assertTrue(state["done"])
def test_undo_do(self): """Checks an undo() and do() sequence.""" state = {"actions": 2} class Action(UndoableAction): def do(self): state["actions"] += 1 def undo(self): state["actions"] -= 1 stack = UndoableActionStack("meh") action1 = Action() action2 = Action() stack.push(action1) stack.push(action2) stack.undo() self.assertEqual(state["actions"], 0) stack.do() self.assertEqual(state["actions"], 2)