-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rose Yemelyanova
committed
Oct 23, 2023
1 parent
7d478b0
commit 615f9ef
Showing
3 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import asyncio | ||
|
||
import pytest | ||
from bluesky.run_engine import RunEngine, TransitionError | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def RE(request): | ||
loop = asyncio.new_event_loop() | ||
loop.set_debug(True) | ||
RE = RunEngine({}, call_returns_result=True, loop=loop) | ||
|
||
def clean_event_loop(): | ||
if RE.state not in ("idle", "panicked"): | ||
try: | ||
RE.halt() | ||
except TransitionError: | ||
pass | ||
loop.call_soon_threadsafe(loop.stop) | ||
RE._th.join() | ||
loop.close() | ||
|
||
request.addfinalizer(clean_event_loop) | ||
return RE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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 |