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

1"""Tests for config file detection and usage in execute_ruff_check.""" 

2 

3from __future__ import annotations 

4 

5from unittest.mock import MagicMock, patch 

6 

7from assertpy import assert_that 

8 

9from lintro.tools.implementations.ruff.check import execute_ruff_check 

10 

11 

12def test_execute_ruff_check_uses_cwd_for_config_discovery( 

13 mock_ruff_tool: MagicMock, 

14) -> None: 

15 """Use cwd for config file discovery. 

16 

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"]) 

35 

36 # Verify _get_cwd was called to determine working directory 

37 mock_ruff_tool._get_cwd.assert_called() 

38 

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") 

43 

44 

45def test_execute_ruff_check_with_config_args( 

46 mock_ruff_tool: MagicMock, 

47) -> None: 

48 """Include config args in command when provided. 

49 

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 ] 

57 

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 ] 

82 

83 execute_ruff_check(mock_ruff_tool, ["/test/project"]) 

84 

85 mock_build_cmd.assert_called_once()