From b78e663b23b56af50f22d3fa039e7f6d6c78e097 Mon Sep 17 00:00:00 2001 From: Keith Ralphs Date: Tue, 9 Jul 2024 15:18:47 +0000 Subject: [PATCH] Remove flyables.py as now handles by ophyd-async --- src/dls_bluesky_core/stubs/flyables.py | 60 -------------------------- tests/stubs/test_flyables.py | 54 ----------------------- tests/test_boilerplate_removed.py | 1 + 3 files changed, 1 insertion(+), 114 deletions(-) delete mode 100644 src/dls_bluesky_core/stubs/flyables.py delete mode 100644 tests/stubs/test_flyables.py diff --git a/src/dls_bluesky_core/stubs/flyables.py b/src/dls_bluesky_core/stubs/flyables.py deleted file mode 100644 index 41acacb..0000000 --- a/src/dls_bluesky_core/stubs/flyables.py +++ /dev/null @@ -1,60 +0,0 @@ -import bluesky.plan_stubs as bps -from bluesky.protocols import Flyable - -from dls_bluesky_core.core import MsgGenerator, group_uuid - - -def fly_and_collect( - flyer: Flyable, - flush_period: float = 0.5, - checkpoint_every_collect: bool = False, - stream_name: str = "primary", -) -> MsgGenerator: - """Fly and collect a flyer, waiting for collect to finish with a period. - - flyer.kickoff and complete are called, which starts the fly scanning process. - bps.wait is called, which finishes after each flush period and then repeats, until - complete finishes. At this point, bps.collect is called to gather the documents - produced. - - For some flyers, this plan will need to be called in succession in order to, for - example, set up a flyer to send triggers multiple times and collect data. For such - a use case, this plan can be setup to checkpoint for each collect. - - Note: this plan must be wrapped with calls to open and close run, and the flyer - must implement the Collectable protocol. See tests/stubs/test_flyables for an - example. - - Args: - flyer (Flyable, Collectable): ophyd-async device which implements Flyable and - Collectable. - flush_period (float): How often to check if flyer.complete has finished. - Defaults to 0.5 - checkpoint_every_collect (bool): whether or not to checkpoint after - flyer.collect has been called. Defaults to - False. - stream_name (str): name of the stream to collect from. Defaults to "primary". - - - Returns: - MsgGenerator: Plan - - Yields: - Iterator[MsgGenerator]: Bluesky messages - """ - yield from bps.kickoff(flyer) - complete_group = group_uuid("complete") - yield from bps.complete(flyer, group=complete_group) - done = False - while not done: - try: - yield from bps.wait(group=complete_group, timeout=flush_period) - except TimeoutError: - pass - else: - done = True - yield from bps.collect( - flyer, stream=True, return_payload=False, name=stream_name - ) - if checkpoint_every_collect: - yield from bps.checkpoint() diff --git a/tests/stubs/test_flyables.py b/tests/stubs/test_flyables.py deleted file mode 100644 index 366b2a0..0000000 --- a/tests/stubs/test_flyables.py +++ /dev/null @@ -1,54 +0,0 @@ -import asyncio -from typing import Dict - -import bluesky.plan_stubs as bps -import pytest -from bluesky.protocols import Collectable, Descriptor, Flyable -from ophyd_async.core import AsyncStatus - -from dls_bluesky_core.stubs.flyables import fly_and_collect - - -class DummyFlyer(Flyable, Collectable): - def __init__(self, name: str) -> None: - self._name = name - self.has_flown = False - - @property - def name(self) -> str: - return self._name - - @AsyncStatus.wrap - async def kickoff(self) -> None: - self._fly_status = AsyncStatus(self._fly()) - - async def _fly(self) -> None: - self.has_flown = True - await asyncio.sleep(0.1) - - def complete(self) -> AsyncStatus: - return self._fly_status - - def describe_collect(self) -> Dict[str, Descriptor]: - return { - self.name: Descriptor( - source="some:source", shape=[], dtype="array", external="STREAM:" - ) - } - - -@pytest.fixture -def flyer() -> Flyable: - return DummyFlyer("test") - - -async def test_fly_and_collect(RE, flyer: DummyFlyer): - def open_and_close_run_for_fly_and_collect(): - yield from bps.open_run() - yield from fly_and_collect( - flyer, flush_period=0.01, checkpoint_every_collect=True - ) - yield from bps.close_run() - - RE(open_and_close_run_for_fly_and_collect()) - assert flyer.has_flown is True diff --git a/tests/test_boilerplate_removed.py b/tests/test_boilerplate_removed.py index b7632d0..ff71e40 100644 --- a/tests/test_boilerplate_removed.py +++ b/tests/test_boilerplate_removed.py @@ -2,6 +2,7 @@ This file checks that all the example boilerplate text has been removed. It can be deleted when all the contained tests pass """ + import sys from pathlib import Path