From 1f1a35e7ccde1cfe239286a9a6333ebe8882d8f3 Mon Sep 17 00:00:00 2001 From: J08nY Date: Sat, 3 Jun 2017 23:00:48 +0200 Subject: Pretty print dicts in dump_json. - Makes dump_json documentation helper recursively print dicts with indentation. So for example {'name': {'a':1, 'b':2}, 'other': test} becomes: name: a: 1 b: 2 other: test --- src/mailman/testing/documentation.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/mailman/testing/documentation.py') diff --git a/src/mailman/testing/documentation.py b/src/mailman/testing/documentation.py index d460be89f..421a272f4 100644 --- a/src/mailman/testing/documentation.py +++ b/src/mailman/testing/documentation.py @@ -109,6 +109,13 @@ def call_http(url, data=None, method=None, username=None, password=None): return content +def _print_dict(data, depth=0): + for item, value in sorted(data.items()): + if isinstance(value, dict): + _print_dict(value, depth+1) + print(' '*depth + '{}: {}'.format(item, value)) + + def dump_json(url, data=None, method=None, username=None, password=None): """Print the JSON dictionary read from a URL. @@ -140,6 +147,9 @@ def dump_json(url, data=None, method=None, username=None, password=None): printable_value = COMMASPACE.join( "'{}'".format(s) for s in sorted(value)) print('{}: [{}]'.format(key, printable_value)) + elif isinstance(value, dict): + print('{}:'.format(key)) + _print_dict(value, 1) else: print('{}: {}'.format(key, value)) -- cgit v1.2.3-70-g09d2