|
| 1 | +from math import inf |
| 2 | +from unittest.mock import AsyncMock |
| 3 | + |
1 | 4 | import pytest |
2 | 5 | from ophyd_async.testing import set_mock_value |
3 | 6 |
|
4 | 7 | from dodal.devices.aperturescatterguard import ( |
5 | | - AperturePosition, |
6 | 8 | ApertureScatterguard, |
7 | | - ApertureValue, |
8 | 9 | ) |
9 | 10 | from dodal.devices.i04.beamsize import Beamsize |
10 | 11 | from dodal.devices.i04.transfocator import Transfocator |
11 | | -from tests.devices.conftest import set_to_position |
12 | 12 |
|
13 | 13 |
|
14 | 14 | @pytest.mark.parametrize( |
15 | | - "selected_aperture, aperture_signal_values, transfocator_sizes, expected_beamsize", |
| 15 | + "aperture_radius, transfocator_sizes, expected_beamsize", |
16 | 16 | [ |
17 | | - (ApertureValue.SMALL, (1, 0, 0), (10.0, 10.0), (10.0, 10.0)), |
18 | | - (ApertureValue.SMALL, (1, 0, 0), (30.0, 10.0), (20.0, 10.0)), |
19 | | - (ApertureValue.SMALL, (1, 0, 0), (10.0, 30.0), (10.0, 20.0)), |
20 | | - (ApertureValue.SMALL, (1, 0, 0), (55.0, 30.0), (20.0, 20.0)), |
21 | | - (ApertureValue.MEDIUM, (0, 1, 0), (10.0, 10.0), (10.0, 10.0)), |
22 | | - (ApertureValue.MEDIUM, (0, 1, 0), (30.0, 70.0), (30.0, 50.0)), |
23 | | - (ApertureValue.MEDIUM, (0, 1, 0), (70.0, 30.0), (50.0, 30.0)), |
24 | | - (ApertureValue.MEDIUM, (0, 1, 0), (90.0, 90.0), (50.0, 50.0)), |
25 | | - (ApertureValue.LARGE, (0, 0, 1), (90.0, 55.0), (90.0, 55.0)), |
26 | | - (ApertureValue.LARGE, (0, 0, 1), (110.0, 55.0), (100.0, 55.0)), |
27 | | - (ApertureValue.LARGE, (0, 0, 1), (90.0, 110.0), (90.0, 100.0)), |
28 | | - (ApertureValue.LARGE, (0, 0, 1), (120.0, 120.0), (100.0, 100.0)), |
29 | | - (ApertureValue.OUT_OF_BEAM, (0, 0, 0), (120.0, 10.0), (0.0, 0.0)), |
30 | | - (ApertureValue.OUT_OF_BEAM, (0, 0, 0), (10.0, 120.0), (0.0, 0.0)), |
31 | | - (ApertureValue.PARKED, (0, 0, 0), (10.0, 10.0), (0.0, 0.0)), |
32 | | - (ApertureValue.PARKED, (0, 0, 0), (120.0, 120.0), (0.0, 0.0)), |
| 17 | + (10.0, (50.0, 60.0), (10.0, 10.0)), |
| 18 | + (20.0, (10.0, 30.0), (10.0, 20.0)), |
| 19 | + (20.0, (30.0, 10.0), (20.0, 10.0)), |
| 20 | + (100.0, (50.0, 60.0), (50.0, 60.0)), |
| 21 | + (inf, (50.0, 60.0), (50.0, 60.0)), |
33 | 22 | ], |
34 | 23 | ) |
35 | 24 | async def test_beamsize_gives_min_of_aperture_and_transfocator_width_and_height( |
36 | | - selected_aperture: ApertureValue, |
37 | | - aperture_signal_values: tuple[int, int, int], |
| 25 | + aperture_radius: float, |
38 | 26 | transfocator_sizes: tuple[float, float], |
39 | 27 | expected_beamsize: tuple[float, float], |
40 | 28 | fake_transfocator: Transfocator, |
41 | 29 | ap_sg: ApertureScatterguard, |
42 | | - aperture_positions: dict[ApertureValue, AperturePosition], |
43 | 30 | ): |
44 | | - await set_to_position(ap_sg, aperture_positions[selected_aperture]) |
| 31 | + set_mock_value(ap_sg.aperture.medium, 1) |
| 32 | + |
| 33 | + ap_sg.radius.read = AsyncMock( |
| 34 | + return_value={ |
| 35 | + "test_ap_sg-radius": { |
| 36 | + "value": aperture_radius, |
| 37 | + "timestamp": 1763051436.7372239, |
| 38 | + "alarm_severity": 0, |
| 39 | + } |
| 40 | + } |
| 41 | + ) # see https://github.com/bluesky/ophyd-async/issues/1132 |
45 | 42 |
|
46 | | - for i, signal in enumerate( |
47 | | - (ap_sg.aperture.small, ap_sg.aperture.medium, ap_sg.aperture.large) |
48 | | - ): |
49 | | - set_mock_value(signal, aperture_signal_values[i]) |
50 | 43 | set_mock_value(fake_transfocator.current_horizontal_size_rbv, transfocator_sizes[0]) |
51 | 44 | set_mock_value(fake_transfocator.current_vertical_size_rbv, transfocator_sizes[1]) |
52 | 45 |
|
|
0 commit comments