|
1 | 1 | import asyncio |
2 | | -from unittest.mock import MagicMock, patch |
| 2 | +from unittest.mock import patch |
3 | 3 |
|
4 | | -import numpy as np |
5 | 4 | import pytest |
6 | | -from numpy.typing import NDArray |
7 | | -from ophyd.v2.core import set_sim_value |
| 5 | +from ophyd_async.core import set_sim_value |
8 | 6 |
|
9 | 7 | from dodal.devices.oav.pin_image_recognition import MxSampleDetect, PinTipDetection |
10 | | -from dodal.devices.oav.pin_image_recognition.utils import SampleLocation |
11 | 8 |
|
12 | 9 | EVENT_LOOP = asyncio.new_event_loop() |
13 | 10 |
|
@@ -90,68 +87,3 @@ async def test_invalid_processing_func_uses_identity_function(): |
90 | 87 | # Assert captured preprocess function is the identitiy function |
91 | 88 | arg = object() |
92 | 89 | assert arg == captured_func(arg) |
93 | | - |
94 | | - |
95 | | -@pytest.mark.parametrize( |
96 | | - "input_array,height,width,reshaped", |
97 | | - [ |
98 | | - (np.zeros(shape=(1,)), 1, 1, np.zeros(shape=(1, 1))), |
99 | | - (np.zeros(shape=(3,)), 1, 1, np.zeros(shape=(1, 1, 3))), |
100 | | - (np.zeros(shape=(1920 * 1080)), 1080, 1920, np.zeros(shape=(1080, 1920))), |
101 | | - ( |
102 | | - np.zeros(shape=(1920 * 1080 * 3)), |
103 | | - 1080, |
104 | | - 1920, |
105 | | - np.zeros(shape=(1080, 1920, 3)), |
106 | | - ), |
107 | | - ], |
108 | | -) |
109 | | -def test_when_data_supplied_THEN_reshaped_correctly_before_call_to_process_array( |
110 | | - input_array: NDArray, height: int, width: int, reshaped: NDArray |
111 | | -): |
112 | | - device = EVENT_LOOP.run_until_complete(_get_pin_tip_detection_device()) |
113 | | - |
114 | | - device.array_data._backend._set_value(input_array) # type: ignore |
115 | | - set_sim_value(device.oav_height, height) |
116 | | - set_sim_value(device.oav_width, width) |
117 | | - |
118 | | - MxSampleDetect.processArray = MagicMock( |
119 | | - autospec=True, |
120 | | - return_value=SampleLocation( |
121 | | - tip_x=10, tip_y=20, edge_bottom=np.array([]), edge_top=np.array([]) |
122 | | - ), |
123 | | - ) |
124 | | - |
125 | | - result = EVENT_LOOP.run_until_complete(device.read()) |
126 | | - |
127 | | - MxSampleDetect.processArray.assert_called_once() |
128 | | - np.testing.assert_array_equal(MxSampleDetect.processArray.call_args[0][0], reshaped) |
129 | | - |
130 | | - assert result[""]["value"] == (10, 20) |
131 | | - |
132 | | - |
133 | | -@pytest.mark.parametrize( |
134 | | - "input_array,height,width", |
135 | | - [ |
136 | | - (np.zeros(shape=(0,)), 1080, 1920), |
137 | | - (np.zeros(shape=(1920 * 1080 * 2)), 1080, 1920), |
138 | | - ], |
139 | | -) |
140 | | -def test_when_invalid_data_length_supplied_THEN_no_call_to_process_array( |
141 | | - input_array: NDArray, height: int, width: int |
142 | | -): |
143 | | - device = EVENT_LOOP.run_until_complete(_get_pin_tip_detection_device()) |
144 | | - |
145 | | - set_sim_value(device.array_data, input_array) |
146 | | - set_sim_value(device.oav_height, height) |
147 | | - set_sim_value(device.oav_width, width) |
148 | | - |
149 | | - MxSampleDetect.processArray = MagicMock( |
150 | | - autospec=True, |
151 | | - ) |
152 | | - |
153 | | - result = EVENT_LOOP.run_until_complete(device.read()) |
154 | | - |
155 | | - MxSampleDetect.processArray.assert_not_called() |
156 | | - |
157 | | - assert result[""]["value"] == (None, None) |
0 commit comments