diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2018-12-24 17:09:51 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2018-12-24 17:09:51 -0500 |
commit | dcb07762bfc91dec3782096ab6dae995e7c6631a (patch) | |
tree | 55ccaaba21d983370c8f7f8743d20ebdb80c99e5 /coverage | |
parent | 8672eee93fc8e4cf017a133607a371547b5e7812 (diff) | |
download | python-coveragepy-git-dcb07762bfc91dec3782096ab6dae995e7c6631a.tar.gz |
Move code to where it belongs
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/misc.py | 38 | ||||
-rw-r--r-- | coverage/results.py | 40 |
2 files changed, 39 insertions, 39 deletions
diff --git a/coverage/misc.py b/coverage/misc.py index c484d61e..c16b6b4a 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -107,44 +107,6 @@ 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". - - Both `lines` and `statements` can be any iterable. All of the elements of - `lines` must be in `statements`, and all of the values must be positive - integers. - - """ - statements = sorted(statements) - lines = sorted(lines) - - pairs = [] - start = None - lidx = 0 - for stmt in statements: - if lidx >= len(lines): - break - if stmt == lines[lidx]: - lidx += 1 - if not start: - start = stmt - end = stmt - elif start: - pairs.append((start, end)) - start = None - if start: - pairs.append((start, end)) - ret = ', '.join(map(nice_pair, pairs)) - return ret - - def expensive(fn): """A decorator to indicate that a method shouldn't be called more than once. diff --git a/coverage/results.py b/coverage/results.py index ecd50ae9..f7e0ae56 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -7,7 +7,7 @@ import collections from coverage.backward import iitems from coverage.debug import SimpleReprMixin -from coverage.misc import contract, format_lines, CoverageException +from coverage.misc import contract, CoverageException, nice_pair class Analysis(object): @@ -272,6 +272,44 @@ class Numbers(SimpleReprMixin): return NotImplemented +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". + + Both `lines` and `statements` can be any iterable. All of the elements of + `lines` must be in `statements`, and all of the values must be positive + integers. + + """ + statements = sorted(statements) + lines = sorted(lines) + + pairs = [] + start = None + lidx = 0 + for stmt in statements: + if lidx >= len(lines): + break + if stmt == lines[lidx]: + lidx += 1 + if not start: + start = stmt + end = stmt + elif start: + pairs.append((start, end)) + start = None + if start: + pairs.append((start, end)) + ret = ', '.join(map(nice_pair, pairs)) + return ret + + @contract(total='number', fail_under='number', precision=int, returns=bool) def should_fail_under(total, fail_under, precision): """Determine if a total should fail due to fail-under. |