Skip to content

Commit 44ccd2e

Browse files
author
eir17846
committed
reorganise tests - use real apple knot functions and polynomials
1 parent 4cfa0f3 commit 44ccd2e

File tree

4 files changed

+21
-56
lines changed

4 files changed

+21
-56
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pytest
2+
3+
from dodal.devices.beamlines.i05_shared.apple_knot import APPLE_KNOT_EXCLUSION_ZONES
4+
from dodal.devices.insertion_device.apple_knot_controller import AppleKnotPathFinder
5+
6+
7+
@pytest.fixture
8+
def apple_knot_i05_path_finder() -> AppleKnotPathFinder:
9+
return AppleKnotPathFinder(APPLE_KNOT_EXCLUSION_ZONES)

tests/devices/beamlines/i05/test_compound_motor.py renamed to tests/devices/beamlines/i05_shared/test_compound_motor.py

File renamed without changes.

tests/devices/insertion_device/test_apple_knot_path_finder.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22

3-
from dodal.common.maths import Rectangle2D
43
from dodal.devices.insertion_device import (
54
AppleKnotPathFinder,
65
)
@@ -10,13 +9,10 @@
109
)
1110

1211
# add mock_config_client, mock_id_gap, mock_phase and mock_jaw_phase_axes to pytest.
13-
pytest_plugins = ["dodal.testing.fixtures.devices.apple2"]
14-
15-
# Define exclusion zones in phase-gap space
16-
TEST_APPLE_KNOT_EXCLUSION_ZONES = (
17-
Rectangle2D(-65.5, 0.0, 65.5, 25.5), # mechanical limit
18-
Rectangle2D(-10.5, 0.0, 10.5, 37.5), # power load limit
19-
)
12+
pytest_plugins = [
13+
"dodal.testing.fixtures.devices.apple2",
14+
"dodal.testing.fixtures.devices.apple_knot",
15+
]
2016

2117

2218
def get_pair_apple2_val(
@@ -42,11 +38,6 @@ def get_pair_apple2_val(
4238
return start_val, target_val
4339

4440

45-
@pytest.fixture
46-
def apple_knot_i05_path_finder() -> AppleKnotPathFinder:
47-
return AppleKnotPathFinder(TEST_APPLE_KNOT_EXCLUSION_ZONES)
48-
49-
5041
@pytest.mark.parametrize(
5142
"start_phase, start_gap, target_phase, target_gap",
5243
[

tests/devices/insertion_device/test_apple_knot_undulator.py

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import numpy.polynomial as poly
21
import pytest
32
from ophyd_async.core import (
43
set_mock_value,
54
)
65

7-
from dodal.common.maths import Rectangle2D
6+
from dodal.devices.beamlines.i05_shared import (
7+
energy_to_gap_converter,
8+
energy_to_phase_converter,
9+
)
810
from dodal.devices.insertion_device import (
911
AppleKnotController,
1012
AppleKnotPathFinder,
@@ -16,47 +18,10 @@
1618
)
1719

1820
# add mock_config_client, mock_id_gap, mock_phase and mock_jaw_phase_axes to pytest.
19-
pytest_plugins = ["dodal.testing.fixtures.devices.apple2"]
20-
21-
# Define exclusion zones in phase-gap space
22-
TEST_APPLE_KNOT_EXCLUSION_ZONES = (
23-
Rectangle2D(-65.5, 0.0, 65.5, 25.5), # mechanical limit
24-
Rectangle2D(-10.5, 0.0, 10.5, 37.5), # power load limit
25-
)
26-
# Test polynomials for energy to gap/phase conversion
27-
TEST_LH_GAP_POLYNOMIAL = poly.Polynomial([12.46, 0.832, -0.002])
28-
TEST_LV_GAP_POLYNOMIAL = poly.Polynomial([8.7456, 0.412, -0.0024317])
29-
TEST_C_GAP_POLYNOMIAL = poly.Polynomial([9.1763, 0.312, -0.000305968])
30-
TEST_C_PHASE_POLYNOMIAL = poly.Polynomial(
31-
[4.4, 0.79, -0.022, 0.00041, -4.921e-6, 3.9683e-8]
32-
)
33-
34-
35-
def energy_to_gap_converter(energy: float, pol: Pol) -> float:
36-
if pol == Pol.LH:
37-
return float(TEST_LH_GAP_POLYNOMIAL(energy))
38-
if pol == Pol.LV:
39-
return float(TEST_LV_GAP_POLYNOMIAL(energy))
40-
if pol == Pol.PC or pol == Pol.NC:
41-
return float(TEST_C_GAP_POLYNOMIAL(energy))
42-
return 0.0
43-
44-
45-
def energy_to_phase_converter(energy: float, pol: Pol) -> float:
46-
if pol == Pol.LH:
47-
return 0.0
48-
if pol == Pol.LV:
49-
return 70.0
50-
if pol == Pol.PC:
51-
return float(TEST_C_PHASE_POLYNOMIAL(energy))
52-
if pol == Pol.NC:
53-
return -float(TEST_C_PHASE_POLYNOMIAL(energy))
54-
return 0.0
55-
56-
57-
@pytest.fixture
58-
def apple_knot_i05_path_finder() -> AppleKnotPathFinder:
59-
return AppleKnotPathFinder(TEST_APPLE_KNOT_EXCLUSION_ZONES)
21+
pytest_plugins = [
22+
"dodal.testing.fixtures.devices.apple2",
23+
"dodal.testing.fixtures.devices.apple_knot",
24+
]
6025

6126

6227
@pytest.fixture

0 commit comments

Comments
 (0)