Skip to content

Commit

Permalink
Add ColorTable tests for various header/title options
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Oct 17, 2024
1 parent 62346e3 commit fa57608
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tests/test_colortable.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,16 @@ class TestColorTableRendering:
Tests the color table rendering using the default alignment (`'c'`)
"""

def test_color_table_rendering(self) -> None:
@pytest.mark.parametrize(
["with_title", "with_header"],
[
(False, True), # the default
(True, True), # titled
(True, False), # titled, no header
(True, True), # both title and header
],
)
def test_color_table_rendering(self, with_title: bool, with_header: bool) -> None:
"""Tests the color table rendering using the default alignment (`'c'`)"""
chars = {
"+": "\x1b[36m+\x1b[0m\x1b[96m",
Expand Down Expand Up @@ -140,15 +149,23 @@ def test_color_table_rendering(self) -> None:
(plus + minus * 3) * 6 + plus,
)

header_str = str("\n".join(header))
body_str = str("\n".join(body))
if with_title:
header_str = str("\n".join(header))
else:
header_str = str(header[2])
if with_header:
body_str = str("\n".join(body))
else:
body_str = str("\n".join(body[2:]))

table = ColorTable(
("A", "B", "C", "D", "E", "F"),
theme=Themes.OCEAN,
)

table.title = "Efforts"
if with_title:
table.title = "Efforts"
table.header = with_header
table.add_row([1, 2, 3, 4, 5, 6])

expected = header_str + "\n" + body_str + "\x1b[0m"
Expand Down

0 comments on commit fa57608

Please sign in to comment.