diff options
-rw-r--r-- | coverage/parser.py | 36 | ||||
-rw-r--r-- | coverage/results.py | 4 | ||||
-rw-r--r-- | tests/backunittest.py | 25 | ||||
-rw-r--r-- | tests/coveragetest.py | 19 |
4 files changed, 46 insertions, 38 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index cfaf02fa..88aad65f 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -14,24 +14,12 @@ class CodeParser(object): """ Base class for any code parser. """ - def _adjust_filename(self, fname): - return fname - - def first_lines(self, lines): - """Map the line numbers in `lines` to the correct first line of the - statement. - - Returns a set of the first lines. - - """ - return set(self.first_line(l) for l in lines) - - def first_line(self, line): - return line - def translate_lines(self, lines): return lines + def translate_arcs(self, arcs): + return arcs + def exit_counts(self): return {} @@ -197,6 +185,24 @@ class PythonParser(CodeParser): else: return line + def first_lines(self, lines): + """Map the line numbers in `lines` to the correct first line of the + statement. + + Returns a set of the first lines. + + """ + return set(self.first_line(l) for l in lines) + + def translate_lines(self, lines): + return self.first_lines(lines) + + def translate_arcs(self, arcs): + return [ + (self.first_line(a), self.first_line(b)) + for (a, b) in arcs + ] + def parse_source(self): """Parse source text to find executable lines, excluded lines, etc. diff --git a/coverage/results.py b/coverage/results.py index 08329766..e422730d 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -26,7 +26,6 @@ class Analysis(object): # Identify missing statements. executed = self.coverage.data.executed_lines(self.filename) executed = self.parser.translate_lines(executed) - executed = self.parser.first_lines(executed) self.missing = self.statements - executed if self.coverage.data.has_arcs(): @@ -74,8 +73,7 @@ class Analysis(object): def arcs_executed(self): """Returns a sorted list of the arcs actually executed in the code.""" executed = self.coverage.data.executed_arcs(self.filename) - m2fl = self.parser.first_line - executed = ((m2fl(l1), m2fl(l2)) for (l1,l2) in executed) + executed = self.parser.translate_arcs(executed) return sorted(executed) def arcs_missing(self): diff --git a/tests/backunittest.py b/tests/backunittest.py index a4377b0b..6498397f 100644 --- a/tests/backunittest.py +++ b/tests/backunittest.py @@ -8,9 +8,9 @@ except ImportError: import unittest -def _need(method): - """Do we need to define our own `method` method?""" - return not hasattr(unittest.TestCase, method) +def unittest_has(method): + """Does `unitttest.TestCase` have `method` defined?""" + return hasattr(unittest.TestCase, method) class TestCase(unittest.TestCase): @@ -20,21 +20,22 @@ class TestCase(unittest.TestCase): `unittest` doesn't have them. """ - if _need('assertCountEqual'): - try: - assertCountEqual = assertSameElements - except NameError: + # pylint: disable=missing-docstring + + if not unittest_has('assertCountEqual'): + if unittest_has('assertSameElements'): + def assertCountEqual(self, *args, **kwargs): + # pylint: disable=no-member + return self.assertSameElements(*args, **kwargs) + else: def assertCountEqual(self, s1, s2): """Assert these have the same elements, regardless of order.""" self.assertEqual(set(s1), set(s2)) - else: - def assertCountEqual(self, *args, **kwargs): - return self.assertSameElements(*args, **kwargs) - if _need('assertRaisesRegex'): + if not unittest_has('assertRaisesRegex'): def assertRaisesRegex(self, *args, **kwargs): return self.assertRaisesRegexp(*args, **kwargs) - if _need('assertRegex'): + if not unittest_has('assertRegex'): def assertRegex(self, *args, **kwargs): return self.assertRegexpMatches(*args, **kwargs) diff --git a/tests/coveragetest.py b/tests/coveragetest.py index e6376a7b..aa851954 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -1,10 +1,11 @@ """Base test case class for coverage testing.""" -import glob, imp, os, random, shlex, shutil, sys, tempfile, textwrap +import glob, os, random, shlex, shutil, sys, tempfile, textwrap import atexit, collections import coverage -from coverage.backward import StringIO, to_bytes, imp, importlib, import_local_file +from coverage.backward import StringIO, to_bytes, import_local_file +from coverage.backward import importlib # pylint: disable=unused-import from coverage.control import _TEST_NAME_FILE from tests.backtest import run_command from tests.backunittest import TestCase @@ -354,19 +355,21 @@ class CoverageTest(TestCase): if statements == line_list: break else: - self.fail("None of the lines choices matched %r" % - statements + self.fail( + "None of the lines choices matched %r" % statements ) + missing_formatted = analysis.missing_formatted() if type(missing) == type(""): - self.assertEqual(analysis.missing_formatted(), missing) + self.assertEqual(missing_formatted, missing) else: for missing_list in missing: - if analysis.missing_formatted() == missing_list: + if missing_formatted == missing_list: break else: - self.fail("None of the missing choices matched %r" % - analysis.missing_formatted() + self.fail( + "None of the missing choices matched %r" % + missing_formatted ) if arcs is not None: |