Пример #1
0
    def test_consume_add_arg(self):
        fsm = FSM()
        fsm.newState("A")
        fsm.newState("B")
        fsm.setStartState("A")

        def _test(*args):
            self.assertEqual(args[-1], "test")
        fsm.addTransition("A", "B", "input1", _test, "foo")
        fsm.consume("input1", "test")
Пример #2
0
class TestFSM(unittest.TestCase):
    def setUp(self):
        self.fsm = FSM("0")
        self.fsm.newState("1")
        self.fsm.addTransition("0", "0", "0", self.zeroIgnored)
        self.fsm.addTransition("0", "1", "1", self.oneSeen)
        self.fsm.addTransition("1", "1", "1", self.oneIgnored)
        self.fsm.addTransition("1", "0", "0", self.zeroSeen)

    def zeroSeen(self):
        pass
    def zeroIgnored(self):
        pass
    def oneSeen(self):
        pass
    def oneIgnored(self):
        pass

    def test_add_indeterministic_transition(self):
        try:
            self.fsm.addTransition("0", "0", "0", None)
        except FSMError, e:
            pass
        else: