Exemplo n.º 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())
Exemplo n.º 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")
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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""")
Exemplo n.º 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")
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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')
Exemplo n.º 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())
Exemplo n.º 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")
Exemplo n.º 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""")
Exemplo n.º 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")
Exemplo n.º 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')
Exemplo n.º 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")
Exemplo n.º 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""")
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 20
0
 def test_special_character(self):
     """espace character for %"""
     tbl = TextTable("%one %%")
     tbl.append({'one': '34'})
     self.assertEqual(str(tbl), 'ONE %\n--- -\n34  %')
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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""")
Exemplo n.º 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')
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 30
0
 def test_length(self):
     """table length"""
     tbl = TextTable()
     tbl.append({'one': 'foo1'})
     tbl.append({'one': 'foo3'})
     self.assertEqual(len(tbl), 2)
Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 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""")
Exemplo n.º 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')
Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 41
0
 def test_special_character(self):
     """espace character for %"""
     tbl = TextTable("%one %%")
     tbl.append({'one': '34'})
     self.assertEqual(str(tbl), 'ONE %\n--- -\n34  %')
Exemplo n.º 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""")
Exemplo n.º 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')
Exemplo n.º 44
0
 def test_simple(self):
     """simple row"""
     tbl = TextTable("%one")
     tbl.append({'one': 'foo'})
     self.assertEqual(str(tbl), "ONE\n---\nfoo")
Exemplo n.º 45
0
 def test_simple(self):
     """simple row"""
     tbl = TextTable("%one")
     tbl.append({'one': 'foo'})
     self.assertEqual(str(tbl), "ONE\n---\nfoo")
Exemplo n.º 46
0
 def test_empty(self):
     """empty table"""
     tbl = TextTable("%foo")
     self.assertEqual(str(tbl), "FOO\n---")
Exemplo 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)
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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")
Exemplo n.º 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')
Exemplo n.º 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)
Exemplo n.º 53
0
 def test_length(self):
     """table length"""
     tbl = TextTable()
     tbl.append({'one': 'foo1'})
     tbl.append({'one': 'foo3'})
     self.assertEqual(len(tbl), 2)
Exemplo n.º 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")
Exemplo 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)
Exemplo n.º 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")
Exemplo n.º 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')