-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
a15765c
commit a0092a3
Showing
1 changed file
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from unittest.mock import AsyncMock, MagicMock, patch | ||
|
||
import pytest | ||
from ophyd_async.core import DeviceCollector, MockSignalBackend, SignalR, set_mock_value | ||
|
||
from dodal.devices.oav.snapshots.snapshot_with_beam_centre import SnapshotWithBeamCentre | ||
|
||
|
||
def create_and_set_mock_signal_r(dtype, name, value): | ||
sig = SignalR(MockSignalBackend(dtype), name=name) | ||
set_mock_value(sig, value) | ||
return sig | ||
|
||
|
||
@pytest.fixture | ||
async def snapshot() -> SnapshotWithBeamCentre: | ||
mock_beam_x = create_and_set_mock_signal_r(int, "moxk_beam_x", 510) | ||
mock_beam_y = create_and_set_mock_signal_r(int, "mock_beam_y", 380) | ||
async with DeviceCollector(mock=True): | ||
snapshot = SnapshotWithBeamCentre("", mock_beam_x, mock_beam_y, "fake_snapshot") | ||
return snapshot | ||
|
||
|
||
@patch("dodal.devices.oav.snapshots.snapshot_with_beam_centre.Image") | ||
@patch("dodal.devices.oav.snapshots.snapshot_with_beam_centre.ImageDraw") | ||
@patch( | ||
"dodal.devices.areadetector.plugins.MJPG_async.ClientSession.get", | ||
autospec=True, | ||
) | ||
async def test_given_snapshot_triggered_then_crosshair_drawn( | ||
mock_get, patch_image_draw, patch_image, snapshot | ||
): | ||
mock_get.return_value.__aenter__.return_value = AsyncMock() | ||
patch_line = MagicMock() | ||
patch_image_draw.Draw.return_value.line = patch_line | ||
|
||
await snapshot.directory.set("/tmp/") | ||
await snapshot.filename.set("test") | ||
|
||
# FIXME This will fail because "function never awaited" | ||
# Need to find it though. | ||
# await snapshot.trigger() | ||
|
||
# assert len(patch_line.mock_calls) == 2 |