Skip to content

Commit

Permalink
Add tests of the _html_color() util fn
Browse files Browse the repository at this point in the history
rich-iannone committed Jan 10, 2024
1 parent 9727709 commit ed25472
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
@@ -1003,3 +1003,59 @@ def test_format_number_with_sep_dec_marks():
gt = GT(df).fmt_number(columns="x", decimals=5, sep_mark=".", dec_mark=",")
x = _get_column_of_values(gt, column_name="x", context="html")
assert x == ["12.345.678,12346", "1,00000", "0,00000", "\u2212" + "12.345.678,12346"]


# ------------------------------------------------------------------------------
# Test `data_color()` and util functions
# ------------------------------------------------------------------------------


@pytest.fixture
def df_color():
df = pd.DataFrame(
{
"A": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
"B": [10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
"C": ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"],
}
)
return df


@pytest.mark.parametrize(
"color, x_out",
[
("red", "#FF0000"),
("#FFF", "#FFFFFF"),
("crimson", "#DC143C"),
("SteelBlue", "#4682B4"),
("RED", "#FF0000"),
("#FFFFFF", "#FFFFFF"),
("transparent", "#FFFFFF00"),
],
)
def test_html_color(color: str, x_out: str):
from great_tables._formats import _html_color

x = _html_color(colors=[color])
assert x == [x_out]


@pytest.mark.parametrize(
"color, x_out, alpha",
[
("red", "#FF0000D8", 0.85),
("#DEF", "#DDEEFFD8", 0.85),
("crimson", "#DC143CD8", 0.85),
("SteelBlue", "#4682B4D8", 0.85),
("RED", "#FF0000D8", 0.85),
("#FFFFFF", "#FFFFFFD8", 0.85),
("transparent", "#FFFFFF00", 0.85),
("#FFFFFF00", "#FFFFFF00", 0.85),
],
)
def test_html_color_with_alpha(color: str, x_out: str, alpha: float):
from great_tables._formats import _html_color

x = _html_color(colors=[color], alpha=alpha)
assert x == [x_out]

0 comments on commit ed25472

Please sign in to comment.