diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-22 13:39:05 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-22 13:39:05 -0400 |
commit | b39a2750f80d9972c92c81eac65d095c63a5510e (patch) | |
tree | 4140dcc8c98182eb4d40228f741a11f8ba29f9a9 /coverage/misc.py | |
parent | a9340b38bf152ff49b38df6026624280419ee93f (diff) | |
download | python-coveragepy-git-b39a2750f80d9972c92c81eac65d095c63a5510e.tar.gz |
A way to see the raw data in the data file.
Diffstat (limited to 'coverage/misc.py')
-rw-r--r-- | coverage/misc.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/coverage/misc.py b/coverage/misc.py index b99fbb81..ca09be7d 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -3,7 +3,9 @@ import errno import hashlib import inspect +import json import os +import re from coverage import env from coverage.backward import string_class, to_bytes, unicode_class @@ -170,6 +172,19 @@ def _needs_to_implement(that, func_name): ) +def pretty_data(data): + """Format data as JSON, but as nicely as possible. + + Returns a string. + + """ + # Start with a basic JSON dump. + out = json.dumps(data, indent=4, sort_keys=True) + # But pairs of numbers shouldn't be split across lines... + out = re.sub(r"\[\s+(-?\d+),\s+(-?\d+)\s+]", r"[\1, \2]", out) + return out + + class CoverageException(Exception): """An exception specific to Coverage.""" pass |