summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/control.py36
-rw-r--r--coverage/misc.py32
2 files changed, 34 insertions, 34 deletions
diff --git a/coverage/control.py b/coverage/control.py
index 8a38fffe..63c0980b 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -3,7 +3,7 @@
import os, re, sys
from coverage.data import CoverageData
-from coverage.misc import nice_pair, CoverageException
+from coverage.misc import format_lines, CoverageException
from coverage.codeunit import code_unit_factory
from coverage.files import FileLocator
@@ -137,38 +137,6 @@ class coverage:
self.analysis_cache[code_unit.filename] = result
return result
- def format_lines(self, statements, lines):
- """Nicely format a list of line numbers.
-
- Format a list of line numbers for printing by coalescing groups of
- lines as long as the lines represent consecutive statements. This will
- coalesce even if there are gaps between statements.
-
- For example, if `statements` is [1,2,3,4,5,10,11,12,13,14] and
- `lines` is [1,2,5,10,11,13,14] then the result will be "1-2, 5-11, 13-14".
-
- """
-
- pairs = []
- i = 0
- j = 0
- start = None
- pairs = []
- while i < len(statements) and j < len(lines):
- if statements[i] == lines[j]:
- if start == None:
- start = lines[j]
- end = lines[j]
- j = j + 1
- elif start:
- pairs.append((start, end))
- start = None
- i = i + 1
- if start:
- pairs.append((start, end))
- ret = ', '.join(map(nice_pair, pairs))
- return ret
-
# Backward compatibility with version 1.
def analysis(self, morf):
f, s, _, m, mf = self.analysis2(morf)
@@ -198,7 +166,7 @@ class coverage:
missing.append(line)
return (filename, statements, excluded, missing,
- self.format_lines(statements, missing))
+ format_lines(statements, missing))
# Programmatic entry point
def report(self, morfs, show_missing=True, ignore_errors=False, file=None):
diff --git a/coverage/misc.py b/coverage/misc.py
index 15ddad08..a6d9f20b 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -14,5 +14,37 @@ def nice_pair(pair):
return "%d-%d" % (start, end)
+def format_lines(statements, lines):
+ """Nicely format a list of line numbers.
+
+ Format a list of line numbers for printing by coalescing groups of lines as
+ long as the lines represent consecutive statements. This will coalesce
+ even if there are gaps between statements.
+
+ For example, if `statements` is [1,2,3,4,5,10,11,12,13,14] and
+ `lines` is [1,2,5,10,11,13,14] then the result will be "1-2, 5-11, 13-14".
+
+ """
+ pairs = []
+ i = 0
+ j = 0
+ start = None
+ pairs = []
+ while i < len(statements) and j < len(lines):
+ if statements[i] == lines[j]:
+ if start == None:
+ start = lines[j]
+ end = lines[j]
+ j = j + 1
+ elif start:
+ pairs.append((start, end))
+ start = None
+ i = i + 1
+ if start:
+ pairs.append((start, end))
+ ret = ', '.join(map(nice_pair, pairs))
+ return ret
+
+
class CoverageException(Exception):
pass