fix: resolve CI test failures with proper mock patching
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-01-30 15:57:24 +00:00
parent 0801432a2c
commit e0601734f1

View File

@@ -120,20 +120,21 @@ class TestCLI:
assert result.exit_code == 0
assert 'No project type detected' in result.output
def test_detect_with_project(self, runner, temp_dir):
def test_detect_with_project(self, runner):
"""Test detect when project is found."""
with patch('gitignore_generator.detector.ProjectDetector') as mock_detector:
mock_instance = MagicMock()
mock_instance.detect.return_value = ['python']
mock_instance.suggest_gitignore.return_value = ['python']
mock_instance.get_detection_details.return_value = [
{'technology': 'python', 'matched_files': ['requirements.txt'], 'confidence': 1}
]
mock_detector.return_value = mock_instance
from gitignore_generator import cli
with runner.isolated_filesystem():
with patch.object(cli, 'ProjectDetector') as mock_detector:
mock_instance = MagicMock()
mock_instance.detect.return_value = ['python']
mock_instance.suggest_gitignore.return_value = ['python']
mock_instance.get_detection_details.return_value = [
{'technology': 'python', 'matched_files': ['requirements.txt'], 'confidence': 1}
]
mock_detector.return_value = mock_instance
with patch('gitignore_generator.api.get_patterns') as mock_patterns:
mock_patterns.return_value = '__pycache__/\n'
with runner.isolated_filesystem():
with patch('gitignore_generator.api.get_patterns') as mock_patterns:
mock_patterns.return_value = 'content'
result = runner.invoke(detect, ['--preview'])
assert result.exit_code == 0