diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-01-02 11:19:45 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-01-02 11:19:45 -0500 |
commit | f50c3af027401c326f3d107288705e9743692f11 (patch) | |
tree | d7d38a39ec46e4ebe919b89bd2382f104399d7b9 | |
parent | 8a23aafc03000fd9e500b1898b7c211e605e2176 (diff) | |
download | python-coveragepy-f50c3af027401c326f3d107288705e9743692f11.tar.gz |
Coding declarations are a pain in the ass
-rw-r--r-- | coverage/parser.py | 5 | ||||
-rw-r--r-- | tests/test_coverage.py | 9 |
2 files changed, 12 insertions, 2 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index fc631fc..262a78e 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -17,7 +17,7 @@ from coverage.backward import bytes_to_ints, string_class from coverage.bytecode import ByteCodes, CodeObjects from coverage.misc import contract, nice_pair, join_regex from coverage.misc import CoverageException, NoSource, NotPython -from coverage.phystokens import compile_unicode, generate_tokens +from coverage.phystokens import compile_unicode, generate_tokens, neuter_encoding_declaration class PythonParser(object): @@ -324,8 +324,9 @@ class TryBlock(object): class AstArcAnalyzer(object): + @contract(text='unicode') def __init__(self, text): - self.root_node = ast.parse(text) + self.root_node = ast.parse(neuter_encoding_declaration(text)) if int(os.environ.get("COVERAGE_ASTDUMP", 0)): # Dump the AST so that failing tests have helpful output. ast_dump(self.root_node) diff --git a/tests/test_coverage.py b/tests/test_coverage.py index 3a27fab..78a5dc8 100644 --- a/tests/test_coverage.py +++ b/tests/test_coverage.py @@ -549,6 +549,15 @@ class SimpleStatementTest(CoverageTest): """, ([1,3,6,7], [1,3,5,6,7], [1,3,4,5,6,7]), "") + def test_nonascii(self): + self.check_coverage("""\ + # coding: utf8 + a = 2 + b = 3 + """, + [2, 3] + ) + class CompoundStatementTest(CoverageTest): """Testing coverage of multi-line compound statements.""" |