Skip to content

Commit

Permalink
A bunch of fixmes with test
Browse files Browse the repository at this point in the history
  • Loading branch information
noemifrisina committed Oct 18, 2024
1 parent a15765c commit a0092a3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/devices/unit_tests/oav/test_snapshots.py
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

0 comments on commit a0092a3

Please sign in to comment.