Esempio n. 1
0
        def test_pretty_printing_tables_with_wide_asian_characters(self):
            table = [
                ["Artist", "Song"],
                ["分島花音", "砂のお城"],
            ]

            if swadr.PYTHON_3:
                txtio = io.StringIO()
            else:
                txtio = io.BytesIO()
                for j, row in enumerate(table):
                    for k, column in enumerate(row):
                        table[j][k] = unicode(column, encoding="utf-8")

            expected = "\n".join((
                "+----------+----------+",
                "| Artist   | Song     |",
                "+----------+----------+",
                "| 分島花音 | 砂のお城 |",
                "+----------+----------+\n",
            ))

            swadr.pretty_print_table(table, breakafter=[0], dest=txtio)
            txtio.seek(0)
            self.assertEqual(txtio.read(), expected)
Esempio n. 2
0
    def test_pretty_print_table_embedded_newlines_and_tabs(self):
        table = [
            [unicode("A"), unicode("B"), unicode("C")],
            [unicode("1"), unicode("2\n\n\tT"), unicode("3\n  X")],
            [unicode("3"), unicode("9"), unicode("27")],
        ]
        expected = unicode("\n").join((
            "+---+-----------+-----+",
            "| A | B         | C   |",
            "+---+-----------+-----+",
            "| 1 | 2         | 3   |",
            "|   |           |   X |",
            "|   |         T |     |",
            "+---+-----------+-----+",
            "| 3 | 9         | 27  |",
            "+---+-----------+-----+\n",
        ))

        if swadr.PYTHON_3:
            txtio = io.StringIO()
        else:
            txtio = io.BytesIO()

        swadr.pretty_print_table(table, breakafter=True, tabsize=8, dest=txtio)
        txtio.seek(0)
        self.assertEqual(txtio.read(), expected)
Esempio n. 3
0
    def test_pretty_print_table_type_acceptance(self):
        table = [
            ["A", "B", "C"],
            [1.23, 2, b"XYZ"],
        ]

        if swadr.PYTHON_3:
            txtio = io.StringIO()
        else:
            txtio = io.BytesIO()

        # This simply needs to not fail, so the contents of txtio is not
        # checked.
        swadr.pretty_print_table(table, dest=txtio)
Esempio n. 4
0
    def test_pretty_print_table_with_unicode(self):
        if swadr.PYTHON_3:
            txtio = io.StringIO()
            table = ["☺"]
        else:
            txtio = io.BytesIO()
            table = [unicode("☺", encoding="utf-8")]

        expected = "\n".join((
            "+---+",
            "| ☺ |",
            "+---+\n",
        ))

        swadr.pretty_print_table(table, dest=txtio)
        txtio.seek(0)
        self.assertEqual(txtio.read(), expected)
Esempio n. 5
0
    def test_pretty_print_table_breakafter_False(self):
        table = [
            [unicode("A"), unicode("B"), unicode("C")],
            [unicode("1"), unicode("2"), unicode("3")],
            [unicode("3"), unicode("9"), unicode("27")],
        ]
        expected = unicode("\n").join((
            "+---+---+----+",
            "| A | B | C  |",
            "| 1 | 2 | 3  |",
            "| 3 | 9 | 27 |",
            "+---+---+----+\n",
        ))

        if swadr.PYTHON_3:
            txtio = io.StringIO()
        else:
            txtio = io.BytesIO()

        swadr.pretty_print_table(table, breakafter=False, dest=txtio)
        txtio.seek(0)
        self.assertEqual(txtio.read(), expected)
Esempio n. 6
0
    def test_numbers_cause_right_alignment(self):
        table = [
            ["One", "Two", "Three"],
            ["Uno", 2, "Tres"],
            ["Uma", 9999, "Troi"],
        ]

        if swadr.PYTHON_3:
            txtio = io.StringIO()
        else:
            txtio = io.BytesIO()

        expected = "\n".join((
            "+-----+------+-------+",
            "| One |  Two | Three |",
            "+-----+------+-------+",
            "| Uno |    2 | Tres  |",
            "| Uma | 9999 | Troi  |",
            "+-----+------+-------+\n",
        ))

        swadr.pretty_print_table(table, breakafter=[0], dest=txtio)
        txtio.seek(0)
        self.assertEqual(txtio.read(), expected)