Skip to content

Commit

Permalink
Removed ophyd sim imports, replace with ophyd_async equivalents (requ…
Browse files Browse the repository at this point in the history
…ires make_detector)
  • Loading branch information
Oliver Copping committed Apr 18, 2024
1 parent f574e6b commit f925e6d
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions tests/protocols/test_protocols.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
import tempfile
from pathlib import Path

import mypy.api
import pytest
from ophyd import sim
from bluesky.utils import new_uid

from ophyd_async import protocols as bs_protocols
from ophyd_async.core import (
DeviceCollector,
StaticDirectoryProvider,
set_sim_callback,
set_sim_value,
)
from ophyd_async.core.flyer import HardwareTriggeredFlyable
from ophyd_async.epics.areadetector.drivers import ADBase
from ophyd_async.epics.areadetector.writers import NDFileHDF
from ophyd_async.epics.demo.demo_ad_sim_detector import DemoADSimDetector
from ophyd_async.sim.demo import SimMotor


def test_readable():
assert isinstance(sim.motor1, bs_protocols.AsyncReadable)
assert isinstance(sim.det1, bs_protocols.AsyncReadable)
assert not isinstance(sim.flyer1, bs_protocols.AsyncReadable)
async def make_detector(prefix: str, name: str, tmp_path: Path):
dp = StaticDirectoryProvider(tmp_path, f"test-{new_uid()}")

async with DeviceCollector(sim=True):
drv = ADBase(f"{prefix}DRV:")
hdf = NDFileHDF(f"{prefix}HDF:")
det = DemoADSimDetector(
drv, hdf, dp, config_sigs=[drv.acquire_time, drv.acquire], name=name
)

def test_pausable():
assert isinstance(sim.det1, bs_protocols.AsyncPausable)
def _set_full_file_name(_, val):
set_sim_value(hdf.full_file_name, str(tmp_path / val))

set_sim_callback(hdf.file_name, _set_full_file_name)

return det


async def test_readable():
async with DeviceCollector(sim=True):
det = await make_detector("test", "test det", Path("/tmp"))
assert isinstance(SimMotor, bs_protocols.AsyncReadable)
assert isinstance(det, bs_protocols.AsyncReadable)
assert not isinstance(HardwareTriggeredFlyable, bs_protocols.AsyncReadable)

0 comments on commit f925e6d

Please sign in to comment.