def test_title_with_color(self): """display with title and color""" tbl = TextTable("%filesystem %two") tbl.title = "title" tbl.color = True tbl.append({'filesystem': 'foo', 'two': 'bar'}) self.assertEqual(str(tbl), "====\033[34m title \033[0m===\n" "\033[34mFILESYSTEM TWO\033[0m\n" "---------- ---\n" "foo bar")
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_color(self): """display with color""" tbl = TextTable("%one") tbl.color = True tbl.append({'one': 'foo'}) self.assertEqual(str(tbl), "\033[34mONE\033[0m\n---\nfoo")