def test_sorting(self): """fill with 2 different sortings""" tbl = TextTable(fmt="%4fsname %node") tbl.show_header = False key = lambda t: t.TYPE table_fill(tbl, self._fs, key) self.assertEqual(str(tbl), 'c... foo2\nc... foo1\nc... foo3\nc... foo0') tbl = TextTable(fmt="%4fsname %node") tbl.show_header = False key = lambda t: t.DISPLAY_ORDER table_fill(tbl, self._fs, key) self.assertEqual(str(tbl), 'c... foo0\nc... foo1\nc... foo2\nc... foo3')
def setup_table(options, fmt=None): """ Return a TextTable already setup based on display command line options like color and header. """ tbl = TextTable(fmt) tbl.color = (options.color == 'auto' and Globals()['color'] == 'auto' \ and sys.stdout.isatty()) or \ (options.color == 'auto' and Globals()['color'] == 'always') \ or (options.color == 'always') tbl.show_header = options.header return tbl
def test_noheader(self): """output without header""" tbl = TextTable("%one") tbl.show_header = False tbl.append({'one': 'foo'}) self.assertEqual(str(tbl), "foo")
def test_support(self): """fill with a support filter""" tbl = TextTable(fmt="%3type %node %count") tbl.show_header = False table_fill(tbl, self._fs, None, supports='dev') self.assertEqual(str(tbl), 'MGT foo1 1\nMDT foo2 1\nOST foo3 2')
def test_format_group(self): """fill with group field in format""" tbl = TextTable(fmt="%3type %count") tbl.show_header = False table_fill(tbl, self._fs) self.assertEqual(str(tbl), 'MDT 1\nMGT 1\nOST 2\nROU 1')
def _fmt_str(self, fmt, txt): tbl = TextTable(fmt) tbl.show_header = False table_fill(tbl, self._fs) self.assertEqual(str(tbl), txt)
def test_padding_noheader(self): """ignore header labels for padding when disabled""" tbl = TextTable("%longer %foo") tbl.show_header = False tbl.append({'longer': 'short', 'foo': 'data'}) self.assertEqual(str(tbl), 'short data')