def test_generation_with_no_tests(self): mock_machine = RoboMachine(states=[], variables=[], rules=[]) output = StringIO() robomachine.generate(machine=mock_machine, output=output, strategy=_MockStrategyWithNoTests) self.assertEqual('*** Test Cases ***', output.getvalue())
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 test_generation_with_same_generated_tests(self): mock_machine = RoboMachine(states=[State('bar', [], [])], variables=[], rules=[]) output = StringIO() robomachine.generate(machine=mock_machine, max_tests=1000, output=output, strategy=_MockStrategyWithSameTests) self.assertEqual( 1, sum(1 for line in output.getvalue().splitlines() if line.startswith('Test ')))
def test_generation_with_same_generated_tests(self): mock_machine = RoboMachine(states=[State('bar', [], [])], variables=[], rules=[]) output = StringIO() robomachine.generate(machine=mock_machine, max_tests=1000, output=output, strategy=_MockStrategyWithSameTests) self.assertEqual(1, sum(1 for line in output.getvalue().splitlines() if line.startswith('Test ')))
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_generate_all_dfs(self): m = parsing.parse(_LOGIN_MACHINE) out = StringIO() robomachine.generate(m, output=out) self.assertEqual(_LOGIN_TESTS_GENERATE_ALL_DFS, out.getvalue())
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)) except RoboMachineParsingException, e: sys.exit(1) output = args.output or os.path.splitext(args.input)[0] + '.txt' with open(output, 'w') as out: robomachine.generate(machine, max_tests=args.tests_max, max_actions=args.actions_max, to_state=args.to_state, output=out, strategy=_select_strategy( args.generation_algorithm)) print 'generated %s' % output if not args.do_not_execute: print 'running generated tests with pybot' retcode = subprocess.call(['pybot', output]) sys.exit(retcode) def _select_strategy(strategy): if strategy == 'random': return RandomStrategy if strategy == 'dfs': return DepthFirstSearchStrategy
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)) except RoboMachineParsingException, e: sys.exit(1) output = args.output or os.path.splitext(args.input)[0]+'.txt' with open(output, 'w') as out: robomachine.generate(machine, max_tests=args.tests_max, max_actions=args.actions_max, to_state=args.to_state, output=out, strategy=_select_strategy(args.generation_algorithm)) print 'generated %s' % output if not args.do_not_execute: print 'running generated tests with pybot' retcode = subprocess.call(['pybot', output]) sys.exit(retcode) def _select_strategy(strategy): if strategy == 'random': return RandomStrategy if strategy == 'dfs': return DepthFirstSearchStrategy if strategy == 'allpairs-random': try: