Coverage for tests / unit / tools / ruff / check / test_output_format.py: 100%
15 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 output format in execute_ruff_check."""
3from __future__ import annotations
5from unittest.mock import MagicMock, patch
7from assertpy import assert_that
9from lintro.parsers.ruff.ruff_issue import RuffIssue
10from lintro.tools.implementations.ruff.check import execute_ruff_check
13def test_execute_ruff_check_output_is_none_on_success(
14 mock_ruff_tool: MagicMock,
15) -> None:
16 """Output summary should be None (suppressed) for successful run.
18 Args:
19 mock_ruff_tool: Mock RuffTool instance for testing.
20 """
21 with (
22 patch(
23 "lintro.tools.implementations.ruff.check.walk_files_with_excludes",
24 return_value=["test.py"],
25 ),
26 patch(
27 "lintro.tools.implementations.ruff.check.run_subprocess_with_timeout",
28 return_value=(True, "[]"),
29 ),
30 patch(
31 "lintro.tools.implementations.ruff.check.parse_ruff_output",
32 return_value=[],
33 ),
34 ):
35 result = execute_ruff_check(mock_ruff_tool, ["/test/project"])
37 # Output is suppressed per the source code comment
38 assert_that(result.output).is_none()
41def test_execute_ruff_check_output_is_none_with_issues(
42 mock_ruff_tool: MagicMock,
43) -> None:
44 """Output summary should be None even with issues (formatters handle display).
46 Args:
47 mock_ruff_tool: Mock RuffTool instance for testing.
48 """
49 lint_issues = [
50 RuffIssue(file="test.py", line=1, column=1, code="F401", message="unused"),
51 ]
53 with (
54 patch(
55 "lintro.tools.implementations.ruff.check.walk_files_with_excludes",
56 return_value=["test.py"],
57 ),
58 patch(
59 "lintro.tools.implementations.ruff.check.run_subprocess_with_timeout",
60 return_value=(False, "[]"),
61 ),
62 patch(
63 "lintro.tools.implementations.ruff.check.parse_ruff_output",
64 return_value=lint_issues,
65 ),
66 ):
67 result = execute_ruff_check(mock_ruff_tool, ["/test/project"])
69 # Verify failure when subprocess fails and issues are found
70 assert_that(result.success).is_false()
71 # Output is suppressed - formatters handle the display
72 assert_that(result.output).is_none()