Coverage for tests / unit / tools / ruff / fix / test_real_plugin.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Tests for execute_ruff_fix with real RuffPlugin.""" 

2 

3from __future__ import annotations 

4 

5from typing import TYPE_CHECKING 

6from unittest.mock import patch 

7 

8import pytest 

9from assertpy import assert_that 

10 

11from lintro.tools.implementations.ruff.fix import execute_ruff_fix 

12 

13if TYPE_CHECKING: 

14 from lintro.tools.definitions.ruff import RuffPlugin 

15 

16 

17def test_execute_ruff_fix_with_real_plugin_no_files( 

18 ruff_plugin: RuffPlugin, 

19) -> None: 

20 """Return success when paths are empty using real plugin. 

21 

22 Args: 

23 ruff_plugin: RuffPlugin instance for testing. 

24 """ 

25 result = execute_ruff_fix(ruff_plugin, []) 

26 

27 assert_that(result.success).is_true() 

28 assert_that(result.output).is_equal_to("No files to fix.") 

29 

30 

31def test_execute_ruff_fix_with_real_plugin_nonexistent_path( 

32 ruff_plugin: RuffPlugin, 

33) -> None: 

34 """Raise FileNotFoundError for nonexistent paths using real plugin. 

35 

36 Args: 

37 ruff_plugin: RuffPlugin instance for testing. 

38 """ 

39 with pytest.raises(FileNotFoundError): 

40 execute_ruff_fix(ruff_plugin, ["/nonexistent/path"]) 

41 

42 

43def test_execute_ruff_fix_integration_with_temp_file( 

44 ruff_plugin: RuffPlugin, 

45 temp_python_file: str, 

46) -> None: 

47 """Execute fix on actual temp file using real plugin. 

48 

49 Args: 

50 ruff_plugin: RuffPlugin instance for testing. 

51 temp_python_file: Temporary Python file for testing. 

52 """ 

53 with ( 

54 patch.object(ruff_plugin, "_run_subprocess") as mock_run, 

55 patch.object( 

56 ruff_plugin, 

57 "_verify_tool_version", 

58 ) as mock_verify, 

59 ): 

60 mock_verify.return_value = None 

61 mock_run.return_value = (True, "[]") 

62 

63 result = execute_ruff_fix(ruff_plugin, [temp_python_file]) 

64 

65 assert_that(result.success).is_true()