Coverage for tests / unit / cli / conftest.py: 66%
38 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Shared fixtures for CLI tests."""
3from __future__ import annotations
5from collections.abc import Generator
6from typing import TYPE_CHECKING
7from unittest.mock import MagicMock, patch
9import pytest
10from click.testing import CliRunner
12from tests.constants import EXIT_SUCCESS
14if TYPE_CHECKING:
15 pass
18@pytest.fixture
19def isolated_cli_runner() -> CliRunner:
20 """Click CLI test runner with isolated filesystem.
22 Returns:
23 A CliRunner instance with isolated filesystem.
24 """
25 return CliRunner(mix_stderr=False)
28@pytest.fixture
29def mock_run_lint_tools_simple() -> Generator[tuple[MagicMock, MagicMock], None, None]:
30 """Mock the run_lint_tools_simple function used by check/format commands.
32 Yields:
33 tuple[MagicMock, MagicMock]: Check and format mock instances.
34 """
35 with (
36 patch("lintro.cli_utils.commands.check.run_lint_tools_simple") as mock_check,
37 patch(
38 "lintro.cli_utils.commands.format.run_lint_tools_simple",
39 ) as mock_format,
40 ):
41 # Configure both mocks to return 0 by default
42 mock_check.return_value = EXIT_SUCCESS
43 mock_format.return_value = EXIT_SUCCESS
44 yield mock_check, mock_format
47@pytest.fixture
48def mock_run_lint_tools_check() -> Generator[MagicMock, None, None]:
49 """Mock run_lint_tools_simple specifically for check command.
51 Yields:
52 MagicMock: A MagicMock instance for the mocked check function.
53 """
54 with patch("lintro.cli_utils.commands.check.run_lint_tools_simple") as mock:
55 mock.return_value = EXIT_SUCCESS
56 yield mock
59@pytest.fixture
60def mock_run_lint_tools_format() -> Generator[MagicMock, None, None]:
61 """Mock run_lint_tools_simple specifically for format command.
63 Yields:
64 MagicMock: A MagicMock instance for the mocked format function.
65 """
66 with patch("lintro.cli_utils.commands.format.run_lint_tools_simple") as mock:
67 mock.return_value = EXIT_SUCCESS
68 yield mock
71@pytest.fixture
72def mock_tool_registry() -> Generator[MagicMock, None, None]:
73 """Mock ToolRegistry with common tools.
75 Yields:
76 MagicMock: A MagicMock instance for the ToolRegistry.
77 """
78 with patch("lintro.plugins.registry.ToolRegistry") as mock:
79 mock.get_names.return_value = ["ruff", "black", "mypy", "pytest"]
80 mock.is_registered.return_value = True
81 mock.get.return_value = MagicMock()
82 yield mock
85@pytest.fixture
86def mock_subprocess_success() -> Generator[MagicMock, None, None]:
87 """Mock successful subprocess execution.
89 Yields:
90 MagicMock: A MagicMock instance for subprocess.run.
91 """
92 with patch("subprocess.run") as mock:
93 mock.return_value = MagicMock(
94 returncode=EXIT_SUCCESS,
95 stdout="",
96 stderr="",
97 )
98 yield mock