Skip to content

Commit 75512c5

Browse files
committed
Updated test_plans
1 parent 16c238b commit 75512c5

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

src/blop/plans.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import functools
22
import warnings
33
from collections.abc import Callable, Generator, Mapping, Sequence
4-
from typing import Any, cast
4+
from typing import Any, TypeVar, cast
55

66
import bluesky.plan_stubs as bps
77
import bluesky.plans as bp
8-
from ax.api.types import TParameterization
98
from bluesky.protocols import Movable, NamedMovable, Readable, Reading
109
from bluesky.utils import Msg, MsgGenerator, plan
1110
from ophyd import Signal # type: ignore[import-untyped]
1211

1312
from .dofs import DOF
1413
from .protocols import OptimizationProblem
1514

15+
_NamedMovableT = TypeVar("_NamedMovableT", bound=NamedMovable)
1616

17-
def _unpack_for_list_scan(movables: Mapping[NamedMovable, Sequence[Any]]) -> list[NamedMovable | Any]:
17+
18+
def _unpack_for_list_scan(movables: Mapping[_NamedMovableT, Sequence[Any]]) -> list[_NamedMovableT | Any]:
1819
"""Unpack the movables and inputs into Bluesky list_scan plan arguments."""
1920
unpacked_list = []
2021
for movable, values in movables.items():
@@ -26,7 +27,7 @@ def _unpack_for_list_scan(movables: Mapping[NamedMovable, Sequence[Any]]) -> lis
2627

2728
@plan
2829
def default_acquire(
29-
movables: Mapping[NamedMovable, Sequence[Any]],
30+
movables: Mapping[_NamedMovableT, Sequence[Any]],
3031
readables: Sequence[Readable] | None = None,
3132
*,
3233
per_step: bp.PerStep | None = None,
@@ -37,12 +38,10 @@ def default_acquire(
3738
3839
Parameters
3940
----------
40-
movables: Mapping[NamedMovable, Sequence[Any]]
41+
movables: Mapping[_NamedMovableT, Sequence[Any]]
4142
The movables to move and the inputs to move them to.
4243
readables: Sequence[Readable]
4344
The readables to trigger and read.
44-
trials: dict[int, TParameterization]
45-
A dictionary mapping trial indices to their suggested parameterizations. Typically only a single trial is provided.
4645
per_step: bp.PerStep | None = None
4746
The plan to execute for each step of the scan.
4847
**kwargs: Any
@@ -310,7 +309,7 @@ def per_step_background_read(
310309

311310
@plan
312311
def acquire_with_background(
313-
movables: Mapping[NamedMovable, Sequence[Any]],
312+
movables: Mapping[_NamedMovableT, Sequence[Any]],
314313
readables: Sequence[Readable] | None = None,
315314
*,
316315
block_beam: Callable[[], MsgGenerator[None]],
@@ -322,7 +321,7 @@ def acquire_with_background(
322321
323322
Parameters
324323
----------
325-
movables: Mapping[NamedMovable, Sequence[Any]]
324+
movables: Mapping[_NamedMovableT, Sequence[Any]]
326325
The movables and the inputs to move them to.
327326
readables: Sequence[Readable] | None = None
328327
The readables that produce data to evaluate.

src/blop/tests/unit/test_plans.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from bluesky.run_engine import RunEngine
66

77
from blop.dofs import DOF
8-
from blop.plans import acquire, acquire_with_background
8+
from blop.plans import acquire_with_background, default_acquire
99

1010
from .conftest import MovableSignal, ReadableSignal
1111

@@ -15,20 +15,20 @@ def RE():
1515
return RunEngine({})
1616

1717

18-
def test_acquire_single_dof(RE):
19-
dof = DOF(movable=MovableSignal("x1", initial_value=-1.0), search_domain=(-5.0, 5.0))
18+
def test_default_acquire_single_movable_readable(RE):
19+
movable = MovableSignal("x1", initial_value=-1.0)
2020
readable = ReadableSignal("objective")
21+
movable_and_input = {movable: [0.0]}
2122
with patch.object(readable, "read", wraps=readable.read) as mock_read:
2223
RE(
23-
acquire(
24-
readables=[readable],
25-
dofs={"x1": dof},
26-
trials={0: {"x1": 0.0}},
24+
default_acquire(
25+
movable_and_input,
26+
[readable],
2727
)
2828
)
2929
assert mock_read.call_count == 1
3030

31-
assert dof.movable.read()["x1"]["value"] == 0.0
31+
assert movable.read()["x1"]["value"] == 0.0
3232

3333

3434
def test_acquire_with_background(RE):
@@ -38,18 +38,17 @@ def block_beam():
3838
def unblock_beam():
3939
yield from bps.null()
4040

41-
dof = DOF(movable=MovableSignal("x1", initial_value=-1.0), search_domain=(-5.0, 5.0))
41+
movable = MovableSignal("x1", initial_value=-1.0)
4242
readable = ReadableSignal("objective")
43-
43+
movable_and_input = {movable: [0.0]}
4444
with patch.object(readable, "read", wraps=readable.read) as mock_read:
4545
RE(
4646
acquire_with_background(
47+
movables=movable_and_input,
4748
readables=[readable],
48-
dofs={"x1": dof},
49-
trials={0: {"x1": 0.0}},
5049
block_beam=block_beam,
5150
unblock_beam=unblock_beam,
5251
)
5352
)
5453
assert mock_read.call_count == 2
55-
assert dof.movable.read()["x1"]["value"] == 0.0
54+
assert movable.read()["x1"]["value"] == 0.0

0 commit comments

Comments
 (0)