|
1 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 |
|
2 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt |
|
3 |
|
4 """Determine facts about the environment.""" |
|
5 |
|
6 import os |
|
7 import platform |
|
8 import sys |
|
9 |
|
10 # Operating systems. |
|
11 WINDOWS = sys.platform == "win32" |
|
12 LINUX = sys.platform == "linux2" |
|
13 |
|
14 # Python implementations. |
|
15 PYPY = (platform.python_implementation() == 'PyPy') |
|
16 if PYPY: |
|
17 PYPYVERSION = sys.pypy_version_info |
|
18 |
|
19 JYTHON = (platform.python_implementation() == 'Jython') |
|
20 IRONPYTHON = (platform.python_implementation() == 'IronPython') |
|
21 |
|
22 # Python versions. |
|
23 PYVERSION = sys.version_info |
|
24 PY2 = PYVERSION < (3, 0) |
|
25 PY3 = PYVERSION >= (3, 0) |
|
26 |
|
27 # Python behavior |
|
28 class PYBEHAVIOR(object): |
|
29 """Flags indicating this Python's behavior.""" |
|
30 |
|
31 # When a break/continue/return statement in a try block jumps to a finally |
|
32 # block, does the finally block do the break/continue/return (pre-3.8), or |
|
33 # does the finally jump back to the break/continue/return (3.8) to do the |
|
34 # work? |
|
35 finally_jumps_back = (PYVERSION >= (3, 8)) |
|
36 |
|
37 # When a function is decorated, does the trace function get called for the |
|
38 # @-line and also the def-line (new behavior in 3.8)? Or just the @-line |
|
39 # (old behavior)? |
|
40 trace_decorated_def = (PYVERSION >= (3, 8)) |
|
41 |
|
42 # Are while-true loops optimized into absolute jumps with no loop setup? |
|
43 nix_while_true = (PYVERSION >= (3, 8)) |
|
44 |
|
45 # Coverage.py specifics. |
|
46 |
|
47 # Are we using the C-implemented trace function? |
|
48 C_TRACER = os.getenv('COVERAGE_TEST_TRACER', 'c') == 'c' |
|
49 |
|
50 # Are we coverage-measuring ourselves? |
|
51 METACOV = os.getenv('COVERAGE_COVERAGE', '') != '' |
|
52 |
|
53 # Are we running our test suite? |
|
54 # Even when running tests, you can use COVERAGE_TESTING=0 to disable the |
|
55 # test-specific behavior like contracts. |
|
56 TESTING = os.getenv('COVERAGE_TESTING', '') == 'True' |