Esempio n. 1
0
    def test_add_middle_mergeable(self):
        history = UndoHistory()
        example = SimpleExample(str_value='foo', value=10)
        undo_item = UndoItem(
            object=example,
            name='str_value',
            old_value='bar',
            new_value='baz',
        )

        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, 1)
        self.assertTrue(history.can_undo)
        self.assertFalse(history.can_redo)
Esempio n. 2
0
    def test_undo_last(self):
        history = UndoHistory()
        self._populate_history(history)

        with self.assertTraitDoesNotChange(history, 'undoable'):
            with self.assertTraitChanges(history, 'redoable', count=1):
                with self.assertTraitChanges(self._example,
                                             'anytrait',
                                             count=1):  # noqa: E501
                    history.undo()

        self.assertEqual(history.now, 2)
        self.assertTrue(history.can_undo)
        self.assertTrue(history.can_redo)
Esempio n. 3
0
    def test_clear_middle(self):
        history = UndoHistory()
        self._populate_history(history)
        history.undo()
        history.undo()

        with self.assertTraitChanges(history, 'redoable', count=1):
            with self.assertTraitChanges(history, 'undoable', count=1):
                with self.assertTraitDoesNotChange(self._example, 'anytrait'):
                    history.clear()

        self.assertEqual(history.now, 0)
        self.assertFalse(history.can_undo)
        self.assertFalse(history.can_redo)
Esempio n. 4
0
    def test_revert_middle(self):
        history = UndoHistory()
        self._populate_history(history)
        history.undo()
        history.undo()

        with self.assertTraitChanges(history, 'redoable', count=1):
            with self.assertTraitChanges(history, 'undoable', count=1):
                with self.assertTraitChanges(self._example,
                                             'anytrait',
                                             count=1):  # noqa: E501
                    history.revert()

        self.assertEqual(history.now, 0)
        self.assertFalse(history.can_undo)
        self.assertFalse(history.can_redo)