|
20 | 20 | _wait_for_dependencies, |
21 | 21 | get_unload_order, |
22 | 22 | reload_domain, |
| 23 | + setup_domains, |
23 | 24 | unload_domain, |
24 | 25 | ) |
25 | 26 | from viseron.exceptions import DomainNotReady |
@@ -1142,3 +1143,64 @@ def test_schedule_domain_setup_schedules_dependencies_first( |
1142 | 1143 |
|
1143 | 1144 | det_future.result() |
1144 | 1145 | cam_future.result() |
| 1146 | + |
| 1147 | + |
| 1148 | +class TestSetupDomains: |
| 1149 | + """Test setup_domains function.""" |
| 1150 | + |
| 1151 | + def test_setup_domains_validates_missing_dependencies( |
| 1152 | + self, vis: MockViseron, caplog: pytest.LogCaptureFixture |
| 1153 | + ) -> None: |
| 1154 | + """Test setup_domains validates and fails domains with missing deps.""" |
| 1155 | + vis.domain_registry.register( |
| 1156 | + component_name="test_comp", |
| 1157 | + component_path="test.path", |
| 1158 | + domain="camera", |
| 1159 | + identifier="cam1", |
| 1160 | + config={}, |
| 1161 | + require_domains=[ |
| 1162 | + RequireDomain( |
| 1163 | + "missing_domain", # type: ignore[arg-type] |
| 1164 | + "missing_id", |
| 1165 | + ), |
| 1166 | + ], |
| 1167 | + ) |
| 1168 | + entry = vis.domain_registry.get("camera", "cam1") |
| 1169 | + assert entry is not None |
| 1170 | + |
| 1171 | + setup_domains(vis) |
| 1172 | + |
| 1173 | + assert entry.state == DomainState.FAILED |
| 1174 | + assert "has missing dependencies" in caplog.text |
| 1175 | + |
| 1176 | + def test_setup_domains_no_pending_returns_early( |
| 1177 | + self, vis: MockViseron, caplog: pytest.LogCaptureFixture |
| 1178 | + ) -> None: |
| 1179 | + """Test setup_domains returns early when no pending domains.""" |
| 1180 | + setup_domains(vis) |
| 1181 | + assert "Setting up" not in caplog.text |
| 1182 | + |
| 1183 | + def test_setup_domains_clears_futures_after_completion( |
| 1184 | + self, vis: MockViseron |
| 1185 | + ) -> None: |
| 1186 | + """Test setup_domains clears futures after all complete.""" |
| 1187 | + mock_domain = MockDomainModule(setup_return=True) |
| 1188 | + |
| 1189 | + vis.domain_registry.register( |
| 1190 | + component_name="test_comp", |
| 1191 | + component_path="test.path", |
| 1192 | + domain="camera", |
| 1193 | + identifier="cam1", |
| 1194 | + config={}, |
| 1195 | + ) |
| 1196 | + entry = vis.domain_registry.get("camera", "cam1") |
| 1197 | + assert entry is not None |
| 1198 | + |
| 1199 | + with patch( |
| 1200 | + "viseron.components.importlib.import_module", return_value=mock_domain |
| 1201 | + ): |
| 1202 | + setup_domains(vis) |
| 1203 | + |
| 1204 | + future = vis.domain_registry.get_future("camera", "cam1") |
| 1205 | + assert future is None |
| 1206 | + assert entry.state == DomainState.LOADED |
0 commit comments