diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-09 09:01:41 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-09 09:01:41 -0400 |
commit | 3cc5b11a413426b07a51e86eab20a7e9ebab4f2d (patch) | |
tree | fbc33f9beb428fe698d28cbdc2419b9c90ed153e /tests/test_parser.py | |
parent | f72ee80a12af6d90172e1af954d0235c77ca7b51 (diff) | |
download | python-coveragepy-git-3cc5b11a413426b07a51e86eab20a7e9ebab4f2d.tar.gz |
Correct the handling of IndentationError and TokenError
Diffstat (limited to 'tests/test_parser.py')
-rw-r--r-- | tests/test_parser.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/test_parser.py b/tests/test_parser.py index 18621d15..84b9a214 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.""" |