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

1import pytest 

2 

3from .classnames import classnames 

4 

5 

6def test_classnames_empty(): 

7 assert classnames() == "" 

8 

9 

10def test_classnames_strings(): 

11 assert classnames("btn", "btn-primary") == "btn btn-primary" 

12 

13 

14def test_classnames_strings_strip(): 

15 assert classnames(" btn ", " btn-primary ") == "btn btn-primary" 

16 

17 

18def test_cslx_empty_strings(): 

19 assert classnames("", "btn", "", "btn-primary", "") == "btn btn-primary" 

20 

21 

22def test_clsx_booleans(): 

23 assert classnames(True, False) == "" 

24 

25 

26def test_classnames_lists_and_tuples(): 

27 assert ( 

28 classnames(["btn", "btn-primary"], ("active", "disabled")) 

29 == "btn btn-primary active disabled" 

30 ) 

31 

32 

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 ) 

41 

42 

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 ) 

53 

54 

55def test_classnames_ignores_none_and_false(): 

56 assert ( 

57 classnames("btn", None, False, "active", {"hidden": None, "visible": True}) 

58 == "btn active visible" 

59 ) 

60 

61 

62def test_classnames_raises_type_error_on_invalid_input(): 

63 with pytest.raises(ValueError): 

64 classnames(123) 

65 

66 with pytest.raises(ValueError): 

67 classnames(["btn", 456]) 

68 

69 

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 )