Coverage for tests / unit / parsers / conftest.py: 56%

16 statements  

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

1"""Shared fixtures for parser unit tests.""" 

2 

3from __future__ import annotations 

4 

5from unittest.mock import Mock 

6 

7import pytest 

8 

9 

10@pytest.fixture 

11def mock_tool_output() -> Mock: 

12 """Provide a mock tool output for parser testing. 

13 

14 Returns: 

15 Mock: Configured mock with sample tool output data. 

16 """ 

17 mock_output = Mock() 

18 mock_output.stdout = "" 

19 mock_output.stderr = "" 

20 mock_output.returncode = 0 

21 return mock_output 

22 

23 

24@pytest.fixture 

25def sample_ruff_json_output() -> str: 

26 """Provide sample JSON output from ruff for testing. 

27 

28 Returns: 

29 str: JSON-formatted string mimicking ruff output. 

30 """ 

31 return """[ 

32 { 

33 "code": "F401", 

34 "message": "Unused import", 

35 "location": {"row": 1, "column": 1}, 

36 "filename": "test.py" 

37 } 

38 ]""" 

39 

40 

41@pytest.fixture 

42def sample_pytest_json_output() -> str: 

43 """Provide sample JSON output from pytest for testing. 

44 

45 Returns: 

46 str: JSON-formatted string mimicking pytest output. 

47 """ 

48 return """{ 

49 "session": { 

50 "tests": 5, 

51 "passed": 3, 

52 "failed": 2, 

53 "errors": 0, 

54 "warnings": 0 

55 }, 

56 "tests": [ 

57 { 

58 "nodeid": "test_example.py::test_pass", 

59 "outcome": "passed", 

60 "duration": 0.01 

61 }, 

62 { 

63 "nodeid": "test_example.py::test_fail", 

64 "outcome": "failed", 

65 "duration": 0.02 

66 } 

67 ] 

68 }"""