Coverage for tdom/classnames_test.py: 100%
27 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-17 19:54 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-17 19:54 +0000
1import pytest
3from .classnames import classnames
6def test_classnames_empty():
7 assert classnames() == ""
10def test_classnames_strings():
11 assert classnames("btn", "btn-primary") == "btn btn-primary"
14def test_classnames_strings_strip():
15 assert classnames(" btn ", " btn-primary ") == "btn btn-primary"
18def test_cslx_empty_strings():
19 assert classnames("", "btn", "", "btn-primary", "") == "btn btn-primary"
22def test_clsx_booleans():
23 assert classnames(True, False) == ""
26def test_classnames_lists_and_tuples():
27 assert (
28 classnames(["btn", "btn-primary"], ("active", "disabled"))
29 == "btn btn-primary active disabled"
30 )
33def test_classnames_dicts():
34 assert (
35 classnames(
36 "btn",
37 {"btn-primary": True, "disabled": False, "active": True, "shown": "yes"},
38 )
39 == "btn btn-primary active shown"
40 )
43def test_classnames_mixed_inputs():
44 assert (
45 classnames(
46 "btn",
47 ["btn-primary", "active"],
48 {"disabled": True, "hidden": False},
49 ("extra",),
50 )
51 == "btn btn-primary active disabled extra"
52 )
55def test_classnames_ignores_none_and_false():
56 assert (
57 classnames("btn", None, False, "active", {"hidden": None, "visible": True})
58 == "btn active visible"
59 )
62def test_classnames_raises_type_error_on_invalid_input():
63 with pytest.raises(ValueError):
64 classnames(123)
66 with pytest.raises(ValueError):
67 classnames(["btn", 456])
70def test_classnames_kitchen_sink():
71 assert (
72 classnames(
73 "foo",
74 [1 and "bar", {"baz": False, "bat": None}, ["hello", ["world"]]],
75 "cya",
76 )
77 == "foo bar hello world cya"
78 )