Coverage for tests / unit / utils / result_formatters / test_generic_output.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 generic tool output in print_tool_result."""
3from __future__ import annotations
5from typing import TYPE_CHECKING, Any
7import pytest
8from assertpy import assert_that
10from lintro.utils.result_formatters import print_tool_result
12if TYPE_CHECKING:
13 from collections.abc import Callable
16def test_no_issues_shows_success_message(
17 console_capture_with_kwargs: tuple[
18 Callable[..., None],
19 list[tuple[str, dict[str, Any]]],
20 ],
21 success_capture: tuple[Callable[[str], None], list[str]],
22) -> None:
23 """Verify success message displayed when tool finds no issues.
25 Args:
26 console_capture_with_kwargs: Mock console output capture with kwargs.
27 success_capture: Mock success message capture.
28 """
29 mock_console, _ = console_capture_with_kwargs
30 mock_success, success_calls = success_capture
32 print_tool_result(
33 console_output_func=mock_console,
34 success_func=mock_success,
35 tool_name="ruff",
36 output="",
37 issues_count=0,
38 )
40 assert_that(success_calls).contains("✓ No issues found.")
43def test_issues_found_shows_error_message_with_count(
44 console_capture_with_kwargs: tuple[
45 Callable[..., None],
46 list[tuple[str, dict[str, Any]]],
47 ],
48 success_capture: tuple[Callable[[str], None], list[str]],
49) -> None:
50 """Verify error message with issue count displayed when issues found.
52 Args:
53 console_capture_with_kwargs: Mock console output capture with kwargs.
54 success_capture: Mock success message capture.
55 """
56 mock_console, console_output = console_capture_with_kwargs
57 mock_success, _ = success_capture
59 print_tool_result(
60 console_output_func=mock_console,
61 success_func=mock_success,
62 tool_name="ruff",
63 output="Some lint errors",
64 issues_count=5,
65 )
67 red_texts = [t for t, kwargs in console_output if kwargs.get("color") == "red"]
68 assert_that(any("5 issues" in t for t in red_texts)).is_true()
71def test_success_false_shows_failure_even_with_zero_issues(
72 console_capture_with_kwargs: tuple[
73 Callable[..., None],
74 list[tuple[str, dict[str, Any]]],
75 ],
76 success_capture: tuple[Callable[[str], None], list[str]],
77) -> None:
78 """Verify failure message shown when success=False despite zero issues.
80 Args:
81 console_capture_with_kwargs: Mock console output capture with kwargs.
82 success_capture: Mock success message capture.
83 """
84 mock_console, console_output = console_capture_with_kwargs
85 mock_success, _ = success_capture
87 print_tool_result(
88 console_output_func=mock_console,
89 success_func=mock_success,
90 tool_name="ruff",
91 output="",
92 issues_count=0,
93 success=False,
94 )
96 red_texts = [t for t, kwargs in console_output if kwargs.get("color") == "red"]
97 assert_that(any("failed" in t.lower() for t in red_texts)).is_true()
100@pytest.mark.parametrize(
101 ("output_text", "description"),
102 [
103 ("No files to lint", "no files to lint message"),
104 ("No Python files found to lint", "no Python files found message"),
105 ],
106 ids=["no_files_to_lint", "no_python_files_found"],
107)
108def test_no_files_processed_warning(
109 console_capture_with_kwargs: tuple[
110 Callable[..., None],
111 list[tuple[str, dict[str, Any]]],
112 ],
113 success_capture: tuple[Callable[[str], None], list[str]],
114 output_text: str,
115 description: str,
116) -> None:
117 """Verify warning shown when no files were processed.
119 Args:
120 console_capture_with_kwargs: Mock console output capture with kwargs.
121 success_capture: Mock success message capture.
122 output_text: Tool output text to test.
123 description: Description of the test case.
124 """
125 mock_console, console_output = console_capture_with_kwargs
126 mock_success, _ = success_capture
128 print_tool_result(
129 console_output_func=mock_console,
130 success_func=mock_success,
131 tool_name="ruff",
132 output=output_text,
133 issues_count=0,
134 )
136 texts = [t for t, _ in console_output]
137 assert_that(any("No files processed" in t for t in texts)).described_as(
138 f"Expected 'No files processed' warning for {description}",
139 ).is_true()