Coverage for tests / unit / utils / output / conftest.py: 100%

33 statements  

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

1"""Shared fixtures and test data for file writer tests. 

2 

3Provides MockIssue and MockToolResult dataclasses along with factories 

4for creating test data across multiple file writer test modules. 

5""" 

6 

7from __future__ import annotations 

8 

9from dataclasses import dataclass, field 

10from typing import TYPE_CHECKING, Any 

11 

12import pytest 

13 

14if TYPE_CHECKING: 

15 from collections.abc import Callable 

16 

17 

18@dataclass 

19class MockIssue: 

20 """Mock issue for testing file writer functionality.""" 

21 

22 file: str = "src/main.py" 

23 line: int = 10 

24 code: str = "E001" 

25 message: str = "Test error" 

26 

27 

28@dataclass 

29class MockToolResult: 

30 """Mock tool result for testing file writer functionality.""" 

31 

32 name: str = "test-tool" 

33 success: bool = True 

34 issues_count: int = 0 

35 output: str = "" 

36 issues: list[MockIssue] = field(default_factory=list) 

37 

38 

39@pytest.fixture 

40def mock_tool_result_factory() -> Callable[..., MockToolResult]: 

41 """Provide a factory for creating MockToolResult instances with custom attributes. 

42 

43 Returns: 

44 Factory function that creates MockToolResult instances. 

45 """ 

46 

47 def _create(**kwargs: Any) -> MockToolResult: 

48 return MockToolResult(**kwargs) 

49 

50 return _create 

51 

52 

53@pytest.fixture 

54def mock_issue_factory() -> Callable[..., MockIssue]: 

55 """Provide a factory for creating MockIssue instances with custom attributes. 

56 

57 Returns: 

58 Factory function that creates MockIssue instances. 

59 """ 

60 

61 def _create(**kwargs: Any) -> MockIssue: 

62 return MockIssue(**kwargs) 

63 

64 return _create 

65 

66 

67@pytest.fixture 

68def sample_results_with_issues( 

69 mock_tool_result_factory: Callable[..., MockToolResult], 

70 mock_issue_factory: Callable[..., MockIssue], 

71) -> list[MockToolResult]: 

72 """Provide sample tool results with issues for testing output formats. 

73 

74 Args: 

75 mock_tool_result_factory: Factory for creating mock tool results. 

76 mock_issue_factory: Factory for creating mock issues. 

77 

78 Returns: 

79 List containing a single MockToolResult with one issue. 

80 """ 

81 return [ 

82 mock_tool_result_factory( 

83 name="ruff", 

84 issues_count=1, 

85 issues=[mock_issue_factory()], 

86 ), 

87 ] 

88 

89 

90@pytest.fixture 

91def sample_results_empty( 

92 mock_tool_result_factory: Callable[..., MockToolResult], 

93) -> list[MockToolResult]: 

94 """Provide sample tool results with no issues for testing output formats. 

95 

96 Args: 

97 mock_tool_result_factory: Factory for creating mock tool results. 

98 

99 Returns: 

100 List containing a single MockToolResult with zero issues. 

101 """ 

102 return [mock_tool_result_factory(name="ruff", issues_count=0)]