Example #1
0
 def test_str(self):
     # Check that str returns the formatted_as_strings() output.
     table = Table()
     aligns = ["left", "left", "left"]
     table.add_row(["one", "two", "three"], aligns=aligns)
     table.add_row(["1", "2", "3"], aligns=aligns)
     expected = "\n".join(table.formatted_as_strings())
     result = str(table)
     self.assertEqual(result, expected)
Example #2
0
 def test_empty(self):
     table = Table()
     self.assertIsNone(table.n_columns)
     self.assertEqual(len(table.rows), 0)
     self.assertIsNone(table.col_widths)
     # Check other methods : should be ok but do nothing.
     table.set_min_column_widths()  # Ok but does nothing.
     self.assertIsNone(table.col_widths)
     self.assertEqual(table.formatted_as_strings(), [])
     self.assertEqual(str(table), "")
Example #3
0
    def test_formatted_as_strings(self):
        # Test simple self-print is same as
        table = Table()
        aligns = ["left", "right", "left"]
        table.add_row(["1", "266", "32"], aligns)
        table.add_row(["123", "2", "3"], aligns)

        # Check that printing calculates default column widths, and result..
        self.assertEqual(table.col_widths, None)
        result = table.formatted_as_strings()
        self.assertEqual(result, ["1   266 32", "123   2 3"])
        self.assertEqual(table.col_widths, [3, 3, 2])
Example #4
0
 def test_table_set_width(self):
     # Check that changes do *not* affect pre-existing widths.
     table = Table()
     aligns = ["left", "right", "left"]
     table.col_widths = [3, 3, 2]
     table.add_row(["333", "333", "22"], aligns)
     table.add_row(["a", "b", "c"], aligns)
     table.add_row(["12345", "12345", "12345"], aligns)
     result = table.formatted_as_strings()
     self.assertEqual(table.col_widths, [3, 3, 2])
     self.assertEqual(
         result,
         [
             "333 333 22",
             "a     b c",
             "12345 12345 12345",  # These are exceeding the given widths.
         ],
     )
Example #5
0
 def test_unlimited_column(self):
     table = Table()
     aligns = ["left", "right", "left"]
     table.add_row(["a", "beee", "c"], aligns)
     table.add_row(["abcd", "any-longer-stuff", "this"],
                   aligns,
                   i_col_unlimited=1)
     table.add_row(["12", "x", "yy"], aligns)
     result = table.formatted_as_strings()
     self.assertEqual(
         result,
         [
             "a    beee c",
             "abcd any-longer-stuff this",
             # NOTE: the widths-calc is ignoring cols 1-2, but
             # entry#0 *is* extending the width of col#0
             "12      x yy",
         ],
     )