Skip to content

Commit

Permalink
Update for wrapped count plan
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondJoseph committed Sep 18, 2024
1 parent 5fc475f commit 7395e95
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 32 deletions.
4 changes: 3 additions & 1 deletion src/blueapi/startup/example_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def _scanspec_to_cycler(spec: Spec[str], axes: Mapping[str, Movable]) -> Cycler:
@validate_call(config={"arbitrary_types_allowed": True})
def count(
detectors: Annotated[
set[Readable], "Set of readable devices, will take a reading at each point"
set[Readable],
"Set of readable devices, will take a reading at each point",
Field(min_items=1),
],
num: Annotated[int, "Number of frames to collect", Field(ge=1)] = 1,
delay: Annotated[
Expand Down
14 changes: 14 additions & 0 deletions tests/unit_tests/worker/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pathlib import Path
from unittest.mock import AsyncMock, MagicMock

import pytest
from ophyd_async.core import PathInfo


@pytest.fixture
def updating_path_provider(tmp_path: Path):
updating_mock_path_provider = MagicMock()
updating_mock_path_provider.data_session = AsyncMock(return_value="bar")
updating_mock_path_provider.update = AsyncMock()
updating_mock_path_provider.return_value = PathInfo(tmp_path, "foo", 0)
return updating_mock_path_provider
70 changes: 39 additions & 31 deletions tests/unit_tests/worker/test_task_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import threading
from collections.abc import Callable, Iterable
from concurrent.futures import Future
from pathlib import Path
from queue import Full
from typing import Any, TypeVar
from unittest.mock import MagicMock, patch

import pytest
from dodal.common import MsgGenerator
from dodal.common.types import UpdatingPathProvider

from blueapi.config import EnvironmentConfig, Source, SourceKind
from blueapi.core import BlueskyContext, EventStream
Expand Down Expand Up @@ -308,40 +310,46 @@ def begin_task_and_wait_until_complete(
#


def test_worker_and_data_events_produce_in_order(worker: TaskWorker) -> None:
assert_running_count_plan_produces_ordered_worker_and_data_events(
[
WorkerEvent(
state=WorkerState.RUNNING,
task_status=TaskStatus(
task_id="count", task_complete=False, task_failed=False
def test_worker_and_data_events_produce_in_order(
updating_path_provider: UpdatingPathProvider, tmp_path: Path, worker: TaskWorker
) -> None:
with patch(
"dodal.common.beamlines.beamline_utils.get_path_provider",
return_value=updating_path_provider,
):
assert_running_count_plan_produces_ordered_worker_and_data_events(
[
WorkerEvent(
state=WorkerState.RUNNING,
task_status=TaskStatus(
task_id="count", task_complete=False, task_failed=False
),
errors=[],
warnings=[],
),
errors=[],
warnings=[],
),
DataEvent(name="start", doc={}),
DataEvent(name="descriptor", doc={}),
DataEvent(name="event", doc={}),
DataEvent(name="stop", doc={}),
WorkerEvent(
state=WorkerState.IDLE,
task_status=TaskStatus(
task_id="count", task_complete=False, task_failed=False
DataEvent(name="start", doc={}),
DataEvent(name="descriptor", doc={}),
DataEvent(name="event", doc={}),
DataEvent(name="stop", doc={}),
WorkerEvent(
state=WorkerState.IDLE,
task_status=TaskStatus(
task_id="count", task_complete=False, task_failed=False
),
errors=[],
warnings=[],
),
errors=[],
warnings=[],
),
WorkerEvent(
state=WorkerState.IDLE,
task_status=TaskStatus(
task_id="count", task_complete=True, task_failed=False
WorkerEvent(
state=WorkerState.IDLE,
task_status=TaskStatus(
task_id="count", task_complete=True, task_failed=False
),
errors=[],
warnings=[],
),
errors=[],
warnings=[],
),
],
worker,
)
],
worker,
)


def assert_running_count_plan_produces_ordered_worker_and_data_events(
Expand Down

0 comments on commit 7395e95

Please sign in to comment.