Skip to content

Commit

Permalink
Simplify ad standard det tests (#592)
Browse files Browse the repository at this point in the history
* Refactor ADPilatus tests to use the ad_standard_det_factory

* Add default signals for sim detector config

* Fix type annotation

* Overhaul sim detector tests to use ad standard det factory, improve factory with mock put callback

* Fix tests for remaining detectors to account for new changes to factory fixture

* Make sure to include config_sigs passed to init

* Add suggestions from review
  • Loading branch information
jwlodek authored Sep 21, 2024
1 parent c9c70ba commit e7cef5b
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 230 deletions.
2 changes: 1 addition & 1 deletion src/ophyd_async/epics/adsimdetector/_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def __init__(
lambda: self.name,
adcore.ADBaseDatasetDescriber(self.drv),
),
config_sigs=config_sigs,
config_sigs=(self.drv.acquire_period, self.drv.acquire_time, *config_sigs),
name=name,
)
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def create_static_dir_provider_given_fp(fp: FilenameProvider):

@pytest.fixture
def static_path_provider(
static_path_provider_factory: callable,
static_path_provider_factory: Callable,
static_filename_provider: FilenameProvider,
):
return static_path_provider_factory(static_filename_provider)
Expand Down
10 changes: 1 addition & 9 deletions tests/epics/adaravis/test_aravis.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ async def test_can_read(test_adaravis: adaravis.AravisDetector):
async def test_decribe_describes_writer_dataset(
test_adaravis: adaravis.AravisDetector, one_shot_trigger_info: TriggerInfo
):
set_mock_value(test_adaravis._writer.hdf.file_path_exists, True)
set_mock_value(test_adaravis._writer.hdf.capture, True)

assert await test_adaravis.describe() == {}
await test_adaravis.stage()
await test_adaravis.prepare(one_shot_trigger_info)
Expand All @@ -106,10 +103,7 @@ async def test_can_collect(
one_shot_trigger_info: TriggerInfo,
):
path_info = static_path_provider()
full_file_name = path_info.directory_path / "foo.h5"
set_mock_value(test_adaravis.hdf.full_file_name, str(full_file_name))
set_mock_value(test_adaravis._writer.hdf.file_path_exists, True)
set_mock_value(test_adaravis._writer.hdf.capture, True)
full_file_name = path_info.directory_path / f"{path_info.filename}.h5"
await test_adaravis.stage()
await test_adaravis.prepare(one_shot_trigger_info)
docs = [(name, doc) async for name, doc in test_adaravis.collect_asset_docs(1)]
Expand All @@ -135,8 +129,6 @@ async def test_can_collect(
async def test_can_decribe_collect(
test_adaravis: adaravis.AravisDetector, one_shot_trigger_info: TriggerInfo
):
set_mock_value(test_adaravis._writer.hdf.file_path_exists, True)
set_mock_value(test_adaravis._writer.hdf.capture, True)
assert (await test_adaravis.describe_collect()) == {}
await test_adaravis.stage()
await test_adaravis.prepare(one_shot_trigger_info)
Expand Down
13 changes: 3 additions & 10 deletions tests/epics/adkinetix/test_kinetix.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def setup_trigger_mode(trig_mode: DetectorTrigger):


async def test_hints_from_hdf_writer(test_adkinetix: adkinetix.KinetixDetector):
assert test_adkinetix.hints == {"fields": ["test_adkinetix1"]}
assert test_adkinetix.hints == {"fields": [test_adkinetix.name]}


async def test_can_read(test_adkinetix: adkinetix.KinetixDetector):
Expand All @@ -62,9 +62,6 @@ async def test_can_read(test_adkinetix: adkinetix.KinetixDetector):
async def test_decribe_describes_writer_dataset(
test_adkinetix: adkinetix.KinetixDetector, one_shot_trigger_info: TriggerInfo
):
set_mock_value(test_adkinetix._writer.hdf.file_path_exists, True)
set_mock_value(test_adkinetix._writer.hdf.capture, True)

assert await test_adkinetix.describe() == {}
await test_adkinetix.stage()
await test_adkinetix.prepare(one_shot_trigger_info)
Expand All @@ -85,10 +82,8 @@ async def test_can_collect(
one_shot_trigger_info: TriggerInfo,
):
path_info = static_path_provider()
full_file_name = path_info.directory_path / "foo.h5"
set_mock_value(test_adkinetix.hdf.full_file_name, str(full_file_name))
set_mock_value(test_adkinetix._writer.hdf.file_path_exists, True)
set_mock_value(test_adkinetix._writer.hdf.capture, True)
full_file_name = path_info.directory_path / f"{path_info.filename}.h5"

await test_adkinetix.stage()
await test_adkinetix.prepare(one_shot_trigger_info)
docs = [(name, doc) async for name, doc in test_adkinetix.collect_asset_docs(1)]
Expand All @@ -114,8 +109,6 @@ async def test_can_collect(
async def test_can_decribe_collect(
test_adkinetix: adkinetix.KinetixDetector, one_shot_trigger_info: TriggerInfo
):
set_mock_value(test_adkinetix._writer.hdf.file_path_exists, True)
set_mock_value(test_adkinetix._writer.hdf.capture, True)
assert (await test_adkinetix.describe_collect()) == {}
await test_adkinetix.stage()
await test_adkinetix.prepare(one_shot_trigger_info)
Expand Down
54 changes: 31 additions & 23 deletions tests/epics/adpilatus/test_pilatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,24 @@
from unittest.mock import patch

import pytest
from bluesky.run_engine import RunEngine

from ophyd_async.core import (
DetectorTrigger,
DeviceCollector,
PathProvider,
TriggerInfo,
set_mock_value,
)
from ophyd_async.epics import adpilatus
from ophyd_async.epics import adcore, adpilatus


@pytest.fixture
async def test_adpilatus(
RE: RunEngine,
static_path_provider: PathProvider,
) -> adpilatus.PilatusDetector:
async with DeviceCollector(mock=True):
test_adpilatus = adpilatus.PilatusDetector("PILATUS:", static_path_provider)

return test_adpilatus


async def test_deadtime_overridable(static_path_provider: PathProvider):
async with DeviceCollector(mock=True):
test_adpilatus = adpilatus.PilatusDetector(
"PILATUS:",
static_path_provider,
readout_time=adpilatus.PilatusReadoutTime.pilatus2,
)
pilatus_controller = test_adpilatus.controller
def test_adpilatus(ad_standard_det_factory) -> adpilatus.PilatusDetector:
return ad_standard_det_factory(adpilatus.PilatusDetector)


async def test_deadtime_overridable(test_adpilatus: adpilatus.PilatusDetector):
pilatus_controller = test_adpilatus._controller
pilatus_controller._readout_time = adpilatus.PilatusReadoutTime.pilatus2

# deadtime invariant with exposure time
assert pilatus_controller.get_deadtime(0) == 2.28e-3

Expand Down Expand Up @@ -110,7 +97,7 @@ async def _trigger(


async def test_hints_from_hdf_writer(test_adpilatus: adpilatus.PilatusDetector):
assert test_adpilatus.hints == {"fields": ["test_adpilatus"]}
assert test_adpilatus.hints == {"fields": [test_adpilatus.name]}


async def test_unsupported_trigger_excepts(test_adpilatus: adpilatus.PilatusDetector):
Expand Down Expand Up @@ -144,3 +131,24 @@ async def dummy_open(multiplier: int = 0):
)
assert (await test_adpilatus.drv.acquire_time.get_value()) == 1.0
assert (await test_adpilatus.drv.acquire_period.get_value()) == 1.0 + 950e-6


async def test_pilatus_controller(test_adpilatus: adpilatus.PilatusDetector):
pilatus = test_adpilatus._controller
pilatus_driver = pilatus._drv
set_mock_value(pilatus_driver.armed, True)
await pilatus.prepare(TriggerInfo(number=1, trigger=DetectorTrigger.constant_gate))
await pilatus.arm()
await pilatus.wait_for_idle()

assert await pilatus_driver.num_images.get_value() == 1
assert await pilatus_driver.image_mode.get_value() == adcore.ImageMode.multiple
assert (
await pilatus_driver.trigger_mode.get_value()
== adpilatus.PilatusTriggerMode.ext_enable
)
assert await pilatus_driver.acquire.get_value() is True

await pilatus.disarm()

assert await pilatus_driver.acquire.get_value() is False
46 changes: 0 additions & 46 deletions tests/epics/adpilatus/test_pilatus_controller.py

This file was deleted.

32 changes: 0 additions & 32 deletions tests/epics/adsimdetector/test_adsim_controller.py

This file was deleted.

Loading

0 comments on commit e7cef5b

Please sign in to comment.