diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-22 20:47:24 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-22 20:47:24 -0400 |
commit | 4245d1feacee23580f3d809568f87364f4ea7b03 (patch) | |
tree | 2291d426ffd0cf886274387f191792a31148cfad /coverage/debug.py | |
parent | 5478599f2cc54878fe61418648a9aece0f6142aa (diff) | |
download | python-coveragepy-git-4245d1feacee23580f3d809568f87364f4ea7b03.tar.gz |
Move the raw data dumper to a more internal place.
Diffstat (limited to 'coverage/debug.py')
-rw-r--r-- | coverage/debug.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/coverage/debug.py b/coverage/debug.py index b4c65d26..e5bb6b0b 100644 --- a/coverage/debug.py +++ b/coverage/debug.py @@ -1,7 +1,9 @@ """Control of and utilities for debugging.""" import inspect +import json import os +import re # When debugging, it can be helpful to force some options, especially when @@ -92,3 +94,16 @@ def short_stack(): # pragma: debugging def dump_stack_frames(): # pragma: debugging """Print a summary of the stack to stdout.""" print(short_stack()) + + +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 |