8000 Adapt to https://github.com/python/cpython/pull/22027 · nedbat/coveragepy@1c13cb9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c13cb9

Browse files
committed
1 parent c315908 commit 1c13cb9

File tree

7 files changed

+33
-8
lines changed

7 files changed

+33
-8
lines changed

coverage/env.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
PY2 = PYVERSION < (3, 0)
1818
PY3 = PYVERSION >= (3, 0)
1919

20+
NOOPT = getattr(sys.flags, "noopt", False)
21+
2022
# Python implementations.
2123
PYPY = (platform.python_implementation() == 'PyPy')
2224
if PYPY:
@@ -80,7 +82,7 @@ class PYBEHAVIOR(object):
8082
trace_decorated_def = (PYVERSION >= (3, 8))
8183

8284
# Are while-true loops optimized into absolute jumps with no loop setup?
83-
nix_while_true = (PYVERSION >= (3, 8))
85+
nix_while_true = (PYVERSION >= (3, 8)) and not NOOPT
8486

8587
# Python 3.9a1 made sys.argv[0] and other reported files absolute paths.
8688
report_absolute_files = (PYVERSION >= (3, 9))

coverage/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ def _handle__TryFinally(self, node):
11111111
def _handle__While(self, node):
11121112
constant_test = self.is_constant_expr(node.test)
11131113
start = to_top = self.line_for_node(node.test)
1114-
if constant_test and (env.PY3 or constant_test == "Num"):
1114+
if not env.NOOPT and constant_test and (env.PY3 or constant_test == "Num"):
11151115
to_top = self.line_for_node(node.body[0])
11161116
self.block_stack.append(LoopBlock(start=to_top))
11171117
from_start = ArcStart(start, cause="the condition on line {lineno} was never true")
@@ -1126,7 +1126,7 @@ def _handle__While(self, node):
11261126
else_exits = self.add_body_arcs(node.orelse, from_start=from_start)
11271127
exits |= else_exits
11281128
else:
1129-
# No `else` clause: you can exit from the start.
1129+
# No `else` clause: you can exit from the start if the condition isn't constant.
11301130
if not constant_test:
11311131
exits.add(from_start)
11321132
return exits

igor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ def print_banner(label):
327327
if '__pypy__' in sys.builtin_module_names:
328328
version += " (pypy %s)" % ".".join(str(v) for v in sys.pypy_version_info)
329329

330+
if getattr(sys.flags, "noopt", False):
331+
version += " (noopt)"
332+
330333
try:
331334
which_python = os.path.relpath(sys.executable)
332335
except ValueError:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
Programming Language :: Python :: 3.7
3434
Programming Language :: Python :: 3.8
3535
Programming Language :: Python :: 3.9
36+
Programming Language :: Python :: 3.10
3637
Programming Language :: Python :: Implementation :: CPython
3738
Programming Language :: Python :: Implementation :: PyPy
3839
Topic :: Software Development :: Quality Assurance

tests/test_arcs.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ def test_nested_breaks(self):
248248

249249
def test_while_true(self):
250250
# With "while 1", the loop knows it's constant.
251-
if env.PYBEHAVIOR.nix_while_true:
251+
if env.NOOPT:
252+
arcz = ".1 12 23 34 45 36 62 57 7."
253+
elif env.PYBEHAVIOR.nix_while_true:
252254
arcz = ".1 13 34 45 36 63 57 7."
253255
else:
254256
arcz = ".1 12 23 34 45 36 63 57 7."
@@ -265,7 +267,9 @@ def test_while_true(self):
265267
)
266268
# With "while True", 2.x thinks it's computation,
267269
# 3.x thinks it's constant.
268-
if env.PYBEHAVIOR.nix_while_true:
270+
if env.NOOPT:
271+
arcz = ".1 12 23 34 45 36 62 57 7."
272+
elif env.PYBEHAVIOR.nix_while_true:
269273
arcz = ".1 13 34 45 36 63 57 7."
270274
elif env.PY3:
271275
arcz = ".1 12 23 34 45 36 63 57 7."
@@ -305,7 +309,9 @@ def method(self):
305309
def test_bug_496_continue_in_constant_while(self):
306310
# https://github.com/nedbat/coveragepy/issues/496
307311
# A continue in a while-true needs to jump to the right place.
308-
if env.PYBEHAVIOR.nix_while_true:
312+
if env.NOOPT:
313+
arcz = ".1 12 23 34 45 52 46 67 7."
314+
elif env.PYBEHAVIOR.nix_while_true:
309315
arcz = ".1 13 34 45 53 46 67 7."
310316
elif env.PY3:
311317
arcz = ".1 12 23 34 45 53 46 67 7."
@@ -1086,6 +1092,10 @@ class OptimizedIfTest(CoverageTest):
10861092
"""Tests of if statements being optimized away."""
10871093

10881094
def test_optimized_away_if_0(self):
1095+
if env.NOOPT:
1096+
lines = [1, 2, 3, 4, 5, 6, 8, 9]
1097+
else:
1098+
lines = [1, 2, 3, 8, 9]
10891099
self.check_coverage("""\
10901100
a = 1
10911101
if len([2]):
@@ -1097,7 +1107,7 @@ def test_optimized_away_if_0(self):
10971107
e = 8
10981108
f = 9
10991109
""",
1100-
lines=[1, 2, 3, 8, 9],
1110+
lines=lines,
11011111
arcz=".1 12 23 28 38 89 9.",
11021112
arcz_missing="28",
11031113
)

tests/test_plugins.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,11 @@ def coverage_init(reg, options):
867867
reg.add_file_tracer(Plugin())
868868
""")
869869
self.run_bad_plugin(
870-
"bad_plugin", "Plugin", our_error=False, excmsg="an integer is required",
870+
"bad_plugin", "Plugin", our_error=False,
871+
excmsgs=[
872+
"an integer is required",
873+
"'str' object cannot be interpreted as an integer",
874+
],
871875
)
872876

873877

tox.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ setenv =
3232
jython: COVERAGE_NO_CTRACER=no C extension under Jython
3333
jython: PYTEST_ADDOPTS=-n 0
3434

35+
whitelist_externals =
36+
env
37+
3538
commands =
3639
python setup.py --quiet clean develop
3740

@@ -47,6 +50,8 @@ commands =
4750
python setup.py --quiet build_ext --inplace
4851
python igor.py test_with_tracer c {posargs}
4952

53+
env PYTHONNOOPT=1 python igor.py test_with_tracer c {posargs}
54+
5055
[testenv:py39]
5156
basepython = python3.9
5257

0 commit comments

Comments
 (0)
0