예제 #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
파일: DisplayTest.py 프로젝트: thiell/shine
 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
파일: DisplayTest.py 프로젝트: thiell/shine
 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
파일: DisplayTest.py 프로젝트: thiell/shine
 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
파일: DisplayTest.py 프로젝트: thiell/shine
 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
파일: DisplayTest.py 프로젝트: thiell/shine
 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')