From c613b3a509f061885304d0b82834c6865cbfe4ce Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Sat, 22 Apr 2017 14:15:13 +0800 Subject: Add support for render a justified output from list and dict Change-Id: I4411e62b3d1a067cfa8ae1296cf521877aedb830 Signed-off-by: Yujun Zhang --- qtip/reporter/filters.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'qtip/reporter') diff --git a/qtip/reporter/filters.py b/qtip/reporter/filters.py index c0c379df..52b34bc6 100644 --- a/qtip/reporter/filters.py +++ b/qtip/reporter/filters.py @@ -8,7 +8,16 @@ ############################################################################## -def justify(pair, width=80, padding_with='.'): +def _justify_pair(pair, width=80, padding_with='.'): """align first element along the left margin, second along the right, padding spaces""" n = width - len(pair[0]) return '{key}{value:{c}>{n}}'.format(key=pair[0], value=pair[1], c=padding_with, n=n) + + +def justify(content, width=80, padding_with='.'): + if isinstance(content, list): + return '\n'.join([justify(item, width, padding_with) for item in content]) + elif isinstance(content, dict): + return '\n'.join([justify(item, width, padding_with) for item in content.items()]) + else: + return _justify_pair(content, width, padding_with) -- cgit 1.2.3-korg