summaryrefslogtreecommitdiffstats
path: root/qtip
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-22 14:15:13 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-24 08:51:48 +0800
commitc613b3a509f061885304d0b82834c6865cbfe4ce (patch)
tree1c80db5108605a277e6469a15438a8cc88d6a8a3 /qtip
parent40c29df6796e6d055f35b730e70dac87ab7db2d4 (diff)
Add support for render a justified output from list and dict
Change-Id: I4411e62b3d1a067cfa8ae1296cf521877aedb830 Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
Diffstat (limited to 'qtip')
-rw-r--r--qtip/reporter/filters.py11
1 files changed, 10 insertions, 1 deletions
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)