Takuto Ikuta | d0a8c00 | 2022-07-01 01:56:59 | [diff] [blame] | 1 | #!/usr/bin/env vpython3 |
skyostil | 1ec102e | 2016-10-13 03:11:36 | [diff] [blame] | 2 | # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | import json |
| 7 | import os |
| 8 | import sys |
| 9 | |
Joshua Hood | 3fade1f | 2022-05-04 16:00:42 | [diff] [blame] | 10 | # Add src/testing/ into sys.path for importing common without pylint errors. |
| 11 | sys.path.append( |
| 12 | os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) |
| 13 | from scripts import common |
skyostil | 1ec102e | 2016-10-13 03:11:36 | [diff] [blame] | 14 | |
| 15 | |
| 16 | def main_run(args): |
| 17 | typ_path = os.path.abspath(os.path.join( |
| 18 | os.path.dirname(__file__), os.path.pardir, os.path.pardir, |
Ned Nguyen | c335c43 | 2018-04-23 01:16:46 | [diff] [blame] | 19 | 'third_party', 'catapult', 'third_party', 'typ')) |
skyostil | 1ec102e | 2016-10-13 03:11:36 | [diff] [blame] | 20 | _AddToPathIfNeeded(typ_path) |
Joshua Hood | 3fade1f | 2022-05-04 16:00:42 | [diff] [blame] | 21 | import typ #pylint: disable=import-outside-toplevel |
skyostil | 1ec102e | 2016-10-13 03:11:36 | [diff] [blame] | 22 | |
altimin | eaffa8e0 | 2016-11-08 23:56:31 | [diff] [blame] | 23 | top_level_dir = os.path.join( |
| 24 | common.SRC_DIR, 'headless', 'lib', 'browser', 'devtools_api') |
skyostil | 1ec102e | 2016-10-13 03:11:36 | [diff] [blame] | 25 | with common.temporary_file() as tempfile_path: |
| 26 | rc = typ.main( |
| 27 | argv=[], |
| 28 | top_level_dir=top_level_dir, |
| 29 | write_full_results_to=tempfile_path, |
| 30 | coverage_source=[top_level_dir]) |
| 31 | |
| 32 | with open(tempfile_path) as f: |
| 33 | results = json.load(f) |
| 34 | |
| 35 | parsed_results = common.parse_common_test_results(results, test_separator='.') |
| 36 | failures = parsed_results['unexpected_failures'] |
| 37 | |
Ben Pastene | 58c7818f | 2021-07-01 16:58:07 | [diff] [blame] | 38 | valid = bool(rc <= common.MAX_FAILURES_EXIT_STATUS and |
| 39 | ((rc == 0) or failures)) |
| 40 | common.record_local_script_results( |
Takuto Ikuta | d0a8c00 | 2022-07-01 01:56:59 | [diff] [blame] | 41 | 'headless_python_unittests', args.output, list(failures.keys()), valid) |
skyostil | 1ec102e | 2016-10-13 03:11:36 | [diff] [blame] | 42 | |
| 43 | return rc |
| 44 | |
| 45 | |
| 46 | def main_compile_targets(args): |
| 47 | json.dump([], args.output) |
| 48 | |
| 49 | |
| 50 | def _AddToPathIfNeeded(path): |
| 51 | if path not in sys.path: |
| 52 | sys.path.insert(0, path) |
| 53 | |
| 54 | |
| 55 | if __name__ == '__main__': |
| 56 | funcs = { |
| 57 | 'run': main_run, |
| 58 | 'compile_targets': main_compile_targets, |
| 59 | } |
| 60 | sys.exit(common.run_script(sys.argv[1:], funcs)) |