Coverage for tests / unit / formatters / styles / test_html.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Tests for lintro.formatters.styles.html module.""" 

2 

3from __future__ import annotations 

4 

5from assertpy import assert_that 

6 

7from lintro.formatters.styles.html import HtmlStyle 

8 

9 

10def test_html_style_empty_rows(html_style: HtmlStyle) -> None: 

11 """HtmlStyle returns no issues message for empty rows. 

12 

13 Args: 

14 html_style: HtmlStyle fixture. 

15 """ 

16 result = html_style.format(["File", "Line"], []) 

17 assert_that(result).is_equal_to("<p>No issues found.</p>") 

18 

19 

20def test_html_style_single_row(html_style: HtmlStyle) -> None: 

21 """HtmlStyle formats single row correctly. 

22 

23 Args: 

24 html_style: HtmlStyle fixture. 

25 """ 

26 result = html_style.format( 

27 ["File", "Line"], 

28 [["test.py", "10"]], 

29 ) 

30 assert_that(result).contains("<table>") 

31 assert_that(result).contains("</table>") 

32 assert_that(result).contains("<th>File</th>") 

33 assert_that(result).contains("<td>test.py</td>") 

34 

35 

36def test_html_style_multiple_rows(html_style: HtmlStyle) -> None: 

37 """HtmlStyle formats multiple rows correctly. 

38 

39 Args: 

40 html_style: HtmlStyle fixture. 

41 """ 

42 result = html_style.format( 

43 ["File"], 

44 [["a.py"], ["b.py"]], 

45 ) 

46 assert_that(result.count("<tr>")).is_equal_to(3) # 1 header + 2 data 

47 

48 

49def test_html_style_escapes_html_characters(html_style: HtmlStyle) -> None: 

50 """HtmlStyle escapes HTML special characters. 

51 

52 Args: 

53 html_style: HtmlStyle fixture. 

54 """ 

55 result = html_style.format( 

56 ["Message"], 

57 [["<script>alert('xss')</script>"]], 

58 ) 

59 assert_that(result).contains("&lt;script&gt;") 

60 assert_that(result).does_not_contain("<script>") 

61 

62 

63def test_html_style_escapes_ampersand(html_style: HtmlStyle) -> None: 

64 """HtmlStyle escapes ampersand character. 

65 

66 Args: 

67 html_style: HtmlStyle fixture. 

68 """ 

69 result = html_style.format( 

70 ["Message"], 

71 [["A & B"]], 

72 ) 

73 assert_that(result).contains("A &amp; B") 

74 

75 

76def test_html_style_pads_short_rows(html_style: HtmlStyle) -> None: 

77 """HtmlStyle pads short rows with empty cells. 

78 

79 Args: 

80 html_style: HtmlStyle fixture. 

81 """ 

82 result = html_style.format( 

83 ["File", "Line", "Message"], 

84 [["test.py"]], 

85 ) 

86 # Should have 3 <td> elements in the row 

87 assert_that(result.count("<td>")).is_equal_to(3) 

88 

89 

90def test_html_style_ignores_tool_name(html_style: HtmlStyle) -> None: 

91 """HtmlStyle ignores tool_name parameter. 

92 

93 Args: 

94 html_style: HtmlStyle fixture. 

95 """ 

96 result = html_style.format( 

97 ["File"], 

98 [["test.py"]], 

99 tool_name="ruff", 

100 ) 

101 assert_that(result).does_not_contain("ruff")