Beispiel #1
0
    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)
Beispiel #2
0
    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"])
Beispiel #3
0
    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"])
Beispiel #4
0
    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"])
Beispiel #5
0
    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"])
Beispiel #6
0
    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)