|
| 1 | +import pytest |
| 2 | +from pytest import CaptureFixture |
| 3 | +from dependency_resolver.core.orchestrator import Orchestrator |
| 4 | + |
| 5 | + |
| 6 | +class TestOrchestrator: |
| 7 | + """Test cases for the Orchestrator class.""" |
| 8 | + |
| 9 | + def test_orchestrator_default_detectors(self) -> None: |
| 10 | + """Test that orchestrator initializes with all detectors by default.""" |
| 11 | + orchestrator = Orchestrator() |
| 12 | + |
| 13 | + # Should have all 6 detectors |
| 14 | + assert len(orchestrator.detectors) == 6 |
| 15 | + |
| 16 | + detector_names = {detector.NAME for detector in orchestrator.detectors} |
| 17 | + expected_names = {"docker-info", "dpkg", "apk", "maven", "pip", "npm"} |
| 18 | + assert detector_names == expected_names |
| 19 | + |
| 20 | + def test_orchestrator_select_valid_detectors(self) -> None: |
| 21 | + """Test selecting valid detectors.""" |
| 22 | + orchestrator = Orchestrator(selected_detectors="pip,dpkg") |
| 23 | + |
| 24 | + # Should have only 2 detectors |
| 25 | + assert len(orchestrator.detectors) == 2 |
| 26 | + |
| 27 | + detector_names = {detector.NAME for detector in orchestrator.detectors} |
| 28 | + expected_names = {"pip", "dpkg"} |
| 29 | + assert detector_names == expected_names |
| 30 | + |
| 31 | + def test_orchestrator_select_single_detector(self) -> None: |
| 32 | + """Test selecting a single detector.""" |
| 33 | + orchestrator = Orchestrator(selected_detectors="npm") |
| 34 | + |
| 35 | + # Should have only 1 detector |
| 36 | + assert len(orchestrator.detectors) == 1 |
| 37 | + assert orchestrator.detectors[0].NAME == "npm" |
| 38 | + |
| 39 | + def test_orchestrator_select_all_detectors(self) -> None: |
| 40 | + """Test selecting all detectors explicitly.""" |
| 41 | + orchestrator = Orchestrator(selected_detectors="pip,npm,dpkg,apk,maven,docker-info") |
| 42 | + |
| 43 | + # Should have all 6 detectors |
| 44 | + assert len(orchestrator.detectors) == 6 |
| 45 | + |
| 46 | + detector_names = {detector.NAME for detector in orchestrator.detectors} |
| 47 | + expected_names = {"docker-info", "dpkg", "apk", "maven", "pip", "npm"} |
| 48 | + assert detector_names == expected_names |
| 49 | + |
| 50 | + def test_orchestrator_invalid_detector_name(self) -> None: |
| 51 | + """Test that invalid detector names raise ValueError.""" |
| 52 | + with pytest.raises(ValueError) as exc_info: |
| 53 | + Orchestrator(selected_detectors="pip,invalid-detector") |
| 54 | + |
| 55 | + error_message = str(exc_info.value) |
| 56 | + assert "Invalid detector names: invalid-detector" in error_message |
| 57 | + assert "Available detectors:" in error_message |
| 58 | + |
| 59 | + def test_orchestrator_multiple_invalid_detector_names(self) -> None: |
| 60 | + """Test that multiple invalid detector names are reported.""" |
| 61 | + with pytest.raises(ValueError) as exc_info: |
| 62 | + Orchestrator(selected_detectors="pip,invalid1,invalid2") |
| 63 | + |
| 64 | + error_message = str(exc_info.value) |
| 65 | + assert "Invalid detector names: invalid1, invalid2" in error_message |
| 66 | + |
| 67 | + def test_orchestrator_whitespace_handling(self) -> None: |
| 68 | + """Test that whitespace in detector names is handled correctly.""" |
| 69 | + orchestrator = Orchestrator(selected_detectors=" pip , dpkg ") |
| 70 | + |
| 71 | + # Should have 2 detectors despite whitespace |
| 72 | + assert len(orchestrator.detectors) == 2 |
| 73 | + |
| 74 | + detector_names = {detector.NAME for detector in orchestrator.detectors} |
| 75 | + expected_names = {"pip", "dpkg"} |
| 76 | + assert detector_names == expected_names |
| 77 | + |
| 78 | + def test_orchestrator_empty_selection(self) -> None: |
| 79 | + """Test that empty string selection uses all detectors.""" |
| 80 | + orchestrator = Orchestrator(selected_detectors="") |
| 81 | + |
| 82 | + # Should have all 6 detectors (empty string is falsy) |
| 83 | + assert len(orchestrator.detectors) == 6 |
| 84 | + |
| 85 | + def test_orchestrator_none_selection(self) -> None: |
| 86 | + """Test that None selection uses all detectors.""" |
| 87 | + orchestrator = Orchestrator(selected_detectors=None) |
| 88 | + |
| 89 | + # Should have all 6 detectors |
| 90 | + assert len(orchestrator.detectors) == 6 |
| 91 | + |
| 92 | + def test_orchestrator_debug_output_for_selected_detectors(self, capsys: CaptureFixture[str]) -> None: |
| 93 | + """Test that debug output shows selected detectors.""" |
| 94 | + Orchestrator(debug=True, selected_detectors="pip,npm") |
| 95 | + |
| 96 | + captured = capsys.readouterr() |
| 97 | + assert "Selected detectors: pip, npm" in captured.out |
0 commit comments