def close_file(self, file_): """ Close and check the file """ file_.seek(0) case = ByteStreamToStreamResult(file_) result = StreamToDict(self.handle_dict) result.startTestRun() case.run(result) result.stopTestRun() file_.close()
def to_disk(argv=None, stdin=None, stdout=None): if stdout is None: stdout = sys.stdout if stdin is None: stdin = sys.stdin parser = optparse.OptionParser( description="Export a subunit stream to files on disk.", epilog=dedent("""\ Creates a directory per test id, a JSON file with test metadata within that directory, and each attachment is written to their name relative to that directory. Global packages (no test id) are discarded. Exits 0 if the export was completed, or non-zero otherwise. """)) parser.add_option("-d", "--directory", help="Root directory to export to.", default=".") options, args = parser.parse_args(argv) if len(args) > 1: raise Exception("Unexpected arguments.") if len(args): source = io.open(args[0], 'rb') else: source = stdin exporter = DiskExporter(options.directory) result = StreamToDict(exporter.export) run_tests_from_stream(source, result, protocol_version=2) return 0
def get_test_ids(self, run_id): """Return the test ids from the specified run. :param run_id: the id of the test run to query. :return: a list of test ids for the tests that were part of the specified test run. """ run = self.get_test_run(run_id) ids = [] def gather(test_dict): ids.append(test_dict['id']) result = StreamToDict(gather) result.startTestRun() try: run.get_test().run(result) finally: result.stopTestRun() return ids
def main(): os.environ["PYTHON_API_KEY"] = api_key test_suites = _collect_test_suites() main_test_suite = TestSuite() for test_suite in test_suites: main_test_suite.addTests(test_suite) concurrent_suite = ConcurrentStreamTestSuite( lambda: ((case, None) for case in main_test_suite)) result = StreamToDict(callback) result.startTestRun() try: concurrent_suite.run(result) finally: result.stopTestRun() all = SUCCESS + FAILS print("All: " + str(all) + " SUCCESS: " + str(SUCCESS) + " FAILS: " + str(FAILS)) if 'FAILED' in globals() and FAILED: sys.exit(1)
def main(): os.environ["PYTHON_API_KEY"] = api_key test_suites = _collect_test_suites() main_test_suite = TestSuite() for test_suite in test_suites: main_test_suite.addTests(test_suite) concurrent_suite = ConcurrentStreamTestSuite(lambda: ((case, None) for case in main_test_suite)) result = StreamToDict(callback) result.startTestRun() try: concurrent_suite.run(result) finally: result.stopTestRun() all = SUCCESS + FAILS print("All: " + str(all) + " SUCCESS: " + str(SUCCESS) + " FAILS: " + str(FAILS)) if 'FAILED' in globals() and FAILED: sys.exit(1)
def convert_stream(stream_file, strip_details=False): """Converts a subunit stream into a raw list of test dicts. :param stream_file: subunit stream to be converted :param strip_details: if True, remove test details (e.g. stdout/stderr) :return: a list of individual test results """ ret = [] result_stream = subunit.ByteStreamToStreamResult(stream_file) starts = StreamResult() summary = StreamSummary() outcomes = StreamToDict( partial(_read_test, out=ret, strip_details=strip_details)) result = CopyStreamResult([starts, outcomes, summary]) result.startTestRun() result_stream.run(result) result.stopTestRun() return ret