Пример #1
0
def tableify(result, max_width):
    renderer = CellRenderer()
    columns = zip(result.keys(), [renderer] * len(result.keys()))
    table = Table(columns, max_width=max_width)
    for row in islice(result, 10):
        table.add_row(row)
    return u("\n").join(table.render())
Пример #2
0
 def test_only_header_with_columns(self):
     expected = textwrap.dedent("""\
         ╒══════╤══════╕
         │ spam │ eggs │
         ╞══════╪══════╡
         └──────┴──────┘""")
     renderer = DefaultCellRenderer("left")
     table = Table([("spam", renderer), ("eggs", renderer)], 15)
     lines = list(table.render())
     for line in lines:
         self.assertEqual(len(line), 15)
     self.assertEqual("\n".join(lines), expected)
Пример #3
0
 def test_only_header_with_columns(self):
     expected = textwrap.dedent(u("""\
         \u2552\u2550\u2550\u2550\u2550\u2550\u2550\u2564\u2550\u2550\u2550\u2550\u2550\u2550\u2555
         \u2502 spam \u2502 eggs \u2502
         \u255e\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2561
         \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2518"""))
     renderer = DefaultCellRenderer("left")
     table = Table([("spam", renderer), ("eggs", renderer)], 15)
     lines = list(table.render())
     for line in lines:
         self.assertEqual(len(line), 15)
     self.assertEqual(u("\n").join(lines), expected)
Пример #4
0
 def test_full_table(self):
     expected = textwrap.dedent("""\
         ╒══════════════════╤═══════════╕
         │     Column A     │  Column B │
         ╞══════════════════╪═══════════╡
         │ Value 1 A        │ Value 1 B │
         ├──────────────────┼───────────┤
         │ Value 2 A longer │       2 B │
         └──────────────────┴───────────┘""")
     left_renderer = DefaultCellRenderer("left")
     right_renderer = DefaultCellRenderer("right")
     table = Table([
         ("Column A", left_renderer),
         ("Column B", right_renderer)
     ])
     table.add_row(["Value 1 A", "Value 1 B"])
     table.add_row(["Value 2 A longer", "2 B"])
     rendered_table = "\n".join(table.render())
     self.assertEqual(rendered_table, expected)
Пример #5
0
 def test_full_table(self):
     expected = textwrap.dedent(u("""\
         \u2552\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2564\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2555
         \u2502     Column A     \u2502  Column B \u2502
         \u255e\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2561
         \u2502 Value 1 A        \u2502 Value 1 B \u2502
         \u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524
         \u2502 Value 2 A longer \u2502       2 B \u2502
         \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"""))
     left_renderer = DefaultCellRenderer("left")
     right_renderer = DefaultCellRenderer("right")
     table = Table([
         ("Column A", left_renderer),
         ("Column B", right_renderer)
     ])
     table.add_row(["Value 1 A", "Value 1 B"])
     table.add_row(["Value 2 A longer", "2 B"])
     rendered_table = u("\n").join(table.render())
     self.assertEqual(rendered_table, expected)
Пример #6
0
 def test_wrapping(self):
     renderer = DefaultCellRenderer("left")
     table = Table([("spam", renderer), ("eggs", renderer)], 25)
     table.add_row(["spam " * 10, "eggs " * 5])
     for line in table.render():
         self.assertEqual(len(line), 25)