def test_generate_random_with_variable_resolving_problem(self): m = robomachine.parse(_VAR_PROBLEM_MACHINE) out = StringIO() robomachine.generate(m, max_actions=1, output=out, strategy=RandomStrategy) self.assertEqual(_TEST_VAR_PROBLEM_MACHINE, out.getvalue())
def main(): args = parser.parse_args() if args.input.endswith('.txt') and not args.output: sys.exit('txt input not allowed when no output') try: with open(args.input, 'r') as inp: machine = robomachine.parse(inp.read()) except IOError, e: sys.exit(unicode(e))
def test_parsing(self): m = robomachine.parse(_MACHINA2) self.assertEqual(m.states[0].name, 'A') self.assertEqual(m.states[0].steps, [' Foo bar', ' Bar foo']) self.assertEqual([a.name for a in m.states[0].actions], ['first', 'second', '']) self.assertEqual([a.next_state.name for a in m.states[0].actions], ['B', 'C', 'D']) self.assertEqual(m.states[1].name, 'B') self.assertEqual(m.states[1].steps, []) self.assertEqual([a.name for a in m.states[1].actions], ['something else', 'other thing']) self.assertEqual([a.next_state.name for a in m.states[1].actions], ['A', 'C']) self.assertEqual(m.states[2].name, 'C') self.assertEqual(m.states[2].steps, [' No Operation #This is a comment']) self.assertEqual(m.states[2].actions, [])
def test_parse_machina_state_steps(self): m = robomachine.parse(_MACHINA) self.assertEqual([' Log In Start State'], m.states[0].steps) self.assertEqual([' Log In End State'], m.states[1].steps)
def test_parse_machina_state_actions(self): m = robomachine.parse(_MACHINA) self.assertEqual(['Some keyword'], [a.name for a in m.states[0].actions]) self.assertEqual([], [a.name for a in m.states[1].actions])
def test_parse_machina_state_names(self): m = robomachine.parse(_MACHINA) self.assertEqual(['Start State', 'End State'], [s.name for s in m.states])
def test_generate_all_dfs_max_actions_2(self): m = robomachine.parse(_MACHINA2) out = StringIO() robomachine.generate(m, max_actions=2, output=out) self.assertEqual(_TESTS2_GENERATE_ALL_DFS_MAX_ACTIONS_2, out.getvalue())
def test_invalid_state_parsing(self): try: m = robomachine.parse(_INVALID_STATE_MACHINE) self.fail('Should raise exception') except RoboMachineParsingException: pass