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 if sys.platform.startswith('win'): |
| 38 print textwrap.dedent(""" |
| 39 Please install coverage by running the appropriate installer from: |
| 40 https://pypi.python.org/pypi/coverage/3.7.1 |
| 41 """) |
| 42 sys.exit(1) |
32 | 43 |
33 def print_coverage_warning(): | 44 try: |
34 if not hasattr(coverage.collector, 'CTracer'): | 45 import setuptools # pylint: disable=W0612 |
35 print "WARNING: Using the pure-python coverage module." | 46 except ImportError: |
36 print " Install the native python coverage module to speed recipe" | 47 print textwrap.dedent(""" |
37 print " training up by an order of magnitude." | 48 No compatible system-wide python-coverage package installed, and |
38 print | 49 setuptools is not installed either. Please obtain setuptools by: |
39 print " pip install coverage" | 50 |
40 print " OR" | 51 Debian/Ubuntu: |
41 print " easy_install coverage" | 52 sudo apt-get install python-setuptools python-dev |
| 53 |
| 54 OS X: |
| 55 https://pypi.python.org/pypi/setuptools#unix-including-mac-os-x-curl |
| 56 |
| 57 Other: |
| 58 https://pypi.python.org/pypi/setuptools#installation-instructions |
| 59 """) |
| 60 sys.exit(1) |
| 61 |
| 62 from pkg_resources import get_build_platform |
| 63 try: |
| 64 # Python 2.7 or >= 3.2 |
| 65 from sysconfig import get_python_version |
| 66 except ImportError: |
| 67 from distutils.sysconfig import get_python_version |
| 68 |
| 69 cov_dir = os.path.join(BASE_DIR, 'third_party', 'coverage-3.7.1') |
| 70 cov_egg = os.path.join(cov_dir, 'dist', 'coverage-3.7.1-py%s-%s.egg' % ( |
| 71 get_python_version(), get_build_platform())) |
| 72 |
| 73 # The C-compiled coverage engine is WAY faster (and less buggy) than the pure |
| 74 # python version, so we build the dist_egg if necessary. |
| 75 if not os.path.exists(cov_egg): |
| 76 import subprocess |
| 77 print 'Building Coverage 3.7.1' |
| 78 p = subprocess.Popen([sys.executable, 'setup.py', 'bdist_egg'], cwd=cov_dir, |
| 79 stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 80 stdout, stderr = p.communicate() |
| 81 if p.returncode != 0: |
| 82 print 'Error while building :(' |
| 83 print stdout |
| 84 print stderr |
| 85 if sys.platform.startswith('linux'): |
| 86 print textwrap.dedent(""" |
| 87 You probably don't have the 'python-dev' package installed. Install |
| 88 it by running: |
| 89 sudo apt-get install python-dev |
| 90 """) |
| 91 else: |
| 92 print textwrap.dedent(""" |
| 93 I'm not sure what's wrong, but your system seems incapable of building |
| 94 python extensions. Please fix that by installing a Python with headers |
| 95 and the approprite command-line build tools for your platform. |
| 96 """) |
| 97 sys.exit(1) |
| 98 |
| 99 sys.path.insert(0, cov_egg) |
| 100 |
| 101 ensure_coverage_importable() |
42 | 102 |
43 from common import find_depot_tools # pylint: disable=W0611 | 103 from common import find_depot_tools # pylint: disable=W0611 |
OLD | NEW |