From e534f087c2337dbe17364130e40761fa4e16569a Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Wed, 22 Jul 2015 20:47:24 -0400 Subject: Move the raw data dumper to a more internal place. --- coverage/debug.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'coverage/debug.py') diff --git a/coverage/debug.py b/coverage/debug.py index b4c65d2..e5bb6b0 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 -- cgit v1.2.1