Coverage for tests / unit / utils / result_formatters / test_action_normalization.py: 100%

19 statements  

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

1"""Tests for action parameter normalization in print_tool_result.""" 

2 

3from __future__ import annotations 

4 

5from typing import TYPE_CHECKING, Any 

6 

7import pytest 

8from assertpy import assert_that 

9 

10from lintro.enums.action import Action 

11from lintro.utils.result_formatters import print_tool_result 

12 

13if TYPE_CHECKING: 

14 from collections.abc import Callable 

15 

16 

17@pytest.mark.parametrize( 

18 ("action_value", "expected_behavior"), 

19 [ 

20 ("check", "success message for no issues"), 

21 (Action.CHECK, "success message for no issues"), 

22 ], 

23 ids=["string_check", "enum_check"], 

24) 

25def test_action_normalization_check( 

26 console_capture_with_kwargs: tuple[ 

27 Callable[..., None], 

28 list[tuple[str, dict[str, Any]]], 

29 ], 

30 success_capture: tuple[Callable[[str], None], list[str]], 

31 action_value: str | Action, 

32 expected_behavior: str, 

33) -> None: 

34 """Verify action parameter accepts both string and enum values. 

35 

36 Args: 

37 console_capture_with_kwargs: Mock console output capture with kwargs. 

38 success_capture: Mock success message capture. 

39 action_value: Action value to test. 

40 expected_behavior: Expected behavior description. 

41 """ 

42 mock_console, _ = console_capture_with_kwargs 

43 mock_success, success_calls = success_capture 

44 

45 print_tool_result( 

46 console_output_func=mock_console, 

47 success_func=mock_success, 

48 tool_name="ruff", 

49 output="", 

50 issues_count=0, 

51 action=action_value, 

52 ) 

53 

54 assert_that(success_calls).described_as( 

55 f"Expected {expected_behavior}", 

56 ).contains("✓ No issues found.") 

57 

58 

59def test_action_fmt_treated_as_fix( 

60 console_capture_with_kwargs: tuple[ 

61 Callable[..., None], 

62 list[tuple[str, dict[str, Any]]], 

63 ], 

64 success_capture: tuple[Callable[[str], None], list[str]], 

65) -> None: 

66 """Verify 'fmt' string action is treated as fix action. 

67 

68 Args: 

69 console_capture_with_kwargs: Mock console output capture with kwargs. 

70 success_capture: Mock success message capture. 

71 """ 

72 mock_console, console_output = console_capture_with_kwargs 

73 mock_success, _ = success_capture 

74 

75 output = "Fixed 2 issue(s)\nFound 0 issue(s) that cannot be auto-fixed" 

76 

77 print_tool_result( 

78 console_output_func=mock_console, 

79 success_func=mock_success, 

80 tool_name="ruff", 

81 output=output, 

82 issues_count=0, 

83 action="fmt", 

84 ) 

85 

86 green_texts = [t for t, kwargs in console_output if kwargs.get("color") == "green"] 

87 assert_that(any("2 fixed" in t for t in green_texts)).is_true()