def setUp(self): self.undo_manager = UndoManager() self.undo_manager.undo = MagicMock() self.undo_manager.redo = MagicMock() self.component = Component() self.tool = UndoTool(component=self.component, undo_manager=self.undo_manager) self.component.tools.append(self.tool)
def _undo_manager_default(self): """ Trait initializer. """ # We make sure the undo package is entirely optional. try: from apptools.undo.api import UndoManager except ImportError: return None return UndoManager()
def _undo_manager_default(self): return UndoManager()
def _undo_manager_default(self): from apptools.undo.api import UndoManager undo_manager = UndoManager() return undo_manager
def setUp(self): self.stack = CommandStack() undo_manager = UndoManager() self.stack.undo_manager = undo_manager self.command = SimpleCommand()
def setUp(self): self.manager = UndoManager() self.stack = CommandStack(undo_manager=self.manager) self.manager.active_stack = self.stack self.data = TargetClass() self.data.value = 0
class TestAttributeSetCommand(TestCase): def setUp(self): self.manager = UndoManager() self.stack = CommandStack(undo_manager=self.manager) self.manager.active_stack = self.stack self.data = TargetClass() self.data.value = 0 def test_command_do(self): command = AttributeSetCommand( data=self.data, attribute='value', value=1 ) self.manager.active_stack.push(command) self.assertEqual(self.data.value, 1) def test_command_undo(self): command = AttributeSetCommand( data=self.data, attribute='value', value=1 ) self.manager.active_stack.push(command) self.manager.active_stack.undo() self.assertEqual(self.data.value, 0) def test_command_redo(self): command = AttributeSetCommand( data=self.data, attribute='value', value=1 ) self.manager.active_stack.push(command) self.manager.undo() self.manager.redo() self.assertEqual(self.data.value, 1) def test_mergeable_command_do(self): command1 = AttributeSetCommand( data=self.data, attribute='value', value=1, mergeable=True, ) command2 = AttributeSetCommand( data=self.data, attribute='value', value=2, mergeable=True, ) self.manager.active_stack.push(command1) self.manager.active_stack.push(command2) self.assertEqual(self.data.value, 2) def test_mergeable_command_undo(self): command1 = AttributeSetCommand( data=self.data, attribute='value', value=1, mergeable=True, ) command2 = AttributeSetCommand( data=self.data, attribute='value', value=2, mergeable=True, ) self.manager.active_stack.push(command1) self.manager.active_stack.push(command2) self.manager.active_stack.undo() self.assertEqual(self.data.value, 0) def test_mergeable_command_redo(self): command1 = AttributeSetCommand( data=self.data, attribute='value', value=1, mergeable=True, ) command2 = AttributeSetCommand( data=self.data, attribute='value', value=2, mergeable=True, ) self.manager.active_stack.push(command1) self.manager.active_stack.push(command2) self.manager.active_stack.undo() self.manager.active_stack.redo() self.assertEqual(self.data.value, 2) def test_unmergeable_command_undo_1(self): command1 = AttributeSetCommand( data=self.data, attribute='value', value=1, ) command2 = AttributeSetCommand( data=self.data, attribute='value', value=2, mergeable=True, ) self.manager.active_stack.push(command1) self.manager.active_stack.push(command2) self.assertEqual(self.data.value, 2) self.manager.active_stack.undo() self.assertEqual(self.data.value, 1) self.manager.active_stack.undo() self.assertEqual(self.data.value, 0) def test_unmergeable_command_undo_2(self): command1 = AttributeSetCommand( data=self.data, attribute='value', value=1, mergeable=True, ) command2 = AttributeSetCommand( data=self.data, attribute='value', value=2, ) self.manager.active_stack.push(command1) self.manager.active_stack.push(command2) self.manager.active_stack.undo() self.assertEqual(self.data.value, 1) self.manager.active_stack.undo() self.assertEqual(self.data.value, 0)
def _undo_manager_default(self): """ Return the default undo manager """ from apptools.undo.api import UndoManager undo_manager = UndoManager(active_stack=self.command_stack) self.command_stack.undo_manager = undo_manager return undo_manager