summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2020-09-12 16:33:13 -0400
committerNed Batchelder <ned@nedbatchelder.com>2020-09-12 16:33:13 -0400
commit1c13cb9cce73bf1e47977be89ef3b086e36ef3c8 (patch)
treee9ee8c4e244cc651575d066d5d3326dbd77539b2
parentc3159081ae67864f75aacc1b86310fe9d8d614cb (diff)
downloadpython-coveragepy-git-nedbat/test-2506.tar.gz
Adapt to https://github.com/python/cpython/pull/22027nedbat/test-2506
-rw-r--r--coverage/env.py4
-rw-r--r--coverage/parser.py4
-rw-r--r--igor.py3
-rw-r--r--setup.py1
-rw-r--r--tests/test_arcs.py18
-rw-r--r--tests/test_plugins.py6
-rw-r--r--tox.ini5
7 files changed, 33 insertions, 8 deletions
diff --git a/coverage/env.py b/coverage/env.py
index b5da3b47..17ace169 100644
--- a/coverage/env.py
+++ b/coverage/env.py
@@ -17,6 +17,8 @@ PYVERSION = sys.version_info + (int(platform.python_version()[-1] == "+"),)
PY2 = PYVERSION < (3, 0)
PY3 = PYVERSION >= (3, 0)
+NOOPT = getattr(sys.flags, "noopt", False)
+
# Python implementations.
PYPY = (platform.python_implementation() == 'PyPy')
if PYPY:
@@ -80,7 +82,7 @@ class PYBEHAVIOR(object):
trace_decorated_def = (PYVERSION >= (3, 8))
# Are while-true loops optimized into absolute jumps with no loop setup?
- nix_while_true = (PYVERSION >= (3, 8))
+ nix_while_true = (PYVERSION >= (3, 8)) and not NOOPT
# Python 3.9a1 made sys.argv[0] and other reported files absolute paths.
report_absolute_files = (PYVERSION >= (3, 9))
diff --git a/coverage/parser.py b/coverage/parser.py
index e3e43149..9b97589b 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -1111,7 +1111,7 @@ class AstArcAnalyzer(object):
def _handle__While(self, node):
constant_test = self.is_constant_expr(node.test)
start = to_top = self.line_for_node(node.test)
- if constant_test and (env.PY3 or constant_test == "Num"):
+ if not env.NOOPT and constant_test and (env.PY3 or constant_test == "Num"):
to_top = self.line_for_node(node.body[0])
self.block_stack.append(LoopBlock(start=to_top))
from_start = ArcStart(start, cause="the condition on line {lineno} was never true")
@@ -1126,7 +1126,7 @@ class AstArcAnalyzer(object):
else_exits = self.add_body_arcs(node.orelse, from_start=from_start)
exits |= else_exits
else:
- # No `else` clause: you can exit from the start.
+ # No `else` clause: you can exit from the start if the condition isn't constant.
if not constant_test:
exits.add(from_start)
return exits
diff --git a/igor.py b/igor.py
index 9a632b57..6502a6fc 100644
--- a/igor.py
+++ b/igor.py
@@ -327,6 +327,9 @@ def print_banner(label):
if '__pypy__' in sys.builtin_module_names:
version += " (pypy %s)" % ".".join(str(v) for v in sys.pypy_version_info)
+ if getattr(sys.flags, "noopt", False):
+ version += " (noopt)"
+
try:
which_python = os.path.relpath(sys.executable)
except ValueError:
diff --git a/setup.py b/setup.py
index 8c837d72..86a054ab 100644
--- a/setup.py
+++ b/setup.py
@@ -33,6 +33,7 @@ Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
+Programming Language :: Python :: 3.10
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
Topic :: Software Development :: Quality Assurance
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index c16f3fa7..daeb7dff 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -248,7 +248,9 @@ class LoopArcTest(CoverageTest):
def test_while_true(self):
# With "while 1", the loop knows it's constant.
- if env.PYBEHAVIOR.nix_while_true:
+ if env.NOOPT:
+ arcz = ".1 12 23 34 45 36 62 57 7."
+ elif env.PYBEHAVIOR.nix_while_true:
arcz = ".1 13 34 45 36 63 57 7."
else:
arcz = ".1 12 23 34 45 36 63 57 7."
@@ -265,7 +267,9 @@ class LoopArcTest(CoverageTest):
)
# With "while True", 2.x thinks it's computation,
# 3.x thinks it's constant.
- if env.PYBEHAVIOR.nix_while_true:
+ if env.NOOPT:
+ arcz = ".1 12 23 34 45 36 62 57 7."
+ elif env.PYBEHAVIOR.nix_while_true:
arcz = ".1 13 34 45 36 63 57 7."
elif env.PY3:
arcz = ".1 12 23 34 45 36 63 57 7."
@@ -305,7 +309,9 @@ class LoopArcTest(CoverageTest):
def test_bug_496_continue_in_constant_while(self):
# https://github.com/nedbat/coveragepy/issues/496
# A continue in a while-true needs to jump to the right place.
- if env.PYBEHAVIOR.nix_while_true:
+ if env.NOOPT:
+ arcz = ".1 12 23 34 45 52 46 67 7."
+ elif env.PYBEHAVIOR.nix_while_true:
arcz = ".1 13 34 45 53 46 67 7."
elif env.PY3:
arcz = ".1 12 23 34 45 53 46 67 7."
@@ -1086,6 +1092,10 @@ class OptimizedIfTest(CoverageTest):
"""Tests of if statements being optimized away."""
def test_optimized_away_if_0(self):
+ if env.NOOPT:
+ lines = [1, 2, 3, 4, 5, 6, 8, 9]
+ else:
+ lines = [1, 2, 3, 8, 9]
self.check_coverage("""\
a = 1
if len([2]):
@@ -1097,7 +1107,7 @@ class OptimizedIfTest(CoverageTest):
e = 8
f = 9
""",
- lines=[1, 2, 3, 8, 9],
+ lines=lines,
arcz=".1 12 23 28 38 89 9.",
arcz_missing="28",
)
diff --git a/tests/test_plugins.py b/tests/test_plugins.py
index 2477f5ce..4c8f18a8 100644
--- a/tests/test_plugins.py
+++ b/tests/test_plugins.py
@@ -867,7 +867,11 @@ class BadFileTracerTest(FileTracerTest):
reg.add_file_tracer(Plugin())
""")
self.run_bad_plugin(
- "bad_plugin", "Plugin", our_error=False, excmsg="an integer is required",
+ "bad_plugin", "Plugin", our_error=False,
+ excmsgs=[
+ "an integer is required",
+ "'str' object cannot be interpreted as an integer",
+ ],
)
diff --git a/tox.ini b/tox.ini
index 88fbbd68..3b1e56dc 100644
--- a/tox.ini
+++ b/tox.ini
@@ -32,6 +32,9 @@ setenv =
jython: COVERAGE_NO_CTRACER=no C extension under Jython
jython: PYTEST_ADDOPTS=-n 0
+whitelist_externals =
+ env
+
commands =
python setup.py --quiet clean develop
@@ -47,6 +50,8 @@ commands =
python setup.py --quiet build_ext --inplace
python igor.py test_with_tracer c {posargs}
+ env PYTHONNOOPT=1 python igor.py test_with_tracer c {posargs}
+
[testenv:py39]
basepython = python3.9