tests: allow plugging in pprint/pprintpp via env.

pull/372/head
David Wilson 6 years ago
parent 4134218ef4
commit 3b012e5bce

@ -1,4 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import os
import io import io
from ansible.module_utils import six from ansible.module_utils import six
@ -8,6 +9,11 @@ try:
except ImportError: except ImportError:
from ansible.plugins.loader import callback_loader from ansible.plugins.loader import callback_loader
try:
pprint = __import__(os.environ['NICE_STDOUT_PPRINT'])
except KeyError:
pprint = None
def printi(tio, obj, key=None, indent=0): def printi(tio, obj, key=None, indent=0):
def write(s, *args): def write(s, *args):
@ -50,7 +56,10 @@ class CallbackModule(DefaultModule):
def _dump_results(self, result, *args, **kwargs): def _dump_results(self, result, *args, **kwargs):
try: try:
tio = io.StringIO() tio = io.StringIO()
printi(tio, result) if pprint:
pprint.pprint(result, stream=tio)
else:
printi(tio, result)
return tio.getvalue() #.encode('ascii', 'replace') return tio.getvalue() #.encode('ascii', 'replace')
except: except:
import traceback import traceback

Loading…
Cancel
Save