def test_partial_column_width(self) -> None:
        rows = [["a", "Alpha"], ["b", "Bravo"]]
        result = list(
            table(rows, widths=[ColumnWidth(),
                                ColumnWidth(width=10)]))
        assert result == ["a  Alpha     ", "b  Bravo     "]

        result = list(table(rows, widths=[ColumnWidth(width=5)]))
        assert result == ["a      Alpha", "b      Bravo"]

        result = list(table(rows, widths=[ColumnWidth(width=5),
                                          ColumnWidth()]))
        assert result == ["a      Alpha", "b      Bravo"]
    def test_column_width_range_violation(self) -> None:
        rows = [["12345"]]
        result = list(table(rows, widths=[ColumnWidth(2, 3)]))
        assert result == ["123", "45 "]

        rows = [["12"]]
        result = list(table(rows, widths=[ColumnWidth(3, 5)]))
        assert result == ["12".ljust(5)]

        rows = [["12"]]
        result = list(table(rows, widths=[ColumnWidth(min=3)]))
        assert result == ["12".ljust(3)]

        rows = [["123"]]
        result = list(table(rows, widths=[ColumnWidth(max=2)]))
        assert result == ["12", "3 "]
Exemplo n.º 3
0
 def __call__(self, disks: Sequence[Disk]) -> Iterator[str]:
     disks_info = [
         self._table_header_long
         if self._long_format else self._table_header_short,
         *(self._disk_to_table_row(disk) for disk in disks),
     ]
     return table(disks_info)
 def test_empty_first_columns(self) -> None:
     rows = [["a", "Alpha"], ["b", "Bravo"]]
     result = list(
         table(rows,
               max_width=2,
               widths=[ColumnWidth(width=1),
                       ColumnWidth(width=2)]))
     assert result == ["a ", "b "]
 def test_simple(self) -> None:
     rows = [["a", "Alpha"], ["b", "Bravo"]]
     result = list(
         table(rows, widths=[ColumnWidth(width=10),
                             ColumnWidth(width=10)]))
     print("\n" + "\n".join(result))
     assert len(result) == 2
     assert "a" in result[0]
     assert "Alpha" in result[0]
     assert "b" in result[1]
     assert "Bravo" in result[1]
 def test_multiline(self) -> None:
     rows = [
         ["a", "Alpha"],
         ["b", "Bravo and Delta And Epsilon"],
         ["two line here", "1213241324141413134"],
     ]
     result = list(
         table(
             rows,
             aligns=[Align.CENTER, Align.RIGHT],
             widths=[ColumnWidth(width=10),
                     ColumnWidth(width=10)],
         ))
     assert len(result) == 6
     assert "a" in result[0]
     assert "Alpha" in result[0]
     assert "b" in result[1]
     assert "Bravo" in result[1]
     assert "Delta" in result[2]
     assert "Epsilon" in result[3]
     assert "here" in result[5]
 def test_no_any_width(self) -> None:
     rows = [["a", "Alpha"], ["b", "Bravo"]]
     result = list(table(rows))
     assert result == ["a  Alpha", "b  Bravo"]
 def test_empty(self) -> None:
     result = list(table(()))
     assert result == []
 def test_column_width_range_simple(self) -> None:
     rows = [["a", "Alpha"], ["b", "Bravo"]]
     result = list(
         table(rows, widths=[ColumnWidth(1, 1),
                             ColumnWidth(1, 5)]))
     assert result == ["a  Alpha", "b  Bravo"]
Exemplo n.º 10
0
 def test_max_table_width(self) -> None:
     rows = [["a", "Alpha"], ["b", "Bravo"]]
     result = list(table(rows, max_width=5))
     for line in result:
         assert len(line) == 5