Skip to content

Commit b2eaebd

Browse files
feat: add load panda from yaml and test for the same (#1705)
1 parent c719bfc commit b2eaebd

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/dodal/plans/load_panda_yaml.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ophyd_async.core import YamlSettingsProvider
2+
from ophyd_async.fastcs.panda import HDFPanda
3+
from ophyd_async.plan_stubs import apply_panda_settings, retrieve_settings
4+
5+
6+
def load_panda_from_yaml(yaml_directory: str, yaml_file_name: str, panda: HDFPanda):
7+
provider = YamlSettingsProvider(yaml_directory)
8+
settings = yield from retrieve_settings(provider, yaml_file_name, panda)
9+
yield from apply_panda_settings(settings)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from unittest.mock import MagicMock, patch
2+
3+
import pytest
4+
from bluesky.plan_stubs import null
5+
from bluesky.run_engine import RunEngine
6+
from ophyd_async.fastcs.panda import HDFPanda
7+
8+
from dodal.plans.load_panda_yaml import load_panda_from_yaml
9+
10+
11+
@pytest.fixture
12+
def panda():
13+
return HDFPanda
14+
15+
16+
def get_test_plan(*args):
17+
yield from null()
18+
return "retrieved_settings"
19+
20+
21+
@patch("dodal.plans.load_panda_yaml.YamlSettingsProvider")
22+
@patch("dodal.plans.load_panda_yaml.retrieve_settings")
23+
@patch("dodal.plans.load_panda_yaml.apply_panda_settings")
24+
def test_load_panda_from_yaml(
25+
mock_apply_panda_settings: MagicMock,
26+
mock_retrieve_settings: MagicMock,
27+
mock_settings_provider: MagicMock,
28+
panda: HDFPanda,
29+
tmpdir,
30+
run_engine: RunEngine,
31+
):
32+
test_file = "test"
33+
mock_settings_provider.return_value = (mock_settings_return := MagicMock())
34+
mock_retrieve_settings.side_effect = get_test_plan
35+
36+
run_engine(
37+
load_panda_from_yaml(
38+
tmpdir,
39+
test_file,
40+
panda,
41+
)
42+
)
43+
44+
mock_settings_provider.assert_called_once_with(tmpdir)
45+
mock_retrieve_settings.assert_called_once_with(
46+
mock_settings_return, test_file, panda
47+
)
48+
mock_apply_panda_settings.assert_called_once_with("retrieved_settings")

0 commit comments

Comments
 (0)