From 1899d5de04915a4efca23ae8dfa2158caffcd46d Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Mon, 21 Oct 2024 17:19:57 +0100 Subject: [PATCH] Add commented out test --- tests/devices/unit_tests/oav/conftest.py | 1 + .../devices/unit_tests/oav/test_oav_utils.py | 47 ++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/devices/unit_tests/oav/conftest.py b/tests/devices/unit_tests/oav/conftest.py index 70f24b9efa..af6aafebed 100644 --- a/tests/devices/unit_tests/oav/conftest.py +++ b/tests/devices/unit_tests/oav/conftest.py @@ -15,4 +15,5 @@ async def oav() -> OAV: oav = OAV("", config=oav_config, name="fake_oav") set_mock_value(oav.grid_snapshot.x_size, 1024) set_mock_value(oav.grid_snapshot.y_size, 768) + set_mock_value(oav.zoom_controller.level, "1.0x") return oav diff --git a/tests/devices/unit_tests/oav/test_oav_utils.py b/tests/devices/unit_tests/oav/test_oav_utils.py index 38fc556ba9..54c46e2c68 100644 --- a/tests/devices/unit_tests/oav/test_oav_utils.py +++ b/tests/devices/unit_tests/oav/test_oav_utils.py @@ -5,6 +5,7 @@ from bluesky.run_engine import RunEngine from ophyd.sim import instantiate_fake_device +# from ophyd_async.core import set_mock_value from dodal.devices.oav.oav_calculations import calculate_beam_distance from dodal.devices.oav.oav_detector import OAV from dodal.devices.oav.pin_image_recognition import PinTipDetection @@ -13,8 +14,11 @@ PinNotFoundException, bottom_right_from_top_left, wait_for_tip_to_be_found, + # get_move_required_so_that_beam_is_at_pixel, ) +# from dodal.devices.smargon import Smargon + def test_bottom_right_from_top_left(): top_left = np.array([123, 123]) @@ -45,7 +49,48 @@ def test_calculate_beam_distance(h, v, expected_x, expected_y, oav: OAV): ) == (expected_x, expected_y) -# TODO add test_values_for_move_so_that_beam_is_at_pixel +# TODO, can't set beam center and micron as I want, will need to calculate +# the right values. +# @pytest.mark.parametrize( +# "px_per_um, beam_centre, angle, pixel_to_move_to, expected_xyz", +# [ +# # Simple case of beam being in the top left and each pixel being 1 mm +# ([1000, 1000], [0, 0], 0, [100, 190], [100, 190, 0]), +# ([1000, 1000], [0, 0], -90, [50, 250], [50, 0, 250]), +# ([1000, 1000], [0, 0], 90, [-60, 450], [-60, 0, -450]), +# # Beam offset +# ([1000, 1000], [100, 100], 0, [100, 100], [0, 0, 0]), +# ([1000, 1000], [100, 100], -90, [50, 250], [-50, 0, 150]), +# # Pixels_per_micron different +# ([10, 50], [0, 0], 0, [100, 190], [1, 9.5, 0]), +# ([60, 80], [0, 0], -90, [50, 250], [3, 0, 20]), +# ], +# ) +# async def test_values_for_move_so_that_beam_is_at_pixel( +# smargon: Smargon, +# oav: OAV, +# px_per_um, +# beam_centre, +# angle, +# pixel_to_move_to, +# expected_xyz, +# ): +# await oav.microns_per_pixel_x._backend.put(px_per_um[0]) +# # set_mock_value(oav.microns_per_pixel_x, px_per_um[0]) +# set_mock_value(oav.microns_per_pixel_y, px_per_um[1]) +# set_mock_value(oav.beam_centre_i, beam_centre[0]) +# set_mock_value(oav.beam_centre_j, beam_centre[1]) + +# set_mock_value(smargon.omega.user_readback, angle) + +# RE = RunEngine(call_returns_result=True) +# pos = RE( +# get_move_required_so_that_beam_is_at_pixel( +# smargon, pixel_to_move_to, oav +# ) +# ).plan_result # type: ignore + +# assert pos == pytest.approx(expected_xyz) @pytest.mark.asyncio