Skip to content

Commit 276a0ba

Browse files
committed
Switch tests from VMX to I04
The tests now test against I04 and DIAD instead of VMX and DIAD. I also factored out a couple of constants from the test files
1 parent 7f891c1 commit 276a0ba

File tree

4 files changed

+40
-37
lines changed

4 files changed

+40
-37
lines changed

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def simple_data_source_manager(
123123

124124

125125
@pytest.fixture(scope="session")
126-
def vmx_ring():
127-
return pytac.load_csv.load("VMX", mock.MagicMock, symmetry=24)
126+
def i04_ring():
127+
return pytac.load_csv.load("I04", mock.MagicMock, symmetry=24)
128128

129129

130130
@pytest.fixture(scope="session")

tests/constants.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,18 @@
1515
LATTICE_NAME = "lattice"
1616

1717
CURRENT_DIR_PATH = Path(__file__).resolve().parent
18+
19+
# Update this to the lattice mode you want to be used in *most* tests.
20+
TESTING_MODE = "I04"
21+
TESTING_MODE_RING = "I04".lower() + "_ring"
22+
23+
# Update this with the ringmodes that pytac supports
24+
SUPPORTED_MODES = {
25+
"I04",
26+
"DIAD",
27+
"DIADSP",
28+
"DIADTHz",
29+
"I04SP",
30+
"I04THz",
31+
"48",
32+
}

tests/test_load.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytac
88
from pytac.load_csv import available_ringmodes, load, load_unitconv, resolve_unitconv
9-
9+
from constants import TESTING_MODE, SUPPORTED_MODES
1010

1111
@pytest.fixture
1212
def mock_cs_raises_ImportError():
@@ -32,8 +32,8 @@ def test_default_control_system_import():
3232
- assert that the default control system is indeed cothread and that it
3333
is loaded onto the lattice correctly
3434
"""
35-
assert bool(load("VMX"))
36-
assert isinstance(load("VMX")._cs, pytac.cothread_cs.CothreadControlSystem)
35+
assert bool(load(TESTING_MODE))
36+
assert isinstance(load(TESTING_MODE)._cs, pytac.cothread_cs.CothreadControlSystem)
3737

3838

3939
def test_import_fail_raises_ControlSystemException(mock_cs_raises_ImportError):
@@ -44,7 +44,7 @@ def test_import_fail_raises_ControlSystemException(mock_cs_raises_ImportError):
4444
"""
4545
with patch("pytac.cothread_cs.CothreadControlSystem", mock_cs_raises_ImportError):
4646
with pytest.raises(pytac.exceptions.ControlSystemException):
47-
load("VMX")
47+
load(TESTING_MODE)
4848

4949

5050
def test_elements_loaded(lattice):
@@ -134,22 +134,9 @@ def test_resolve_unitconv_raises_UnitsException_if_unrecognised_UnitConv_type(
134134

135135

136136
def test_available_ringmodes():
137-
ringmodes = {
138-
"SRI0913_MOGA",
139-
"I04",
140-
"VMX",
141-
"DIAD",
142-
"VMXSP",
143-
"VMXTHz",
144-
"DIADSP",
145-
"DIADTHz",
146-
"I04SP",
147-
"I04THz",
148-
"48",
149-
}
150-
assert available_ringmodes() == ringmodes
137+
assert available_ringmodes() == SUPPORTED_MODES
151138
bad_path = Path(__file__).resolve().parent.parent
152139
with pytest.raises(OSError):
153140
available_ringmodes(bad_path)
154141
good_path = bad_path / "src/pytac/data"
155-
assert available_ringmodes(good_path) == ringmodes
142+
assert available_ringmodes(good_path) == SUPPORTED_MODES

tests/test_machine.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111

1212
import pytac
13+
from constants import TESTING_MODE, TESTING_MODE_RING
1314

1415
EPS = 1e-8
1516

@@ -21,13 +22,13 @@ def get_lattice(ring_mode):
2122

2223

2324
def test_load_lattice_using_default_dir():
24-
lat = pytac.load_csv.load("VMX", mock.MagicMock())
25-
assert len(lat) == 2192
25+
lat = pytac.load_csv.load(TESTING_MODE, mock.MagicMock())
26+
assert len(lat) == 2190
2627

2728

2829
@pytest.mark.parametrize(
2930
"lattice, name, n_elements, length",
30-
[("vmx_ring", "VMX", 2192, 561.571), ("diad_ring", "DIAD", 2194, 561.571)],
31+
[(TESTING_MODE_RING, TESTING_MODE, 2190, 561.571), ("diad_ring", "DIAD", 2194, 561.571)],
3132
)
3233
def test_load_lattice(lattice, name, n_elements, length, request):
3334
lattice = request.getfixturevalue(lattice)
@@ -36,7 +37,7 @@ def test_load_lattice(lattice, name, n_elements, length, request):
3637
assert (lattice.get_length() - length) < EPS
3738

3839

39-
@pytest.mark.parametrize("lattice, n_bpms", [("vmx_ring", 173), ("diad_ring", 173)])
40+
@pytest.mark.parametrize("lattice, n_bpms", [(TESTING_MODE_RING, 173), ("diad_ring", 173)])
4041
def test_get_pv_names(lattice, n_bpms, request):
4142
lattice = request.getfixturevalue(lattice)
4243
bpm_x_pvs = lattice.get_element_pv_names("BPM", "x", handle="readback")
@@ -51,7 +52,7 @@ def test_get_pv_names(lattice, n_bpms, request):
5152
assert re.match("SR.*HBPM.*SLOW:DISABLED", pv)
5253

5354

54-
@pytest.mark.parametrize("lattice, n_bpms", [("vmx_ring", 173), ("diad_ring", 173)])
55+
@pytest.mark.parametrize("lattice, n_bpms", [(TESTING_MODE_RING, 173), ("diad_ring", 173)])
5556
def test_load_bpms(lattice, n_bpms, request):
5657
lattice = request.getfixturevalue(lattice)
5758
bpms = lattice.get_elements("BPM")
@@ -74,14 +75,14 @@ def test_load_bpms(lattice, n_bpms, request):
7475
assert bpms[-1].cell == 24
7576

7677

77-
@pytest.mark.parametrize("lattice, n_drifts", [("vmx_ring", 1343), ("diad_ring", 1346)])
78+
@pytest.mark.parametrize("lattice, n_drifts", [(TESTING_MODE_RING, 1341), ("diad_ring", 1346)])
7879
def test_load_drift_elements(lattice, n_drifts, request):
7980
lattice = request.getfixturevalue(lattice)
8081
drifts = lattice.get_elements("DRIFT")
8182
assert len(drifts) == n_drifts
8283

8384

84-
@pytest.mark.parametrize("lattice, n_quads", [("vmx_ring", 248), ("diad_ring", 248)])
85+
@pytest.mark.parametrize("lattice, n_quads", [(TESTING_MODE_RING, 248), ("diad_ring", 248)])
8586
def test_load_quadrupoles(lattice, n_quads, request):
8687
lattice = request.getfixturevalue(lattice)
8788
quads = lattice.get_elements("Quadrupole")
@@ -94,7 +95,7 @@ def test_load_quadrupoles(lattice, n_quads, request):
9495

9596

9697
@pytest.mark.parametrize(
97-
"lattice, n_q1b, n_q1d", [("vmx_ring", 34, 12), ("diad_ring", 34, 12)]
98+
"lattice, n_q1b, n_q1d", [(TESTING_MODE_RING, 34, 12), ("diad_ring", 34, 12)]
9899
)
99100
def test_load_quad_family(lattice, n_q1b, n_q1d, request):
100101
lattice = request.getfixturevalue(lattice)
@@ -105,7 +106,7 @@ def test_load_quad_family(lattice, n_q1b, n_q1d, request):
105106

106107

107108
@pytest.mark.parametrize(
108-
"lattice, n_correctors", [("vmx_ring", 173), ("diad_ring", 172)]
109+
"lattice, n_correctors", [(TESTING_MODE_RING, 172), ("diad_ring", 172)]
109110
)
110111
def test_load_correctors(lattice, n_correctors, request):
111112
lattice = request.getfixturevalue(lattice)
@@ -125,7 +126,7 @@ def test_load_correctors(lattice, n_correctors, request):
125126
)
126127

127128

128-
@pytest.mark.parametrize("lattice, n_squads", [("vmx_ring", 98), ("diad_ring", 98)])
129+
@pytest.mark.parametrize("lattice, n_squads", [(TESTING_MODE_RING, 98), ("diad_ring", 98)])
129130
def test_load_squads(lattice, n_squads, request):
130131
lattice = request.getfixturevalue(lattice)
131132
squads = lattice.get_elements("SQUAD")
@@ -137,7 +138,7 @@ def test_load_squads(lattice, n_squads, request):
137138
assert re.match("SR.*SQ.*:SETI", device.sp_pv)
138139

139140

140-
@pytest.mark.parametrize("lattice", ["diad_ring", "vmx_ring"])
141+
@pytest.mark.parametrize("lattice", ["diad_ring", TESTING_MODE_RING])
141142
def test_cell(lattice, request):
142143
lattice = request.getfixturevalue(lattice)
143144
# there are squads in every cell
@@ -146,7 +147,7 @@ def test_cell(lattice, request):
146147
assert sq[-1].cell == 24
147148

148149

149-
@pytest.mark.parametrize("lattice", ["diad_ring", "vmx_ring"])
150+
@pytest.mark.parametrize("lattice", ["diad_ring", TESTING_MODE_RING])
150151
@pytest.mark.parametrize("field", ("x", "y"))
151152
def test_bpm_unitconv(lattice, field, request):
152153
lattice = request.getfixturevalue(lattice)
@@ -157,18 +158,18 @@ def test_bpm_unitconv(lattice, field, request):
157158
assert uc.phys_to_eng(2) == 2000
158159

159160

160-
def test_hstr_unitconv(vmx_ring):
161+
def test_hstr_unitconv(i04_ring):
161162
# From MML: hw2physics('HTRIM', 'Monitor', 2.5, [1])
162-
htrim = vmx_ring.get_elements("HTRIM")[0]
163+
htrim = i04_ring.get_elements("HTRIM")[0]
163164
# This test depends on the lattice having an energy of 3000Mev.
164165
uc = htrim._data_source_manager._uc["x_kick"]
165166
numpy.testing.assert_allclose(uc.eng_to_phys(2.5), 0.0001925)
166167
numpy.testing.assert_allclose(uc.phys_to_eng(0.0001925), 2.5)
167168

168169

169-
def test_quad_unitconv(vmx_ring):
170+
def test_quad_unitconv(i04_ring):
170171
# From MML: hw2physics('Q1D', 'Monitor', 70, [1])
171-
q1d = vmx_ring.get_elements("Q1D")
172+
q1d = i04_ring.get_elements("Q1D")
172173
# This test depends on the lattice having an energy of 3000Mev.
173174
for q in q1d:
174175
uc = q._data_source_manager._uc["b1"]

0 commit comments

Comments
 (0)