def run_wpr_test(self, test_filter=[], invert=False): """Wrapper that mocks the _run method and returns its result.""" class FakeStdout: def __init__(self): self.line_index = 0 self.lines = [ 'Test Case \'-[a 1]\' started.', 'Test Case \'-[a 1]\' has uninteresting logs.', 'Test Case \'-[a 1]\' passed (0.1 seconds)', 'Test Case \'-[b 2]\' started.', 'Test Case \'-[b 2]\' passed (0.1 seconds)', 'Test Case \'-[c 3]\' started.', 'Test Case \'-[c 3]\' has interesting failure info.', 'Test Case \'-[c 3]\' failed (0.1 seconds)', ] def readline(self): if self.line_index < len(self.lines): return_line = self.lines[self.line_index] self.line_index += 1 return return_line else: return None class FakeProcess: def __init__(self): self.stdout = FakeStdout() self.returncode = 0 def stdout(self): return self.stdout def wait(self): return def popen(recipe_cmd, env, stdout, stderr): return FakeProcess() tr = test_runner.WprProxySimulatorTestRunner( 'fake-app', 'fake-iossim', 'replay-path', 'platform', 'os', 'wpr-tools-path', 'xcode-version', 'xcode-build', 'out-dir', ) self.mock(test_runner.WprProxySimulatorTestRunner, 'wprgo_start', lambda a,b: None) self.mock(test_runner.WprProxySimulatorTestRunner, 'wprgo_stop', lambda _: None) self.mock(os.path, 'isfile', lambda _: True) self.mock(glob, 'glob', lambda _: ["file1", "file2"]) self.mock(subprocess, 'Popen', popen) tr.xctest_path = 'fake.xctest' cmd = tr.get_launch_command(test_filter=test_filter, invert=invert) return tr._run(cmd=cmd, shards=1)
def test_init(self): """Ensures instance is created.""" tr = test_runner.WprProxySimulatorTestRunner( 'fake-app', 'fake-iossim', 'replay-path', 'platform', 'os', 'wpr-tools-path', 'xcode-version', 'xcode-build', 'out-dir', ) self.assertTrue(tr)
def test_wpr_tools_not_found(self): """Ensures WprToolsNotFoundError is raised.""" self.mock(os.path, 'exists', lambda p: not p.endswith('bad-tools-path')) with self.assertRaises(test_runner.WprToolsNotFoundError): test_runner.WprProxySimulatorTestRunner( 'fake-app', 'fake-iossim', 'replay-path', 'platform', 'os', 'bad-tools-path', 'xcode-version', 'xcode-build', 'out-dir', )
def main(): logging.basicConfig(format='[%(asctime)s:%(levelname)s] %(message)s', level=logging.DEBUG, datefmt='%I:%M:%S') args, test_args = parse_args() summary = {} tr = None if not os.path.exists(args.out_dir): os.makedirs(args.out_dir) try: if args.xcode_parallelization: tr = xcodebuild_runner.SimulatorParallelTestRunner( args.app, args.iossim, args.xcode_build_version, args.version, args.platform, out_dir=args.out_dir, mac_toolchain=args.mac_toolchain_cmd, retries=args.retries, shards=args.shards, xcode_path=args.xcode_path, test_cases=args.test_cases, test_args=test_args, env_vars=args.env_var) elif args.replay_path != 'NO_PATH': tr = test_runner.WprProxySimulatorTestRunner( args.app, args.iossim, args.replay_path, args.platform, args.version, args.wpr_tools_path, args.xcode_build_version, args.out_dir, env_vars=args.env_var, mac_toolchain=args.mac_toolchain_cmd, retries=args.retries, shards=args.shards, test_args=test_args, test_cases=args.test_cases, xcode_path=args.xcode_path, xctest=args.xctest, ) elif args.iossim and args.platform and args.version: tr = test_runner.SimulatorTestRunner( args.app, args.iossim, args.platform, args.version, args.xcode_build_version, args.out_dir, env_vars=args.env_var, mac_toolchain=args.mac_toolchain_cmd, retries=args.retries, shards=args.shards, test_args=test_args, test_cases=args.test_cases, use_trusted_cert=args.use_trusted_cert, wpr_tools_path=args.wpr_tools_path, xcode_path=args.xcode_path, xctest=args.xctest, ) else: tr = test_runner.DeviceTestRunner( args.app, args.xcode_build_version, args.out_dir, env_vars=args.env_var, mac_toolchain=args.mac_toolchain_cmd, restart=args.restart, retries=args.retries, test_args=test_args, test_cases=args.test_cases, xcode_path=args.xcode_path, xctest=args.xctest, ) return 0 if tr.launch() else 1 except test_runner.TestRunnerError as e: sys.stderr.write(traceback.format_exc()) summary['step_text'] = '%s%s' % (e.__class__.__name__, ': %s' % e.args[0] if e.args else '') # test_runner.Launch returns 0 on success, 1 on failure, so return 2 # on exception to distinguish between a test failure, and a failure # to launch the test at all. return 2 finally: if tr: summary['logs'] = tr.logs with open(os.path.join(args.out_dir, 'summary.json'), 'w') as f: json.dump(summary, f) if tr: with open(os.path.join(args.out_dir, 'full_results.json'), 'w') as f: json.dump(tr.test_results, f)