Пример #1
0
    def test_add_end_extend_merge(self):
        history = UndoHistory()
        example = SimpleExample(str_value='foo', value=10)
        undo_item = UndoItem(
            object=example,
            name='str_value',
            old_value='foo',
            new_value='baz',
        )

        history.add(
            UndoItem(
                object=example,
                name='str_value',
                old_value='foo',
                new_value='bar',
            ))

        with self.assertTraitDoesNotChange(history, 'undoable'):
            with self.assertTraitDoesNotChange(history, 'redoable'):
                history.add(undo_item, extend=True)

        self.assertEqual(history.now, 1)
        self.assertTrue(history.can_undo)
        self.assertFalse(history.can_redo)
        # XXX this is testing private state to ensure merge happened
        self.assertEqual(len(history.stack._stack), 1)
Пример #2
0
    def test_add_end_extend(self):
        history = UndoHistory()
        example = SimpleExample(str_value='foo', value=10)
        undo_item = UndoItem(
            object=example,
            name='value',
            old_value=0,
            new_value=10,
        )

        history.add(
            UndoItem(
                object=example,
                name='str_value',
                old_value='foo',
                new_value='bar',
            ))

        with self.assertTraitDoesNotChange(history, 'undoable'):
            with self.assertTraitDoesNotChange(history, 'redoable'):
                history.add(undo_item, extend=True)

        self.assertEqual(history.now, 1)
        self.assertTrue(history.can_undo)
        self.assertFalse(history.can_redo)
Пример #3
0
    def test_general_command_do(self):
        history = UndoHistory()
        command = DummyCommand()

        history.add(command)

        self.assertEqual(command.data, "do")
Пример #4
0
    def test_add_empty(self):
        history = UndoHistory()
        example = SimpleExample(str_value='foo')

        undo_item = UndoItem(
            object=example,
            name='str_value',
            old_value='foo',
            new_value='bar',
        )

        with self.assertTraitChanges(history, 'undoable', count=1):
            with self.assertTraitDoesNotChange(history, 'redoable'):
                history.add(undo_item)

        self.assertEqual(history.now, 1)
        self.assertTrue(history.can_undo)
        self.assertFalse(history.can_redo)
Пример #5
0
    def test_add_middle(self):
        history = UndoHistory()
        example = SimpleExample(str_value='foo', value=10)
        undo_item = UndoItem(
            object=example,
            name='value',
            old_value=0,
            new_value=10,
        )

        history.add(
            UndoItem(
                object=example,
                name='str_value',
                old_value='foo',
                new_value='bar',
            ))
        history.add(
            UndoItem(
                object=example,
                name='str_value',
                old_value='bar',
                new_value='wombat',
            ), )
        history.undo()

        with self.assertTraitDoesNotChange(history, 'undoable'):
            with self.assertTraitChanges(history, 'redoable', count=1):
                history.add(undo_item)

        self.assertEqual(history.now, 2)
        self.assertTrue(history.can_undo)
        self.assertFalse(history.can_redo)