Exemplo n.º 1
0
 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())
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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))
Exemplo n.º 4
0
 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, [])
Exemplo n.º 5
0
 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, [])
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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])
Exemplo n.º 8
0
 def test_parse_machina_state_names(self):
     m = robomachine.parse(_MACHINA)
     self.assertEqual(['Start State', 'End State'], [s.name for s in m.states])
Exemplo n.º 9
0
 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())
Exemplo n.º 10
0
 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())
Exemplo n.º 11
0
 def test_invalid_state_parsing(self):
     try:
         m = robomachine.parse(_INVALID_STATE_MACHINE)
         self.fail('Should raise exception')
     except RoboMachineParsingException:
         pass
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 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])
Exemplo n.º 14
0
 def test_parse_machina_state_names(self):
     m = robomachine.parse(_MACHINA)
     self.assertEqual(['Start State', 'End State'],
                      [s.name for s in m.states])
Exemplo n.º 15
0
 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())
Exemplo n.º 16
0
 def test_invalid_state_parsing(self):
     try:
         m = robomachine.parse(_INVALID_STATE_MACHINE)
         self.fail('Should raise exception')
     except RoboMachineParsingException:
         pass