本文整理汇总了Python中Shine.CLI.TextTable.TextTable类的典型用法代码示例。如果您正苦于以下问题:Python TextTable类的具体用法?Python TextTable怎么用?Python TextTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pattern_fields
def test_pattern_fields(self):
"""fields could be extracted from pattern"""
tbl = TextTable("%foo %bar")
self.assertEqual(['foo', 'bar'], tbl.pattern_fields())
tbl = TextTable("%foo likes %>20bar and %other")
self.assertEqual(['foo', 'bar', 'other'], tbl.pattern_fields())
示例2: test_several_lines
def test_several_lines(self):
"""list of rows"""
tbl = TextTable("%one")
tbl.append({'one': 'foo1'})
tbl.append({'one': 'foo2'})
tbl.append({'one': 'foo3'})
self.assertEqual(str(tbl), "ONE\n---\nfoo1\nfoo2\nfoo3")
示例3: test_long_title_truncated
def test_long_title_truncated(self):
"""very wide data does not imply wery wide title"""
tbl = TextTable("%one %two")
tbl.title = "title"
tbl.append({'one': 'foobar', 'two': ' go' * 100})
self.assertEqual(str(tbl),
"== title =\n"
"ONE TWO\n"
"--- ---\n"
"foobar " + ' go' * 100)
示例4: test_column_width_values
def test_column_width_values(self):
"""column width with longer values"""
tbl = TextTable("%one %two")
tbl.append({'one': 'foo1', 'two': 'bar1'})
tbl.append({'one': 'foofoo2', 'two': 'barbar2'})
self.assertEqual(str(tbl),
"""ONE TWO
--- ---
foo1 bar1
foofoo2 barbar2""")
示例5: test_title_with_color
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")
示例6: test_sorting
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')
示例7: setup_table
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
示例8: test_two_fields
def test_two_fields(self):
"""format with 2 fields"""
tbl = TextTable("%one %two")
tbl.append({'one': 'foo1', 'two':'bar1'})
self.assertEqual(str(tbl),"ONE TWO\n--- ---\nfoo1 bar1")
示例9: test_length
def test_length(self):
"""table length"""
tbl = TextTable()
tbl.append({'one': 'foo1'})
tbl.append({'one': 'foo3'})
self.assertEqual(len(tbl), 2)
示例10: _fmt_str
def _fmt_str(self, fmt, txt):
tbl = TextTable(fmt)
tbl.show_header = False
table_fill(tbl, self._fs)
self.assertEqual(str(tbl), txt)
示例11: test_simple
def test_simple(self):
"""simple row"""
tbl = TextTable("%one")
tbl.append({'one': 'foo'})
self.assertEqual(str(tbl), "ONE\n---\nfoo")
示例12: test_support
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')
示例13: test_header_label
def test_header_label(self):
"""output with header label"""
tbl = TextTable("%fsname")
tbl.header_labels = {'fsname': 'filesystem'}
tbl.append({'fsname': 'foo'})
self.assertEqual(str(tbl), "FILESYSTEM\n----------\nfoo")
示例14: test_column_alignement_header
def test_column_alignement_header(self):
"""column alignment with longer header"""
tbl = TextTable("%filesystem %two")
tbl.append({'filesystem': 'foo', 'two': 'bar'})
self.assertEqual(str(tbl),
"FILESYSTEM TWO\n---------- ---\nfoo bar")
示例15: test_title
def test_title(self):
"""display with a simple title"""
tbl = TextTable("%one")
tbl.title = "test title"
tbl.append({'one': 'foo'})
self.assertEqual(str(tbl), "= test title =\nONE\n---\nfoo")