summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-12-24 11:11:37 -0500
committerNed Batchelder <ned@nedbatchelder.com>2015-12-24 11:11:37 -0500
commit26a49dc5ccb6465a3cdd7a2346c530ce4f88b0dd (patch)
tree4a3e56f20c0ec65c7baa6fdcfb0883a8fdf5653d
parent3ff583872ebb4069e8e6e2fa5b7b947acab42a1e (diff)
downloadpython-coveragepy-git-26a49dc5ccb6465a3cdd7a2346c530ce4f88b0dd.tar.gz
Non-ascii characters work again in config regexes. Fixes #455.
-rw-r--r--CHANGES.rst3
-rw-r--r--coverage/parser.py6
-rw-r--r--tests/test_config.py7
-rw-r--r--tests/test_coverage.py14
4 files changed, 28 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 923e100d..72d39ad0 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -19,9 +19,12 @@ Unreleased
- Files with two encoding declarations are properly supported, fixing
`issue 453`_. Thanks, Max Linke.
+- 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`_.
.. _issue 131: https://bitbucket.org/ned/coveragepy/issues/131/pragma-on-a-decorator-line-should-affect
.. _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
Version 4.0.3 --- 2015-11-24
diff --git a/coverage/parser.py b/coverage/parser.py
index 7b8a60f1..884d40cb 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -9,6 +9,7 @@ import re
import token
import tokenize
+from coverage import env
from coverage.backward import range # pylint: disable=redefined-builtin
from coverage.backward import bytes_to_ints
from coverage.bytecode import ByteCodes, CodeObjects
@@ -95,7 +96,10 @@ class PythonParser(object):
part of it.
"""
- regex_c = re.compile(join_regex(regexes))
+ combined = join_regex(regexes)
+ if env.PY2:
+ combined = combined.decode("utf8")
+ regex_c = re.compile(combined)
matches = set()
for i, ltext in enumerate(self.lines, start=1):
if regex_c.search(ltext):
diff --git a/tests/test_config.py b/tests/test_config.py
index 93a7bbf6..5667e930 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -379,11 +379,18 @@ class ConfigFileTest(CoverageTest):
def test_non_ascii(self):
self.make_file(".coveragerc", """\
+ [report]
+ exclude_lines =
+ first
+ ✘${TOX_ENVNAME}
+ third
[html]
title = tabblo & «ταБЬℓσ» # numbers
""")
+ self.set_environ("TOX_ENVNAME", "weirdo")
cov = coverage.Coverage()
+ self.assertEqual(cov.config.exclude_list, ["first", "✘weirdo", "third"])
self.assertEqual(cov.config.html_title, "tabblo & «ταБЬℓσ» # numbers")
def test_unreadable_config(self):
diff --git a/tests/test_coverage.py b/tests/test_coverage.py
index 9e2a444c..02da2032 100644
--- a/tests/test_coverage.py
+++ b/tests/test_coverage.py
@@ -1,3 +1,4 @@
+# coding: utf-8
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
@@ -1128,7 +1129,7 @@ class ExcludeTest(CoverageTest):
self.check_coverage("""\
a = 1; b = 2
- if 0:
+ if len([]):
a = 4 # -cc
""",
[1,3], "", excludes=['-cc'])
@@ -1478,6 +1479,17 @@ class ExcludeTest(CoverageTest):
""",
[8,9], "", excludes=['#pragma: NO COVER'])
+ def test_excludes_non_ascii(self):
+ self.check_coverage("""\
+ # coding: utf-8
+ a = 1; b = 2
+
+ if len([]):
+ a = 5 # ✘cover
+ """,
+ [2, 4], "", excludes=['✘cover']
+ )
+
class Py24Test(CoverageTest):
"""Tests of new syntax in Python 2.4."""