diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-11-29 08:55:08 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-11-29 08:55:08 -0500 |
commit | 3f544ee33de31e96ca2d25d95da614e9a7a12f50 (patch) | |
tree | 55494ebfa947bcd81e24e91e94e960696fb96d61 /tests/test_parser.py | |
parent | 025cc4ab92236971adc3961e0a177019fed2e6fd (diff) | |
download | python-coveragepy-git-3f544ee33de31e96ca2d25d95da614e9a7a12f50.tar.gz |
Don't be confused by files with missing final newlines. #293
Diffstat (limited to 'tests/test_parser.py')
-rw-r--r-- | tests/test_parser.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/tests/test_parser.py b/tests/test_parser.py index a392ea03..244d4c70 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -99,7 +99,7 @@ class ParserFileTest(CoverageTest): def parse_file(self, filename): """Parse `text` as source, and return the `PythonParser` used.""" parser = PythonParser(filename=filename, exclude="nocover") - parser.parse_source() + self.statements, self.excluded = parser.parse_source() return parser def test_line_endings(self): @@ -128,4 +128,32 @@ class ParserFileTest(CoverageTest): coverage = "\xe7\xf6v\xear\xe3g\xe9" """) parser = self.parse_file("encoded.py") - parser.exit_counts() # TODO: This value should be tested! + self.assertEqual(parser.exit_counts(), {1: 1}) + + def test_missing_line_ending(self): + # Test that the set of statements is the same even if a final + # multi-line statement has no final newline. + # https://bitbucket.org/ned/coveragepy/issue/293 + + self.make_file("normal.py", """\ + out, err = subprocess.Popen( + [sys.executable, '-c', 'pass'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE).communicate() + """) + + self.parse_file("normal.py") + self.assertEqual(self.statements, set([1])) + + self.make_file("abrupt.py", """\ + out, err = subprocess.Popen( + [sys.executable, '-c', 'pass'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE).communicate()""") # no final newline. + + # Double-check that some test helper wasn't being helpful. + with open("abrupt.py") as f: + self.assertEqual(f.read()[-1], ")") + + self.parse_file("abrupt.py") + self.assertEqual(self.statements, set([1])) |