Skip to content

Commit

Permalink
Move make_detector to conftest.py and make it a fixture (#716)
Browse files Browse the repository at this point in the history
* Move make_detector to conftest.py and make it a fixture

* Ruff linter

* More ruff fixes
  • Loading branch information
thomashopkins32 authored Jan 6, 2025
1 parent c781e27 commit 07dd570
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import pytest
from bluesky.run_engine import RunEngine, TransitionError
from bluesky.utils import new_uid
from pytest import FixtureRequest

from ophyd_async.core import (
Expand All @@ -18,7 +19,9 @@
StaticFilenameProvider,
StaticPathProvider,
TriggerInfo,
init_devices,
)
from ophyd_async.epics import adsimdetector

PANDA_RECORD = str(Path(__file__).parent / "fastcs" / "panda" / "db" / "panda.db")
INCOMPLETE_BLOCK_RECORD = str(
Expand Down Expand Up @@ -246,6 +249,32 @@ def one_shot_trigger_info() -> TriggerInfo:
)


@pytest.fixture
async def sim_detector(request: FixtureRequest):
"""Fixture that creates a simulated detector.
Args:
prefix (str): The PV prefix for the detector
name (str): Name for the detector instance
tmp_path (Path): Temporary directory for file writing
"""
prefix = (
request.param[0] if isinstance(request.param, list | tuple) else request.param
)
name = request.param[1] if isinstance(request.param, list | tuple) else "test"
tmp_path = request.getfixturevalue("tmp_path")

fp = StaticFilenameProvider(f"test-{new_uid()}")
dp = StaticPathProvider(fp, tmp_path)

async with init_devices(mock=True):
det = adsimdetector.SimDetector(prefix, dp, name=name)

det._config_sigs = [det.drv.acquire_time, det.drv.acquire]

return det


def pytest_collection_modifyitems(config, items):
tango_dir = "tests/tango"

Expand Down
27 changes: 6 additions & 21 deletions tests/core/test_protocol.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
from pathlib import Path

from bluesky.utils import new_uid
import pytest

from ophyd_async.core import (
AsyncReadable,
StandardFlyer,
StaticFilenameProvider,
StaticPathProvider,
init_devices,
)
from ophyd_async.epics import adsimdetector
from ophyd_async.sim import SimMotor


async def make_detector(prefix: str, name: str, tmp_path: Path):
fp = StaticFilenameProvider(f"test-{new_uid()}")
dp = StaticPathProvider(fp, tmp_path)

async with init_devices(mock=True):
det = adsimdetector.SimDetector(prefix, dp, name=name)

det._config_sigs = [det.drv.acquire_time, det.drv.acquire]

return det


async def test_readable():
async with init_devices(mock=True):
det = await make_detector("test", "test det", Path("/tmp"))
@pytest.mark.parametrize(
"sim_detector", [("test", "test det", Path("/tmp"))], indirect=True
)
async def test_readable(sim_detector):
assert isinstance(SimMotor, AsyncReadable)
assert isinstance(det, AsyncReadable)
assert isinstance(sim_detector, AsyncReadable)
assert not isinstance(StandardFlyer, AsyncReadable)

0 comments on commit 07dd570

Please sign in to comment.