示例#1
0
    def testOneFile(self):
        self.shortDescription()
        fsm = parseFSM(self.fsmlFile)
        with open(self.inputFile) as inputFile, open(
                self.correctOutputFile) as outFile:
            correctInputJson = json.load(inputFile)

            # (1) this is the correct output which is created together with the input
            correctJsonOutput = json.load(outFile)

            # (2) this is the output of the Simulator.py module of assignment 2
            simulatedJsonOutput = simulateFSM(fsm, list(correctInputJson))

            # (3) what follows is the output of the dynamically generated TurnstileStepper modules
            generateCode(fsm)  # generate Stepper and Handler
            import TurnstileHandler_generated  # import the newly generated modules (& update their reference)
            reload(TurnstileHandler_generated)
            import TurnstileStepper_generated
            reload(TurnstileStepper_generated)
            stepper = TurnstileStepper_generated.Stepper()
            generatedJsonOutput = stepper.simulateFSM_generated(
                list(correctInputJson))
            try:
                os.remove('./TurnstileStepper_generated.pyc')
                os.remove('./TurnstileHandler_generated.pyc')
            except OSError:
                pass

            # assert all 3 are equal
            self.assertEqual(correctJsonOutput, simulatedJsonOutput)
            self.assertEqual(correctJsonOutput, generatedJsonOutput)
示例#2
0
    def testOneFile(self):
        self.shortDescription()
        fsm = parseFSM(self.fsmlFile)
        with open(self.inputFile) as inputFile, open(self.correctOutputFile) as outFile:
            correctInputJson = json.load(inputFile)

            # (1) this is the correct output which is created together with the input
            correctJsonOutput = json.load(outFile)

            # (2) this is the output of the Simulator.py module of assignment 2
            simulatedJsonOutput = simulateFSM(fsm, list(correctInputJson))

             # (3) what follows is the output of the dynamically generated TurnstileStepper modules
            generateCode(fsm)  # generate Stepper and Handler
            import TurnstileHandler_generated  # import the newly generated modules (& update their reference)
            reload(TurnstileHandler_generated)
            import TurnstileStepper_generated
            reload(TurnstileStepper_generated)
            stepper = TurnstileStepper_generated.Stepper()
            generatedJsonOutput = stepper.simulateFSM_generated(list(correctInputJson))
            try:
                os.remove('./TurnstileStepper_generated.pyc')
                os.remove('./TurnstileHandler_generated.pyc')
            except OSError:
                pass

            # assert all 3 are equal
            self.assertEqual(correctJsonOutput, simulatedJsonOutput)
            self.assertEqual(correctJsonOutput, generatedJsonOutput)
示例#3
0
文件: MainFSM.py 项目: nico1510/sle
def main():
    try:
        fsm = parseFSM("./sample.fsml")
        sampleInput = json.load(open("./sample_input.json", "r"))

        # just for visualization of the fsm dict (not needed anywhere in the code)
        jsonFile = open("./sample_fsml.json", 'w')
        jsonFile.write(json.dumps(fsm))

        # check the ok constraints
        ok(fsm)
        #simulate the fsm
        output = simulateFSM(fsm, sampleInput)
        # dump the simulation output to file
        outFile = open("./sample_output.json", 'w')
        outFile.write(json.dumps(output))

        #generate Code
        generateCode(fsm)

        #draw fsm
        drawFSM(fsm)

    except FsmException:
        raise
示例#4
0
def main():
    try:
        fsm = parseFSM("./sample.fsml")
        sampleInput = json.load(open("./sample_input.json", "r"))

        # just for visualization of the fsm dict (not needed anywhere in the code)
        jsonFile = open("./sample_fsml.json", 'w')
        jsonFile.write(json.dumps(fsm))

        # check the ok constraints
        ok(fsm)
        #simulate the fsm
        output = simulateFSM(fsm, sampleInput)
        # dump the simulation output to file
        outFile = open("./sample_output.json", 'w')
        outFile.write(json.dumps(output))

        #generate Code
        generateCode(fsm)

        #draw fsm
        drawFSM(fsm)

    except FsmException:
        raise