def setUp(self): styler = Styler() self.table = MultiTable(initial_section=False, column_separator='|', styler=styler, auto_reformat=False) self.formatter = TableFormatter(Object(color='off')) self.formatter.table = self.table self.stream = six.StringIO()
def __init__(self, args, table=None): super(TableFormatter, self).__init__(args) if args.color == 'auto': self.table = MultiTable(initial_section=False, column_separator='|') elif args.color == 'off': styler = Styler() self.table = MultiTable(initial_section=False, column_separator='|', styler=styler) elif args.color == 'on': styler = ColorizedStyler() self.table = MultiTable(initial_section=False, column_separator='|', styler=styler) else: raise ValueError("Unknown color option: %s" % args.color)
def tabulate(operation, data): """ Formats a data structure as a table :param operation: the title of the table :param data: list or dict to print """ if data is None: return "" table = MultiTable(initial_section=False, column_separator='|', styler=Styler(), auto_reformat=False) formatter = TableFormatter( type('dummy', (object, ), { "color": "on", "query": None })) formatter.table = table stream = six.StringIO() formatter(operation, data, stream=stream) return stream.getvalue()