Skip to content

Commit b9384f3

Browse files
committed
Fix controller tests for new structure
1 parent faedcbb commit b9384f3

File tree

6 files changed

+1173
-984
lines changed

6 files changed

+1173
-984
lines changed

src/fastcs_eiger/eiger_controller.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import asyncio
2-
from collections.abc import Coroutine
2+
from collections.abc import Callable, Coroutine
33
from dataclasses import dataclass
44
from io import BytesIO
5-
from typing import Any, Callable, Literal
5+
from typing import Any, Literal
66

77
import numpy as np
88
from fastcs.attributes import Attribute, AttrR, AttrRW, AttrW
@@ -326,9 +326,7 @@ def __init__(
326326
self.stale = False
327327
self.attribute_mapping: dict[str, AttrR] = {}
328328

329-
async def introspect_detector_subsystem(
330-
self, connection: HTTPConnection
331-
) -> list[EigerParameter]:
329+
async def introspect(self, connection: HTTPConnection) -> list[EigerParameter]:
332330
parameters = []
333331
for mode in EIGER_PARAMETER_MODES:
334332
subsystem_keys = [
@@ -352,7 +350,6 @@ async def introspect_detector_subsystem(
352350
for key, response in zip(subsystem_keys, responses, strict=False)
353351
]
354352
)
355-
356353
return parameters
357354

358355
async def queue_update(self, parameters: list[str]):
@@ -380,7 +377,7 @@ def __init__(self, subsystem: Subsystem, connection: HTTPConnection):
380377
super().__init__()
381378

382379
async def initialise(self) -> None:
383-
parameters = await self.subsystem.introspect_detector_subsystem(self.connection)
380+
parameters = await self.subsystem.introspect(self.connection)
384381
await self._create_subcontrollers(parameters)
385382
attributes = _create_attributes(parameters, _key_to_attribute_name)
386383

src/fastcs_eiger/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Callable, TypeVar
1+
from collections.abc import Callable
2+
from typing import TypeVar
23

34
T = TypeVar("T")
45

tests/conftest.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any
33

44
import pytest
5+
from pytest_mock import MockerFixture
56

67
# Prevent pytest from catching exceptions when debugging in vscode so that break on
78
# exception works correctly (see: https://github.com/pytest-dev/pytest/issues/7409)
@@ -19,3 +20,131 @@ def pytest_exception_interact(call: pytest.CallInfo[Any]):
1920
@pytest.hookimpl(tryfirst=True)
2021
def pytest_internalerror(excinfo: pytest.ExceptionInfo[Any]):
2122
raise excinfo.value
23+
24+
25+
_detector_config_keys = [
26+
"auto_summation",
27+
"beam_center_x",
28+
"beam_center_y",
29+
"bit_depth_image",
30+
"bit_depth_readout",
31+
"chi_increment",
32+
"chi_start",
33+
"compression",
34+
"count_time",
35+
"counting_mode",
36+
"countrate_correction_applied",
37+
"countrate_correction_count_cutoff",
38+
"data_collection_date",
39+
"description",
40+
"detector_distance",
41+
"detector_number",
42+
"detector_readout_time",
43+
"eiger_fw_version",
44+
"element",
45+
"extg_mode",
46+
"fast_arm",
47+
"flatfield_correction_applied",
48+
"frame_count_time",
49+
"frame_time",
50+
"incident_energy",
51+
"incident_particle_type",
52+
"instrument_name",
53+
"kappa_increment",
54+
"kappa_start",
55+
"mask_to_zero",
56+
"nexpi",
57+
"nimages",
58+
"ntrigger",
59+
"ntriggers_skipped",
60+
"number_of_excluded_pixels",
61+
"omega_increment",
62+
"omega_start",
63+
"phi_increment",
64+
"phi_start",
65+
"photon_energy",
66+
"pixel_mask_applied",
67+
"roi_mode",
68+
"sample_name",
69+
"sensor_material",
70+
"sensor_thickness",
71+
"software_version",
72+
"source_name",
73+
"threshold/1/energy",
74+
"threshold/1/mode",
75+
"threshold/1/number_of_excluded_pixels",
76+
"threshold/2/energy",
77+
"threshold/2/mode",
78+
"threshold/2/number_of_excluded_pixels",
79+
"threshold/difference/lower_threshold",
80+
"threshold/difference/mode",
81+
"threshold/difference/upper_threshold",
82+
"threshold_energy",
83+
"total_flux",
84+
"trigger_mode",
85+
"trigger_start_delay",
86+
"two_theta_increment",
87+
"two_theta_start",
88+
"virtual_pixel_correction_applied",
89+
"x_pixel_size",
90+
"x_pixels_in_detector",
91+
"y_pixel_size",
92+
"y_pixels_in_detector",
93+
]
94+
95+
_detector_status_keys = [
96+
"humidity",
97+
"link_0",
98+
"link_1",
99+
"series_unique_id",
100+
"state",
101+
"temperature",
102+
"time",
103+
]
104+
105+
_stream_config_keys = [
106+
"format",
107+
"header_appendix",
108+
"header_detail",
109+
"image_appendix",
110+
"mode",
111+
]
112+
_stream_status_keys = ["dropped", "state"]
113+
_monitor_config_keys = ["buffer_size", "discard_new", "mode"]
114+
_monitor_status_keys = ["buffer_free", "dropped", "error", "state"]
115+
116+
117+
@pytest.fixture
118+
def detector_config_keys():
119+
return _detector_config_keys
120+
121+
122+
@pytest.fixture
123+
def detector_status_keys():
124+
return _detector_status_keys
125+
126+
127+
@pytest.fixture
128+
def mock_connection(mocker: MockerFixture):
129+
connection = mocker.patch("fastcs_eiger.http_connection.HTTPConnection")
130+
connection.get = mocker.AsyncMock()
131+
132+
async def _connection_get(uri):
133+
if "detector/api/1.8.0/status/keys" in uri:
134+
return _detector_status_keys
135+
elif "detector/api/1.8.0/config/keys" in uri:
136+
return _detector_config_keys
137+
elif "monitor/api/1.8.0/status/keys" in uri:
138+
return _monitor_status_keys
139+
elif "monitor/api/1.8.0/config/keys" in uri:
140+
return _monitor_config_keys
141+
elif "stream/api/1.8.0/status/keys" in uri:
142+
return _stream_status_keys
143+
elif "stream/api/1.8.0/config/keys" in uri:
144+
return _stream_config_keys
145+
else:
146+
# dummy response
147+
return {"access_mode": "rw", "value": 0.0, "value_type": "float"}
148+
149+
connection.get.side_effect = _connection_get
150+
return connection

0 commit comments

Comments
 (0)