Skip to content

Commit

Permalink
fixed persistent tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Jan 14, 2025
1 parent 16b794a commit b3450d1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/ophyd_async/epics/adaravis/_aravis_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def prepare(self, trigger_info: TriggerInfo):
else:
image_mode = adcore.ImageMode.MULTIPLE
if (exposure := trigger_info.livetime) is not None:
asyncio.gather(self.driver.acquire_time.set(exposure))
await self.driver.acquire_time.set(exposure)

trigger_mode, trigger_source = self._get_trigger_info(trigger_info.trigger)
# trigger mode must be set first and on it's own!
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def _error_and_kill_pending_tasks(
task
for task in asyncio.all_tasks(loop)
if (coro := task.get_coro()) is not None
and hasattr(coro, "__name__")
and coro.__name__ not in _ALLOWED_PYTEST_TASKS
and not task.done()
}
Expand All @@ -112,7 +113,7 @@ def _error_and_kill_pending_tasks(


@pytest.fixture(autouse=True, scope="function")
def fail_test_on_unclosed_tasks(request: FixtureRequest):
async def fail_test_on_unclosed_tasks(request: FixtureRequest):
"""
Used on every test to ensure failure if there are pending tasks
by the end of the test.
Expand Down
34 changes: 21 additions & 13 deletions tests/epics/adaravis/test_aravis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import cast
from unittest.mock import AsyncMock, patch

import pytest

Expand Down Expand Up @@ -133,17 +134,24 @@ async def test_can_decribe_collect(


async def test_unsupported_trigger_excepts(test_adaravis: adaravis.AravisDetector):
with pytest.raises(
ValueError,
# str(EnumClass.value) handling changed in Python 3.11
match=r"AravisController only supports the following trigger types: .* but",
):
await test_adaravis.prepare(
TriggerInfo(
number_of_triggers=0,
trigger=DetectorTrigger.VARIABLE_GATE,
deadtime=1,
livetime=1,
frame_timeout=3,
with patch(
"ophyd_async.epics.adcore._hdf_writer.ADHDFWriter.open", new_callable=AsyncMock
) as mock_open:
with pytest.raises(
ValueError,
# str(EnumClass.value) handling changed in Python 3.11
match=(
"AravisController only supports the following trigger types: .* but"
),
):
await test_adaravis.prepare(
TriggerInfo(
number_of_triggers=0,
trigger=DetectorTrigger.VARIABLE_GATE,
deadtime=1,
livetime=1,
frame_timeout=3,
)
)
)

mock_open.assert_called_once()
31 changes: 18 additions & 13 deletions tests/epics/adpilatus/test_pilatus.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from collections.abc import Awaitable, Callable
from typing import cast
from unittest.mock import patch
from unittest.mock import AsyncMock, patch

import pytest

Expand Down Expand Up @@ -103,19 +103,24 @@ async def test_hints_from_hdf_writer(test_adpilatus: adpilatus.PilatusDetector):


async def test_unsupported_trigger_excepts(test_adpilatus: adpilatus.PilatusDetector):
with pytest.raises(
ValueError,
# str(EnumClass.value) handling changed in Python 3.11
match=r"PilatusController only supports the following trigger types: .* but",
):
await test_adpilatus.prepare(
TriggerInfo(
number_of_triggers=1,
trigger=DetectorTrigger.EDGE_TRIGGER,
deadtime=1.0,
livetime=1.0,
open = "ophyd_async.epics.adcore._hdf_writer.ADHDFWriter.open"
with patch(open, new_callable=AsyncMock) as mock_open:
with pytest.raises(
ValueError,
# str(EnumClass.value) handling changed in Python 3.11
match=(
"PilatusController only supports the following trigger types: .* but"
),
):
await test_adpilatus.prepare(
TriggerInfo(
number_of_triggers=1,
trigger=DetectorTrigger.EDGE_TRIGGER,
deadtime=1.0,
livetime=1.0,
)
)
)
mock_open.assert_called_once()


async def test_exposure_time_and_acquire_period_set(
Expand Down

0 comments on commit b3450d1

Please sign in to comment.