fix: resolve CI test failures with proper mock patching
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user