Пример #1
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.failUnlessEqual(state["actions"], 0)
        self.failIf(state["done"])

        stack.do()
        self.failUnlessEqual(state["actions"], 2)
        self.failUnless(state["done"])
Пример #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.failUnlessEqual(state["actions"], 0)
        self.failIf(state["done"])

        stack.do()
        self.failUnlessEqual(state["actions"], 2)
        self.failUnless(state["done"])
Пример #3
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.failIf(state["done"])

        stack.do()
        self.failUnless(state["done"])
Пример #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.failIf(state["done"])

        stack.do()
        self.failUnless(state["done"])