コード例 #1
0
 def testGetColumnWidths(self):
     self.assertEqual([], get_column_widths([[]]))
     self.assertEqual([0], get_column_widths([['']]))
     self.assertEqual([1, 2, 3], get_column_widths([['x', 'yy', 'zzz']]))
     self.assertEqual([3, 3, 3],
                      get_column_widths([['x', 'y', 'zzz'],
                                         ['xxx', 'yy', 'z'],
                                         ['xx', 'yyy', 'zz']]))
コード例 #2
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def testGetColumnWidths(self):
     self.assertEquals([], get_column_widths([[]]))
     self.assertEquals([0], get_column_widths([['']]))
     self.assertEquals([1,2,3], get_column_widths([['x','yy','zzz']]))
     self.assertEquals([3,3,3],
             get_column_widths(
                 [
                     ['x','y','zzz'],
                     ['xxx','yy','z'],
                     ['xx','yyy','zz'],
                 ]))
コード例 #3
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def testPadFields(self):
     table = [['Name', 'Type', 'Description'],
              ['Lollypop', 'Candy', 'Yummy'],
              ['Crisps', 'Snacks', 'Even more yummy, I tell you!']]
     expected_padding = [
              [' Name     ', ' Type   ', ' Description                  '],
              [' Lollypop ', ' Candy  ', ' Yummy                        '],
              [' Crisps   ', ' Snacks ', ' Even more yummy, I tell you! ']]
     widths = get_column_widths(table)
     for input, expect in zip(table, expected_padding):
         self.assertEquals(expect, pad_fields(input, widths))
コード例 #4
0
 def testPadFields(self):
     table = [['Name', 'Type', 'Description'],
              ['Lollypop', 'Candy', 'Yummy'],
              ['Crisps', 'Snacks', 'Even more yummy, I tell you!']]
     expected_padding = [
              [' Name     ', ' Type   ', ' Description                  '],
              [' Lollypop ', ' Candy  ', ' Yummy                        '],
              [' Crisps   ', ' Snacks ', ' Even more yummy, I tell you! ']]
     widths = get_column_widths(table)
     for input, expect in zip(table, expected_padding):
         self.assertEqual(expect, pad_fields(input, widths))
コード例 #5
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
def draw_table(indent, table, manual_widths=None):
    if table == []:
        return []

    if manual_widths is None:
        col_widths = get_column_widths(table)
    else:
        col_widths = manual_widths

    # Reserve room for the spaces
    sep_col_widths = map(lambda x: x + 2, col_widths)
    header_line = table_line(sep_col_widths, header=True)
    normal_line = table_line(sep_col_widths, header=False)

    output = [indent+normal_line]
    first = True
    for row in table:

        if manual_widths:
            row = reflow_row_contents(row, manual_widths)

        row_lines = split_row_into_lines(row)

        # draw the lines (num_lines) for this row
        for row_line in row_lines:
            row_line = pad_fields(row_line, col_widths)
            output.append(indent+"|".join([''] + row_line + ['']))

        # then, draw the separator
        if first:
            output.append(indent+header_line)
            first = False
        else:
            output.append(indent+normal_line)

    return output
コード例 #6
0
def draw_table(indent, table, manual_widths=None):
    if table == []:
        return []

    if manual_widths is None:
        col_widths = get_column_widths(table)
    else:
        col_widths = manual_widths

    # Reserve room for the spaces
    sep_col_widths = map(lambda x: x + 2, col_widths)
    header_line = table_line(sep_col_widths, header=True)
    normal_line = table_line(sep_col_widths, header=False)

    output = [indent + normal_line]
    first = True
    for row in table:

        if manual_widths:
            row = reflow_row_contents(row, manual_widths)

        row_lines = split_row_into_lines(row)

        # draw the lines (num_lines) for this row
        for row_line in row_lines:
            row_line = pad_fields(row_line, col_widths)
            output.append(indent + "|".join([''] + row_line + ['']))

        # then, draw the separator
        if first:
            output.append(indent + header_line)
            first = False
        else:
            output.append(indent + normal_line)

    return output
コード例 #7
0
 def testGetColumnWidthsForMultiLineFields(self):
     self.assertEquals([3, 6],
                       get_column_widths(
                           [['Foo\nBar\nQux', 'This\nis\nreally\nneat!']]))
コード例 #8
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def testGetColumnWidthsForMultiLineFields(self):
     self.assertEquals([3,6],
             get_column_widths([['Foo\nBar\nQux',
                                 'This\nis\nreally\nneat!']]))