def test_negative_widths(self) -> None: with pytest.raises(ValueError, match="Width must be positive integer"): ColumnWidth(width=-1) with pytest.raises(ValueError, match="Min must be positive integer"): ColumnWidth(min=-1) with pytest.raises(ValueError, match="Max must be positive integer"): ColumnWidth(max=-1)
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_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 "]
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_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"]
def test_parse_columns_props_full() -> None: assert parse_columns("{id;max=30;min=5;align=center;NEW_TITLE}") == [ JobColumnInfo("id", "NEW_TITLE", Align.CENTER, ColumnWidth(5, 30)) ]
def test_parse_columns_props_width() -> None: ci = COLUMNS_MAP["id"] assert parse_columns("{id;max=30;min=5;width=10}") == [ JobColumnInfo("id", ci.title, ci.align, ColumnWidth(10, 10, 10)) ]
def test_parse_columns_props_subset() -> None: ci = COLUMNS_MAP["name"] assert parse_columns("{name;align=center;max=20}") == [ JobColumnInfo("name", ci.title, Align.CENTER, ColumnWidth(None, 20)) ]