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

29 statements  

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

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

2 

3from __future__ import annotations 

4 

5from assertpy import assert_that 

6 

7from lintro.formatters.styles.markdown import MarkdownStyle 

8 

9 

10def test_markdown_style_empty_rows(markdown_style: MarkdownStyle) -> None: 

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

12 

13 Args: 

14 markdown_style: MarkdownStyle fixture. 

15 """ 

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

17 assert_that(result).is_equal_to("No issues found.") 

18 

19 

20def test_markdown_style_single_row(markdown_style: MarkdownStyle) -> None: 

21 """MarkdownStyle formats single row correctly. 

22 

23 Args: 

24 markdown_style: MarkdownStyle fixture. 

25 """ 

26 result = markdown_style.format( 

27 ["File", "Line"], 

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

29 ) 

30 assert_that(result).contains("| File | Line |") 

31 assert_that(result).contains("| --- | --- |") 

32 assert_that(result).contains("| test.py | 10 |") 

33 

34 

35def test_markdown_style_multiple_rows(markdown_style: MarkdownStyle) -> None: 

36 """MarkdownStyle formats multiple rows correctly. 

37 

38 Args: 

39 markdown_style: MarkdownStyle fixture. 

40 """ 

41 result = markdown_style.format( 

42 ["File"], 

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

44 ) 

45 lines = result.split("\n") 

46 assert_that(len(lines)).is_equal_to(4) # header + separator + 2 data 

47 

48 

49def test_markdown_style_escapes_pipe_character(markdown_style: MarkdownStyle) -> None: 

50 """MarkdownStyle escapes pipe characters in content. 

51 

52 Args: 

53 markdown_style: MarkdownStyle fixture. 

54 """ 

55 result = markdown_style.format( 

56 ["Message"], 

57 [["A | B"]], 

58 ) 

59 assert_that(result).contains("A \\| B") 

60 

61 

62def test_markdown_style_pads_short_rows(markdown_style: MarkdownStyle) -> None: 

63 """MarkdownStyle pads short rows with empty cells. 

64 

65 Args: 

66 markdown_style: MarkdownStyle fixture. 

67 """ 

68 result = markdown_style.format( 

69 ["File", "Line", "Message"], 

70 [["test.py"]], 

71 ) 

72 # Row should have 3 cells separated by | 

73 data_line = result.split("\n")[2] 

74 assert_that(data_line.count("|")).is_equal_to(4) # leading + 3 separators 

75 

76 

77def test_markdown_style_ignores_tool_name(markdown_style: MarkdownStyle) -> None: 

78 """MarkdownStyle ignores tool_name parameter. 

79 

80 Args: 

81 markdown_style: MarkdownStyle fixture. 

82 """ 

83 result = markdown_style.format( 

84 ["File"], 

85 [["test.py"]], 

86 tool_name="ruff", 

87 ) 

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

89 

90 

91def test_markdown_style_separator_matches_columns( 

92 markdown_style: MarkdownStyle, 

93) -> None: 

94 """MarkdownStyle separator row matches column count. 

95 

96 Args: 

97 markdown_style: MarkdownStyle fixture. 

98 """ 

99 result = markdown_style.format( 

100 ["A", "B", "C", "D"], 

101 [["1", "2", "3", "4"]], 

102 ) 

103 separator_line = result.split("\n")[1] 

104 assert_that(separator_line.count("---")).is_equal_to(4)