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
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Tests for lintro.formatters.styles.markdown module."""
3from __future__ import annotations
5from assertpy import assert_that
7from lintro.formatters.styles.markdown import MarkdownStyle
10def test_markdown_style_empty_rows(markdown_style: MarkdownStyle) -> None:
11 """MarkdownStyle returns no issues message for empty rows.
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.")
20def test_markdown_style_single_row(markdown_style: MarkdownStyle) -> None:
21 """MarkdownStyle formats single row correctly.
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 |")
35def test_markdown_style_multiple_rows(markdown_style: MarkdownStyle) -> None:
36 """MarkdownStyle formats multiple rows correctly.
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
49def test_markdown_style_escapes_pipe_character(markdown_style: MarkdownStyle) -> None:
50 """MarkdownStyle escapes pipe characters in content.
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")
62def test_markdown_style_pads_short_rows(markdown_style: MarkdownStyle) -> None:
63 """MarkdownStyle pads short rows with empty cells.
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
77def test_markdown_style_ignores_tool_name(markdown_style: MarkdownStyle) -> None:
78 """MarkdownStyle ignores tool_name parameter.
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")
91def test_markdown_style_separator_matches_columns(
92 markdown_style: MarkdownStyle,
93) -> None:
94 """MarkdownStyle separator row matches column count.
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)