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 | 13 |
14 RUNTESTS_DIR = os.path.dirname(os.path.abspath(__file__)) | 14 RUNTESTS_DIR = os.path.dirname(os.path.abspath(__file__)) |
15 DATA_PATH = os.path.join(RUNTESTS_DIR, 'data') | 15 DATA_PATH = os.path.join(RUNTESTS_DIR, 'data') |
16 BASE_DIR = os.path.abspath(os.path.join(RUNTESTS_DIR, '..', '..', '..')) | 16 BASE_DIR = os.path.abspath(os.path.join(RUNTESTS_DIR, '..', '..', '..')) |
17 | 17 |
18 sys.path.insert(0, os.path.join(BASE_DIR, 'scripts')) | 18 sys.path.insert(0, os.path.join(BASE_DIR, 'scripts')) |
19 sys.path.insert(0, os.path.join(BASE_DIR, 'site_config')) | 19 sys.path.insert(0, os.path.join(BASE_DIR, 'site_config')) |
20 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party')) | 20 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')) | 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', 'twisted_10_2')) | 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', 'mock-1.0.1')) | 23 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'mock-1.0.1')) |
24 | 24 |
25 try: | 25 def ensure_coverage_importable(): |
26 # The C-compiled coverage engine is WAY faster than the pure python version. | 26 try: |
27 # If we have it, then don't bother with the pure python one. | 27 from distutils.version import StrictVersion |
28 import coverage | 28 import coverage |
29 except ImportError: | 29 if (StrictVersion(coverage.__version__) < StrictVersion('3.7') or |
30 sys.path.insert(0, os.path.join(BASE_DIR, 'third_party', 'coverage-3.6')) | 30 not coverage.collector.CTracer): |
31 import coverage | 31 del sys.modules['coverage'] |
32 del coverage | |
33 else: | |
34 return | |
35 except ImportError: | |
36 pass | |
32 | 37 |
33 def print_coverage_warning(): | 38 from pkg_resources import get_build_platform |
34 if not hasattr(coverage.collector, 'CTracer'): | 39 try: |
35 print "WARNING: Using the pure-python coverage module." | 40 # Python 2.7 or >= 3.2 |
36 print " Install the native python coverage module to speed recipe" | 41 from sysconfig import get_python_version |
37 print " training up by an order of magnitude." | 42 except ImportError: |
38 print | 43 from distutils.sysconfig import get_python_version |
39 print " pip install coverage" | 44 |
40 print " OR" | 45 cov_dir = os.path.join(BASE_DIR, 'third_party', 'coverage-3.7.1') |
41 print " easy_install coverage" | 46 cov_egg = os.path.join(cov_dir, 'dist', 'coverage-3.7.1-py%s-%s.egg' % ( |
Vadim Sh.
2014/04/04 19:21:59
That's what bdist_egg produces? It there a way to
iannucci
2014/04/04 19:34:35
This is taken from setuptools' code. I can force g
| |
47 get_python_version(), get_build_platform())) | |
48 | |
49 # The C-compiled coverage engine is WAY faster (and less buggy) than the pure | |
50 # python version, so we build the dist_egg if necessary. | |
51 if not os.path.exists(cov_egg): | |
52 import subprocess | |
53 print 'Building Coverage 3.7.1' | |
54 p = subprocess.Popen([sys.executable, 'setup.py', 'bdist_egg'], cwd=cov_dir, | |
Vadim Sh.
2014/04/04 19:21:59
It may be worth to add some instructions how to bu
Vadim Sh.
2014/04/04 19:32:21
Oh, it's already possible to import it from system
iannucci
2014/04/04 19:34:35
Yeah I wasn't sure how to support windows, but if
Vadim Sh.
2014/04/04 19:47:08
Also, bdist_egg needs python-dev and setuptools, r
| |
55 stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
56 stdout, stderr = p.communicate() | |
57 if p.returncode != 0: | |
58 print 'Error while building :(' | |
59 print stdout | |
60 print stderr | |
61 sys.exit(1) | |
62 | |
63 sys.path.insert(0, cov_egg) | |
Vadim Sh.
2014/04/04 19:21:59
Call 'ensure_coverage_importable' again, to ensure
iannucci
2014/04/04 19:34:35
? It's called below... it will either pass (and co
Vadim Sh.
2014/04/04 19:47:08
I mean second time, after egg is build, to assert
| |
64 | |
65 ensure_coverage_importable() | |
42 | 66 |
43 from common import find_depot_tools # pylint: disable=W0611 | 67 from common import find_depot_tools # pylint: disable=W0611 |
OLD | NEW |