|
20 | 20 | from dodal.common import PlanGenerator, inject |
21 | 21 | from ophyd import Device |
22 | 22 | from ophyd_async.core import ( |
| 23 | + NotConnectedError, |
23 | 24 | PathProvider, |
24 | 25 | StandardDetector, |
25 | 26 | StaticPathProvider, |
@@ -153,6 +154,20 @@ def devicey_context(sim_motor: Motor, sim_detector: StandardDetector) -> Bluesky |
153 | 154 | return ctx |
154 | 155 |
|
155 | 156 |
|
| 157 | +@pytest.fixture |
| 158 | +def beamline_with_connection_and_build_errors(): |
| 159 | + stm = StaticDeviceManager( |
| 160 | + devices={}, |
| 161 | + build_errors={"foo": RuntimeError("Simulated Build Error")}, |
| 162 | + connection_errors={"bar": NotConnectedError("Simulated Connection Error")}, |
| 163 | + ) |
| 164 | + dev_mod = Mock(spec=ModuleType) |
| 165 | + dev_mod.devices = stm |
| 166 | + with patch("blueapi.core.context.import_module") as imp_mod: |
| 167 | + imp_mod.side_effect = lambda mod: dev_mod if mod == "foo.bar" else None |
| 168 | + yield |
| 169 | + |
| 170 | + |
156 | 171 | class SomeConfigurable: |
157 | 172 | def read_configuration(self) -> SyncOrAsync[dict[str, Reading]]: |
158 | 173 | return {} |
@@ -425,6 +440,28 @@ def test_with_config_passes_mock_to_with_dodal_module( |
425 | 440 | mock_with_dodal_module.assert_called_once_with(ANY, mock=mock) |
426 | 441 |
|
427 | 442 |
|
| 443 | +def test_with_config_raises_exception_group_on_connection_errors_when_ensure_connected( |
| 444 | + empty_context: BlueskyContext, beamline_with_connection_and_build_errors: None |
| 445 | +): |
| 446 | + with pytest.raises(ExceptionGroup, match="Errors occurred while connecting.*") as e: |
| 447 | + empty_context.with_config( |
| 448 | + EnvironmentConfig( |
| 449 | + sources=[DeviceManagerSource(module="foo.bar", ensure_connected=True)] |
| 450 | + ) |
| 451 | + ) |
| 452 | + |
| 453 | + assert e.value.exceptions[0].args[0] == "Simulated Build Error" |
| 454 | + assert e.value.exceptions[1].args[0] == "Simulated Connection Error" |
| 455 | + |
| 456 | + |
| 457 | +def test_with_config_ignores_build_connect_exceptions_by_default( |
| 458 | + empty_context: BlueskyContext, beamline_with_connection_and_build_errors: None |
| 459 | +): |
| 460 | + empty_context.with_config( |
| 461 | + EnvironmentConfig(sources=[DeviceManagerSource(module="foo.bar")]) |
| 462 | + ) |
| 463 | + |
| 464 | + |
428 | 465 | def test_function_spec(empty_context: BlueskyContext): |
429 | 466 | spec = empty_context._type_spec_for_function(has_some_params) |
430 | 467 | assert spec["foo"][0] is int |
|
0 commit comments