Skip to content

Commit

Permalink
Allow passing kwargs to make_all_devices for dodal modules (again) (#…
Browse files Browse the repository at this point in the history
…330)

Functionality added in
#304 and [being used
in
hyperion](https://github.com/DiamondLightSource/hyperion/blob/92b23dac5efc1aa78910d2f0f4bd28725a9ec836/src/hyperion/utils/context.py#L81)
got removed in
076da45
. It doesn't look like there was a clear reason for this removal of
functionality so I think it should be reinstated.
  • Loading branch information
Tom-Willemsen authored Nov 7, 2023
1 parent db8b681 commit 7994906
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/blueapi/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def plan_2(...) -> MsgGenerator:
def with_device_module(self, module: ModuleType) -> None:
self.with_dodal_module(module)

def with_dodal_module(self, module: ModuleType) -> None:
def with_dodal_module(self, module: ModuleType, **kwargs) -> None:
from dodal.utils import make_all_devices

for device in make_all_devices(module).values():
for device in make_all_devices(module, **kwargs).values():
self.device(device)

def plan(self, plan: PlanGenerator) -> PlanGenerator:
Expand Down
19 changes: 19 additions & 0 deletions tests/core/test_context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import Dict, List, Type, Union
from unittest.mock import patch

import pytest
from bluesky.protocols import Descriptor, Movable, Readable, Reading, SyncOrAsync
Expand Down Expand Up @@ -171,6 +172,24 @@ def test_add_devices_from_module(empty_context: BlueskyContext) -> None:
} == empty_context.devices.keys()


def test_extra_kwargs_in_with_dodal_module_passed_to_make_all_devices(
empty_context: BlueskyContext,
) -> None:
"""
Note that this functionality is currently used by hyperion.
"""
import tests.core.fake_device_module as device_module

with patch("dodal.utils.make_all_devices") as mock_make_all_devices:
empty_context.with_dodal_module(
device_module, some_argument=1, another_argument="two"
)

mock_make_all_devices.assert_called_once_with(
device_module, some_argument=1, another_argument="two"
)


@pytest.mark.parametrize(
"addr", ["sim", "sim_det", "sim.setpoint", ["sim"], ["sim", "setpoint"]]
)
Expand Down

0 comments on commit 7994906

Please sign in to comment.