• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env vpython3
2# Copyright 2016 The Chromium Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import json
7import os
8import sys
9
10# Add src/testing/ into sys.path for importing common without pylint errors.
11sys.path.append(
12    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
13from scripts import common
14
15
16def main_run(args):
17  typ_path = os.path.abspath(os.path.join(
18      os.path.dirname(__file__), os.path.pardir, os.path.pardir,
19      'third_party', 'catapult', 'third_party', 'typ'))
20  _AddToPathIfNeeded(typ_path)
21  import typ #pylint: disable=import-outside-toplevel
22
23  top_level_dir = os.path.join(
24      common.SRC_DIR, 'headless', 'lib', 'browser', 'devtools_api')
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
38  valid = bool(rc <= common.MAX_FAILURES_EXIT_STATUS and
39               ((rc == 0) or failures))
40  common.record_local_script_results(
41      'headless_python_unittests', args.output, list(failures.keys()), valid)
42
43  return rc
44
45
46def main_compile_targets(args):
47  json.dump([], args.output)
48
49
50def _AddToPathIfNeeded(path):
51  if path not in sys.path:
52    sys.path.insert(0, path)
53
54
55if __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))
61