Skip to content

Commit

Permalink
feat: accept bare string for mda event channel (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 authored Aug 13, 2023
1 parent 74f2690 commit 7652953
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/useq/_mda_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Tuple,
)

from pydantic import Field
from pydantic_compat import Field, field_validator

from useq._actions import AcquireImage, AnyAction
from useq._base_model import UseqModel
Expand Down Expand Up @@ -158,6 +158,10 @@ def global_index(self) -> int:
)
return 0

@field_validator("channel", mode="before")
def _validate_channel(cls, val: Any) -> Any:
return Channel(config=val) if isinstance(val, str) else val

def to_pycromanager(self) -> "PycroManagerEvent":
from useq.pycromanager import to_pycromanager

Expand Down
4 changes: 4 additions & 0 deletions tests/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,7 @@ def test_z_plan_num_position():
plan = ZRangeAround(range=(i - 1) / 10, step=0.1)
assert plan.num_positions() == i
assert len(list(plan)) == i


def test_channel_str():
assert MDAEvent(channel="DAPI") == MDAEvent(channel={"config": "DAPI"})

0 comments on commit 7652953

Please sign in to comment.