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 | 4361522532396635a593a3892dedd8955848d250 (patch) | |
tree | 16177fbcb5003f5c4c9ece93bf4787d8df394aaf | |
parent | fa02e8b1d5f985c468d9c15869e092394298a41b (diff) | |
download | python-coveragepy-git-4361522532396635a593a3892dedd8955848d250.tar.gz |
Coding declarations are a pain in the ass
--HG--
branch : ast-branch
-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 fc631fcc..262a78e3 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 3a27fab3..78a5dc86 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.""" |