|
17 | 17 | MissingInstrumentSessionError, |
18 | 18 | Plan, |
19 | 19 | PlanCache, |
| 20 | + PlanFailedError, |
20 | 21 | ) |
21 | 22 | from blueapi.client.event_bus import AnyEvent, EventBusClient |
22 | 23 | from blueapi.client.rest import BlueapiRestClient, BlueskyRemoteControlError |
@@ -512,6 +513,39 @@ def callback(on_event: Callable[[AnyEvent, MessageContext], None]): |
512 | 513 | mock_on_event.assert_called_once_with(COMPLETE_EVENT) |
513 | 514 |
|
514 | 515 |
|
| 516 | +def test_scripting_interface_returns_result(): |
| 517 | + client = Mock(spec=BlueapiClient, instrument_session="cm12345-1") |
| 518 | + client.run_task.return_value = TaskStatus( |
| 519 | + task_id="foobar", |
| 520 | + task_complete=True, |
| 521 | + task_failed=False, |
| 522 | + result=TaskResult(result=42, type="int"), |
| 523 | + ) |
| 524 | + demo_plan = Plan( |
| 525 | + "demo", |
| 526 | + client=client, |
| 527 | + model=PlanModel(name="demo", description="Demo plan", schema={}), |
| 528 | + ) |
| 529 | + assert demo_plan() == 42 |
| 530 | + |
| 531 | + |
| 532 | +def test_scripting_interface_raises_exceptions(): |
| 533 | + client = Mock(spec=BlueapiClient, instrument_session="cm12345-1") |
| 534 | + client.run_task.return_value = TaskStatus( |
| 535 | + task_id="foobar", |
| 536 | + task_complete=True, |
| 537 | + task_failed=True, |
| 538 | + result=TaskError(type="ValueError", message="Plan failed"), |
| 539 | + ) |
| 540 | + demo_plan = Plan( |
| 541 | + "demo", |
| 542 | + client=client, |
| 543 | + model=PlanModel(name="demo", description="Demo plan", schema={}), |
| 544 | + ) |
| 545 | + with pytest.raises(PlanFailedError, match="Plan failed"): |
| 546 | + demo_plan() |
| 547 | + |
| 548 | + |
515 | 549 | def test_oidc_config_property(client, mock_rest): |
516 | 550 | assert client.oidc_config == mock_rest.get_oidc_config() |
517 | 551 |
|
|
0 commit comments