diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2019-12-31 07:48:43 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2019-12-31 07:48:43 -0500 |
commit | a9bc9bfd1179a64839d4908fb8f54e7823ee044e (patch) | |
tree | 122d598cd31bc034a011c7ffa6c4928d2d036237 /coverage/misc.py | |
parent | 372f411b8ca76f85c0cc6cc4415d5bee2ca948e2 (diff) | |
download | python-coveragepy-git-a9bc9bfd1179a64839d4908fb8f54e7823ee044e.tar.gz |
Easier to decipher arcz output
Diffstat (limited to 'coverage/misc.py')
-rw-r--r-- | coverage/misc.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/coverage/misc.py b/coverage/misc.py index 6f8c368a..f828a7d4 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -356,6 +356,37 @@ def arcz_to_arcs(arcz): return sorted(arcs) +_arcz_unmap = {val: ch for ch, val in _arcz_map.items()} + +def _arcs_to_arcz_repr_one(num): + """Return an arcz form of the number `num`, or "?" if there is none.""" + if num == -1: + return "." + z = "" + if num < 0: + z += "-" + num *= -1 + z += _arcz_unmap.get(num, "?") + return z + + +def arcs_to_arcz_repr(arcs): + """Convert a list of arcs to a readable multi-line form for asserting. + + Each pair is on its own line, with a comment showing the arcz form, + to make it easier to decode when debugging test failures. + + """ + repr_list = [] + for a, b in arcs: + line = repr((a, b)) + line += " # " + line += _arcs_to_arcz_repr_one(a) + line += _arcs_to_arcz_repr_one(b) + repr_list.append(line) + return "\n".join(repr_list) + "\n" + + class BaseCoverageException(Exception): """The base of all Coverage exceptions.""" pass |