Coverage for tests / unit / formatters / styles / test_plain.py: 100%
34 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.plain module."""
3from __future__ import annotations
5from assertpy import assert_that
7from lintro.formatters.styles.plain import PlainStyle
10def test_plain_style_empty_rows(plain_style: PlainStyle) -> None:
11 """PlainStyle returns no issues message for empty rows.
13 Args:
14 plain_style: PlainStyle fixture.
15 """
16 result = plain_style.format(["File", "Line"], [])
17 assert_that(result).is_equal_to("No issues found.")
20def test_plain_style_single_row(plain_style: PlainStyle) -> None:
21 """PlainStyle formats single row correctly.
23 Args:
24 plain_style: PlainStyle fixture.
25 """
26 result = plain_style.format(
27 ["File", "Line"],
28 [["test.py", "10"]],
29 )
30 assert_that(result).contains("File | Line")
31 assert_that(result).contains("test.py | 10")
34def test_plain_style_multiple_rows(plain_style: PlainStyle) -> None:
35 """PlainStyle formats multiple rows correctly.
37 Args:
38 plain_style: PlainStyle fixture.
39 """
40 result = plain_style.format(
41 ["File"],
42 [["a.py"], ["b.py"]],
43 )
44 lines = result.split("\n")
45 assert_that(len(lines)).is_equal_to(4) # header + separator + 2 data
48def test_plain_style_has_separator_line(plain_style: PlainStyle) -> None:
49 """PlainStyle includes separator line after header.
51 Args:
52 plain_style: PlainStyle fixture.
53 """
54 result = plain_style.format(
55 ["File", "Line"],
56 [["test.py", "10"]],
57 )
58 lines = result.split("\n")
59 # Second line should be dashes
60 assert_that(lines[1]).matches(r"^-+$")
63def test_plain_style_separator_matches_header_length(
64 plain_style: PlainStyle,
65) -> None:
66 """PlainStyle separator matches header length.
68 Args:
69 plain_style: PlainStyle fixture.
70 """
71 result = plain_style.format(
72 ["File", "Line"],
73 [["test.py", "10"]],
74 )
75 lines = result.split("\n")
76 header_len = len(lines[0])
77 separator_len = len(lines[1])
78 assert_that(separator_len).is_equal_to(header_len)
81def test_plain_style_pads_short_rows(plain_style: PlainStyle) -> None:
82 """PlainStyle pads short rows with empty cells.
84 Args:
85 plain_style: PlainStyle fixture.
86 """
87 result = plain_style.format(
88 ["File", "Line", "Message"],
89 [["test.py"]],
90 )
91 data_line = result.split("\n")[2]
92 assert_that(data_line.count("|")).is_equal_to(2)
95def test_plain_style_ignores_tool_name(plain_style: PlainStyle) -> None:
96 """PlainStyle ignores tool_name parameter.
98 Args:
99 plain_style: PlainStyle fixture.
100 """
101 result = plain_style.format(
102 ["File"],
103 [["test.py"]],
104 tool_name="ruff",
105 )
106 assert_that(result).does_not_contain("ruff")
109def test_plain_style_converts_values_to_string(plain_style: PlainStyle) -> None:
110 """PlainStyle converts non-string values to strings.
112 Args:
113 plain_style: PlainStyle fixture.
114 """
115 result = plain_style.format(
116 ["Number", "Bool"],
117 [[42, True]],
118 )
119 assert_that(result).contains("42 | True")