Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Script to setup the environment to run unit tests. | 5 """Script to setup the environment to run unit tests. |
| 6 | 6 |
| 7 Modifies PYTHONPATH to automatically include parent, common and pylibs | 7 Modifies PYTHONPATH to automatically include parent, common and pylibs |
| 8 directories. | 8 directories. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import os | 11 import os |
| 12 import sys | 12 import sys |
| 13 import textwrap | |
| 13 | 14 |
| 14 RUNTESTS_DIR = os.path.dirname(os.path.abspath(__file__)) | 15 RUNTESTS_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 15 DATA_PATH = os.path.join(RUNTESTS_DIR, 'data') | 16 DATA_PATH = os.path.join(RUNTESTS_DIR, 'data') |
| 16 BASE_DIR = os.path.abspath(os.path.join(RUNTESTS_DIR, '..', '..', '..')) | 17 BASE_DIR = os.path.abspath(os.path.join(RUNTESTS_DIR, '..', '..', '..')) |
| 17 | 18 |
| 18 sys.path.insert(0, os.path.join(BASE_DIR, 'scripts')) | 19 sys.path.insert(0, os.path.join(BASE_DIR, 'scripts')) |
| 19 sys.path.insert(0, os.path.join(BASE_DIR, 'site_config')) | 20 sys.path.insert(0, os.path.join(BASE_DIR, 'site_config')) |
| 20 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party')) | 21 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party')) |
| 21 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'buildbot_slave_8_4')) | 22 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'buildbot_slave_8_4')) |
| 22 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'twisted_10_2')) | 23 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'twisted_10_2')) |
| 23 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'mock-1.0.1')) | 24 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'mock-1.0.1')) |
| 24 | 25 |
| 25 try: | 26 def ensure_coverage_importable(): |
| 26 # The C-compiled coverage engine is WAY faster than the pure python version. | 27 try: |
| 27 # If we have it, then don't bother with the pure python one. | 28 from distutils.version import StrictVersion |
| 28 import coverage | 29 import coverage |
| 29 except ImportError: | 30 if (StrictVersion(coverage.__version__) < StrictVersion('3.7') or |
| 30 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'coverage-3.6')) | 31 not coverage.collector.CTracer): |
| 31 import coverage | 32 del sys.modules['coverage'] |
| 33 del coverage | |
| 34 else: | |
| 35 return | |
| 36 except ImportError: | |
| 37 pass | |
| 32 | 38 |
| 33 def print_coverage_warning(): | 39 from pkg_resources import get_build_platform |
| 34 if not hasattr(coverage.collector, 'CTracer'): | 40 try: |
| 35 print "WARNING: Using the pure-python coverage module." | 41 # Python 2.7 or >= 3.2 |
| 36 print " Install the native python coverage module to speed recipe" | 42 from sysconfig import get_python_version |
| 37 print " training up by an order of magnitude." | 43 except ImportError: |
| 38 print | 44 from distutils.sysconfig import get_python_version |
| 39 print " pip install coverage" | 45 |
| 40 print " OR" | 46 cov_dir = os.path.join(BASE_DIR, 'third_party', 'coverage-3.7.1') |
| 41 print " easy_install coverage" | 47 cov_egg = os.path.join(cov_dir, 'dist', 'coverage-3.7.1-py%s-%s.egg' % ( |
| 48 get_python_version(), get_build_platform())) | |
| 49 | |
| 50 # The C-compiled coverage engine is WAY faster (and less buggy) than the pure | |
| 51 # python version, so we build the dist_egg if necessary. | |
| 52 if not os.path.exists(cov_egg): | |
| 53 import subprocess | |
| 54 print 'Building Coverage 3.7.1' | |
| 55 p = subprocess.Popen([sys.executable, 'setup.py', 'bdist_egg'], cwd=cov_dir, | |
| 56 stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
| 57 stdout, stderr = p.communicate() | |
| 58 if p.returncode != 0: | |
| 59 print 'Error while building :(' | |
| 60 print stdout | |
| 61 print stderr | |
| 62 if sys.platform.startswith('win'): | |
| 63 print textwrap.dedent(""" | |
| 64 I see that you\'re running Windows. Please install coverage by running | |
| 65 this executable from the internet: | |
|
Vadim Sh.
2014/04/04 19:47:09
:D
Maybe just link to PyPI page?
| |
| 66 https://pypi.python.org/packages/2.7/c/coverage/coverage-3.7.1.win32-py2 .7.exe#md5=fd290395319e4a7277cbcc086b7bba95 | |
| 67 """) | |
| 68 sys.exit(1) | |
| 69 | |
| 70 sys.path.insert(0, cov_egg) | |
| 71 | |
| 72 ensure_coverage_importable() | |
| 42 | 73 |
| 43 from common import find_depot_tools # pylint: disable=W0611 | 74 from common import find_depot_tools # pylint: disable=W0611 |
| OLD | NEW |