1#!/usr/bin/env python
2# Copyright 2015 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"""A wrapper around typ (test your projects)."""
7
8import os
9import sys
10
11
12def Run(top_level_dir, path=None):
13  """Runs a set of Python tests using typ.
14
15  Args:
16    top_level_dir: Directory to look for Python unit tests in.
17    path: A list of extra paths to add to sys.path when running the tests.
18
19  Returns:
20    An exit code (0 for success, otherwise non-zero).
21  """
22  typ_path = os.path.abspath(os.path.join(
23      os.path.dirname(__file__), os.path.pardir, 'third_party', 'typ'))
24  _AddToPathIfNeeded(typ_path)
25  import typ
26  return typ.main(
27      top_level_dir=top_level_dir,
28      path=(path or []),
29      coverage_source=[top_level_dir])
30
31
32def _AddToPathIfNeeded(path):
33  if path not in sys.path:
34    sys.path.insert(0, path)
35