Skip to content

Commit

Permalink
Expand tests for colon_grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Nicholson committed Sep 26, 2024
1 parent 4a17bc7 commit 18d7b50
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions test/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,9 @@ def test_fancy_grid_multiline_row_align():
result = tabulate(table, tablefmt="fancy_grid", rowalign=[None, "center", "bottom"])
assert_equal(expected, result)


def test_colon_grid():
"Output: colon_grid with two columns aligned left and center"
expected = "\n".join(
[
"+------+------+",
Expand All @@ -1427,6 +1429,82 @@ def test_colon_grid():
assert_equal(expected, result)


def test_colon_grid_wide_characters():
"Output: colon_grid with wide chars in header"
try:
import wcwidth # noqa
except ImportError:
skip("test_colon_grid_wide_characters is skipped")
headers = list(_test_table_headers)
headers[1] = "配列"
expected = "\n".join(
[
"+-----------+---------+",
"| strings | 配列 |",
"+:==========+========:+",
"| spam | 41.9999 |",
"+-----------+---------+",
"| eggs | 451 |",
"+-----------+---------+",
]
)
result = tabulate(_test_table, headers, tablefmt="colon_grid", colalign=["left", "right"])
assert_equal(expected, result)


def test_colon_grid_headerless():
"Output: colon_grid without headers"
expected = "\n".join(
[
"+------+---------+",
"| spam | 41.9999 |",
"+------+---------+",
"| eggs | 451 |",
"+------+---------+",
]
)
result = tabulate(_test_table, tablefmt="colon_grid")
assert_equal(expected, result)


def test_colon_grid_multiline():
"Output: colon_grid with multiline cells"
table = [["Data\n5", "33\n3"]]
headers = ["H1\n1", "H2\n2"]
expected = "\n".join(
[
"+------+------+",
"| H1 | H2 |",
"| 1 | 2 |",
"+:=====+:=====+",
"| Data | 33 |",
"| 5 | 3 |",
"+------+------+",
]
)
result = tabulate(table, headers, tablefmt="colon_grid")
assert_equal(expected, result)


def test_colon_grid_with_empty_cells():
table = [["A", ""], ["", "B"]]
headers = ["H1", "H2"]
alignments = ["center", "right"]
expected = "\n".join(
[
"+------+------+",
"| H1 | H2 |",
"+:====:+=====:+",
"| A | |",
"+------+------+",
"| | B |",
"+------+------+",
]
)
result = tabulate(table, headers, tablefmt="colon_grid", colalign=alignments)
assert_equal(expected, result)


def test_outline():
"Output: outline with headers"
expected = "\n".join(
Expand Down

0 comments on commit 18d7b50

Please sign in to comment.