summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.rst5
-rw-r--r--coverage/phystokens.py3
-rw-r--r--coverage/python.py2
-rw-r--r--tests/test_coverage.py16
4 files changed, 24 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index ffdd1a27..5e20ceae 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -48,6 +48,9 @@ Unreleased
- Non-ascii characters in regexes in the configuration file worked in 3.7, but
stopped working in 4.0. Now they work again, closing `issue 455`_.
+- Form-feed characters would prevent accurate determination of the beginning of
+ statements in the rest of the file. This is now fixed, closing `issue 461`_.
+
.. _issue 129: https://bitbucket.org/ned/coveragepy/issues/129/misleading-branch-coverage-of-empty
.. _issue 131: https://bitbucket.org/ned/coveragepy/issues/131/pragma-on-a-decorator-line-should-affect
.. _issue 146: https://bitbucket.org/ned/coveragepy/issues/146/context-managers-confuse-branch-coverage
@@ -56,6 +59,7 @@ Unreleased
.. _issue 434: https://bitbucket.org/ned/coveragepy/issues/434/indexerror-in-python-35
.. _issue 453: https://bitbucket.org/ned/coveragepy/issues/453/source-code-encoding-can-only-be-specified
.. _issue 455: https://bitbucket.org/ned/coveragepy/issues/455/unusual-exclusions-stopped-working-in
+.. _issue 461: https://bitbucket.org/ned/coveragepy/issues/461/multiline-asserts-need-too-many-pragma
Version 4.0.3 --- 2015-11-24
@@ -1550,3 +1554,4 @@ and 2.1.1.
2002-01-07 GDR Update sys.path when running a file with the -x option, so that
it matches the value the program would get if it were run on its own.
+
diff --git a/coverage/phystokens.py b/coverage/phystokens.py
index 5aa3402c..5e80ed54 100644
--- a/coverage/phystokens.py
+++ b/coverage/phystokens.py
@@ -92,8 +92,7 @@ def source_token_lines(source):
line = []
col = 0
- # The \f is because of http://bugs.python.org/issue19035
- source = source.expandtabs(8).replace('\r\n', '\n').replace('\f', ' ')
+ source = source.expandtabs(8).replace('\r\n', '\n')
tokgen = generate_tokens(source)
for ttype, ttext, (_, scol), (_, ecol), _ in phys_tokens(tokgen):
diff --git a/coverage/python.py b/coverage/python.py
index 5e563828..07d23472 100644
--- a/coverage/python.py
+++ b/coverage/python.py
@@ -50,6 +50,8 @@ def get_python_source(filename):
# Couldn't find source.
raise NoSource("No source for code: '%s'." % filename)
+ # Replace \f because of http://bugs.python.org/issue19035
+ source = source.replace(b'\f', b' ')
source = source.decode(source_encoding(source), "replace")
# Python code should always end with a line with a newline.
diff --git a/tests/test_coverage.py b/tests/test_coverage.py
index c0991b04..227360e3 100644
--- a/tests/test_coverage.py
+++ b/tests/test_coverage.py
@@ -1537,6 +1537,22 @@ class ExcludeTest(CoverageTest):
[2, 4], "", excludes=['✘cover']
)
+ def test_formfeed(self):
+ # https://bitbucket.org/ned/coveragepy/issues/461/multiline-asserts-need-too-many-pragma
+ self.check_coverage("""\
+ x = 1
+ assert len([]) == 0, (
+ "This won't happen %s" % ("hello",)
+ )
+ \f
+ x = 6
+ assert len([]) == 0, (
+ "This won't happen %s" % ("hello",)
+ )
+ """,
+ [1, 6], "", excludes=['assert'],
+ )
+
class Py24Test(CoverageTest):
"""Tests of new syntax in Python 2.4."""