summaryrefslogtreecommitdiff
path: root/tests/test_parser.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-08-09 09:01:41 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-08-09 09:01:41 -0400
commit86d6a54b93c92722c46796cae54b63eed9a6afd6 (patch)
tree5b3ae31d2b442cb5518cc37ab0428fa15a84a424 /tests/test_parser.py
parent5d60702abadc8822672f490c9a96fb3fc7772c1b (diff)
downloadpython-coveragepy-86d6a54b93c92722c46796cae54b63eed9a6afd6.tar.gz
Correct the handling of IndentationError and TokenError
Diffstat (limited to 'tests/test_parser.py')
-rw-r--r--tests/test_parser.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 18621d1..84b9a21 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -8,6 +8,7 @@ import textwrap
from tests.coveragetest import CoverageTest
from coverage import env
+from coverage.misc import NotPython
from coverage.parser import PythonParser
@@ -116,6 +117,25 @@ class PythonParserTest(CoverageTest):
""")
self.assertEqual(parser.exit_counts(), { 1:1, 2:1, 3:1, 6:1 })
+ def test_indentation_error(self):
+ msg = (
+ "Couldn't parse '<code>' as Python source: "
+ "'unindent does not match any outer indentation level' at line 3"
+ )
+ with self.assertRaisesRegex(NotPython, msg):
+ _ = self.parse_source("""\
+ 0 spaces
+ 2
+ 1
+ """)
+
+ def test_token_error(self):
+ msg = "Couldn't parse '<code>' as Python source: 'EOF in multi-line string' at line 1"
+ with self.assertRaisesRegex(NotPython, msg):
+ _ = self.parse_source("""\
+ '''
+ """)
+
class ParserFileTest(CoverageTest):
"""Tests for coverage.py's code parsing from files."""