class TestRedoAction(unittest.TestCase): def setUp(self): self.stack = CommandStack() self.undo_manager = UndoManager() self.stack.undo_manager = self.undo_manager self.undo_manager.active_stack = self.stack self.command = SimpleCommand() def test_update(self): redo_action = RedoAction(command=self.command, undo_manager=self.undo_manager) self.stack.push(self.command) self.undo_manager.undo() self.assertTrue(redo_action.enabled) self.assertEqual(redo_action.name, "&Redo Increment by 1")
class TestUndoManager(unittest.TestCase, UnittestTools): def setUp(self): self.stack_a = CommandStack() self.stack_b = CommandStack() self.undo_manager = UndoManager() self.stack_a.undo_manager = self.undo_manager self.stack_b.undo_manager = self.undo_manager self.undo_manager.active_stack = self.stack_a self.command = SimpleCommand() # Command pushing tests --------------------------------------------------- def test_undo(self): self.assertEqual(self.stack_a._index, -1) self.stack_a.push(self.command) self.assertEqual(self.stack_a._index, 0) with self.assertTraitChanges(self.undo_manager, 'stack_updated', count=1): self.undo_manager.undo() self.assertEqual(self.stack_a._index, -1) def test_redo(self): self.assertEqual(self.stack_a._index, -1) self.stack_a.push(self.command) self.undo_manager.undo() self.assertEqual(self.stack_a._index, -1) with self.assertTraitChanges(self.undo_manager, 'stack_updated', count=1): self.undo_manager.redo() self.assertEqual(self.stack_a._index, 0) def test_change_active_stack(self): for _ in range(5): self.stack_a.push(self.command) self.assertEqual(self.stack_a._index, 4) self.undo_manager.active_stack = self.stack_b for _ in range(5): self.stack_b.push(self.command) self.assertEqual(self.stack_b._index, 4) for _ in range(3): self.undo_manager.undo() self.undo_manager.redo() self.assertEqual(self.stack_a._index, 4) self.assertEqual(self.stack_b._index, 2) def test_active_stack_clean(self): self.assertTrue(self.undo_manager.active_stack_clean) self.stack_a.push(self.command) self.assertFalse(self.undo_manager.active_stack_clean) self.undo_manager.active_stack = None self.assertTrue(self.undo_manager.active_stack_clean)