Coverage for tests / unit / tools / ruff / check / test_config_detection.py: 100%
17 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 config file detection and usage in execute_ruff_check."""
3from __future__ import annotations
5from unittest.mock import MagicMock, patch
7from assertpy import assert_that
9from lintro.tools.implementations.ruff.check import execute_ruff_check
12def test_execute_ruff_check_uses_cwd_for_config_discovery(
13 mock_ruff_tool: MagicMock,
14) -> None:
15 """Use cwd for config file discovery.
17 Args:
18 mock_ruff_tool: Mock RuffTool instance for testing.
19 """
20 with (
21 patch(
22 "lintro.tools.implementations.ruff.check.walk_files_with_excludes",
23 return_value=["/test/project/test.py"],
24 ),
25 patch(
26 "lintro.tools.implementations.ruff.check.run_subprocess_with_timeout",
27 return_value=(True, "[]"),
28 ) as mock_subprocess,
29 patch(
30 "lintro.tools.implementations.ruff.check.parse_ruff_output",
31 return_value=[],
32 ),
33 ):
34 execute_ruff_check(mock_ruff_tool, ["/test/project"])
36 # Verify _get_cwd was called to determine working directory
37 mock_ruff_tool._get_cwd.assert_called()
39 # Verify subprocess was called with cwd
40 mock_subprocess.assert_called()
41 call_kwargs = mock_subprocess.call_args
42 assert_that(call_kwargs.kwargs.get("cwd")).is_equal_to("/test/project")
45def test_execute_ruff_check_with_config_args(
46 mock_ruff_tool: MagicMock,
47) -> None:
48 """Include config args in command when provided.
50 Args:
51 mock_ruff_tool: Mock RuffTool instance for testing.
52 """
53 mock_ruff_tool._build_config_args.return_value = [
54 "--line-length",
55 "100",
56 ]
58 with (
59 patch(
60 "lintro.tools.implementations.ruff.check.walk_files_with_excludes",
61 return_value=["test.py"],
62 ),
63 patch(
64 "lintro.tools.implementations.ruff.check.run_subprocess_with_timeout",
65 return_value=(True, "[]"),
66 ),
67 patch(
68 "lintro.tools.implementations.ruff.check.parse_ruff_output",
69 return_value=[],
70 ),
71 patch(
72 "lintro.tools.implementations.ruff.commands.build_ruff_check_command",
73 ) as mock_build_cmd,
74 ):
75 mock_build_cmd.return_value = [
76 "ruff",
77 "check",
78 "--line-length",
79 "100",
80 "test.py",
81 ]
83 execute_ruff_check(mock_ruff_tool, ["/test/project"])
85 mock_build_cmd.assert_called_once()