Пример #1
0
    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
0
 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
0
 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
0
 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)
Пример #5
0
    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""")
Пример #6
0
    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")
Пример #7
0
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
0
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
Пример #9
0
    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')
Пример #10
0
    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())
Пример #11
0
 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")
Пример #12
0
    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""")
Пример #13
0
    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")
Пример #14
0
    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')
Пример #15
0
 def test_explicit_column_alignment(self):
     """force an explicit column width"""
     tbl = TextTable("%>10one %two")
     tbl.append({'one': 'foo', 'two': 'bar'})
     self.assertEqual(str(tbl),
                      "       ONE TWO\n       --- ---\n       foo bar")
Пример #16
0
 def test_optional_column_non_empty(self):
     """an non-empty optional column shoud be displayed"""
     tbl = TextTable("%foo %bar")
     tbl.optional_cols = [ 'bar' ]
     tbl.append({'foo': 'zap', 'bar': 'zop' })
     self.assertEqual(str(tbl), """FOO BAR\n--- ---\nzap zop""")
Пример #17
0
 def test_column_alignement_explicit(self):
     """force an explicit column width"""
     tbl = TextTable("%>10one %two")
     tbl.append({'one': 'foo', 'two': 'bar'})
     self.assertEqual(str(tbl), 
                      "       ONE TWO\n       --- ---\n       foo bar")
Пример #18
0
 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")
Пример #19
0
 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")
Пример #20
0
 def test_special_character(self):
     """espace character for %"""
     tbl = TextTable("%one %%")
     tbl.append({'one': '34'})
     self.assertEqual(str(tbl), 'ONE %\n--- -\n34  %')
Пример #21
0
 def test_header_column_alignment(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")
Пример #22
0
 def test_aliases(self):
     """format with label aliases"""
     tbl = TextTable("%o %t")
     tbl.aliases = {'o': 'one', 't':'two'}
     tbl.append({'one': 'foo1', 'two': 'bar1'})
     self.assertEqual(str(tbl),"ONE  TWO\n---  ---\nfoo1 bar1")
Пример #23
0
 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")
Пример #24
0
 def test_optional_column_non_empty(self):
     """an non-empty optional column shoud be displayed"""
     tbl = TextTable("%foo %bar")
     tbl.optional_cols = [ 'bar' ]
     tbl.append({'foo': 'zap', 'bar': 'zop' })
     self.assertEqual(str(tbl), """FOO BAR\n--- ---\nzap zop""")
Пример #25
0
 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')
Пример #26
0
 def test_noheader(self):
     """output without header"""
     tbl = TextTable("%one")
     tbl.show_header = False
     tbl.append({'one': 'foo'})
     self.assertEqual(str(tbl), "foo")
Пример #27
0
 def test_aliases(self):
     """format with label aliases"""
     tbl = TextTable("%o %t")
     tbl.aliases = {'o': 'one', 't':'two'}
     tbl.append({'one': 'foo1', 'two': 'bar1'})
     self.assertEqual(str(tbl),"ONE  TWO\n---  ---\nfoo1 bar1")
Пример #28
0
 def test_column_short(self):
     """force a too short column width which will truncate value"""
     tbl = TextTable("%4label %two")
     tbl.append({'label': 'lustre-OST0000', 'two': 'bar'})
     self.assertEqual(str(tbl), "L... TWO\n---- ---\nl... bar")
Пример #29
0
 def test_row_with_none_value(self):
     """row with a None value"""
     tbl = TextTable("%foo")
     tbl.append({'foo': None})
     self.assertEqual(str(tbl), "FOO\n---\n")
Пример #30
0
 def test_length(self):
     """table length"""
     tbl = TextTable()
     tbl.append({'one': 'foo1'})
     tbl.append({'one': 'foo3'})
     self.assertEqual(len(tbl), 2)
Пример #31
0
 def test_unknown_key(self):
     """unknown key should raise KeyError"""
     tbl = TextTable("%one is %nice")
     tbl.append({'one': 'bar'})
     self.assertRaises(KeyError, str, tbl)
Пример #32
0
 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")
Пример #33
0
 def test_optional_column_empty(self):
     """an empty optional column should not be displayed"""
     tbl = TextTable("%foo %bar")
     tbl.optional_cols = [ 'bar' ]
     tbl.append({'foo': 'zap', 'bar': None })
     self.assertEqual(str(tbl), """FOO\n---\nzap""")
Пример #34
0
 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')
Пример #35
0
 def _fmt_str(self, fmt, txt):
     tbl = TextTable(fmt)
     tbl.show_header = False
     table_fill(tbl, self._fs)
     self.assertEqual(str(tbl), txt)
Пример #36
0
 def test_column_short(self):
     """force a too short column width which will truncate value"""
     tbl = TextTable("%4label %two")
     tbl.append({'label': 'lustre-OST0000', 'two': 'bar'})
     self.assertEqual(str(tbl), "L... TWO\n---- ---\nl... bar")
Пример #37
0
 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")
Пример #38
0
 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")
Пример #39
0
 def test_unknown_key(self):
     """unknown key should raise KeyError"""
     tbl = TextTable("%one is %nice")
     tbl.append({'one': 'bar'})
     self.assertRaises(KeyError, str, tbl)
Пример #40
0
 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")
Пример #41
0
 def test_special_character(self):
     """espace character for %"""
     tbl = TextTable("%one %%")
     tbl.append({'one': '34'})
     self.assertEqual(str(tbl), 'ONE %\n--- -\n34  %')
Пример #42
0
 def test_optional_column_empty(self):
     """an empty optional column should not be displayed"""
     tbl = TextTable("%foo %bar")
     tbl.optional_cols = [ 'bar' ]
     tbl.append({'foo': 'zap', 'bar': None })
     self.assertEqual(str(tbl), """FOO\n---\nzap""")
Пример #43
0
 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')
Пример #44
0
 def test_simple(self):
     """simple row"""
     tbl = TextTable("%one")
     tbl.append({'one': 'foo'})
     self.assertEqual(str(tbl), "ONE\n---\nfoo")
Пример #45
0
 def test_simple(self):
     """simple row"""
     tbl = TextTable("%one")
     tbl.append({'one': 'foo'})
     self.assertEqual(str(tbl), "ONE\n---\nfoo")
Пример #46
0
 def test_empty(self):
     """empty table"""
     tbl = TextTable("%foo")
     self.assertEqual(str(tbl), "FOO\n---")
Пример #47
0
 def _fmt_str(self, fmt, txt):
     tbl = TextTable(fmt)
     tbl.show_header = False
     table_fill(tbl, self._fs)
     self.assertEqual(str(tbl), txt)
Пример #48
0
 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")
Пример #49
0
 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")
Пример #50
0
 def test_noheader(self):
     """output without header"""
     tbl = TextTable("%one")
     tbl.show_header = False
     tbl.append({'one': 'foo'})
     self.assertEqual(str(tbl), "foo")
Пример #51
0
 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')
Пример #52
0
 def test_empty_fs(self):
     """fill with an empty filesystem"""
     tbl = TextTable()
     table_fill(tbl, self._fs, None)
     self.assertEqual(len(tbl), 0)
Пример #53
0
 def test_length(self):
     """table length"""
     tbl = TextTable()
     tbl.append({'one': 'foo1'})
     tbl.append({'one': 'foo3'})
     self.assertEqual(len(tbl), 2)
Пример #54
0
 def test_row_with_none_value(self):
     """row with a None value"""
     tbl = TextTable("%foo")
     tbl.append({'foo': None})
     self.assertEqual(str(tbl), "FOO\n---\n")
Пример #55
0
 def test_bad_field(self):
     """fill with bad field name"""
     self._fs.new_target(Server('foo', ['foo@tcp']), 'mgt', 0, '/dev/foo')
     tbl = TextTable('%badname')
     self.assertRaises(DisplayError, table_fill, tbl, self._fs)
Пример #56
0
 def test_ignore_bad_keys(self):
     """bad keys are displayed as-is."""
     tbl = TextTable("%one is %nice")
     tbl.ignore_bad_keys = True
     tbl.append({'one': 'bar'})
     self.assertEqual(str(tbl), "ONE IS %NICE\n--- -- -----\nbar is %nice")
Пример #57
0
 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')