2
2
from typing import Any
3
3
4
4
import pytest
5
+ from pytest_mock import MockerFixture
5
6
6
7
# Prevent pytest from catching exceptions when debugging in vscode so that break on
7
8
# exception works correctly (see: https://github.com/pytest-dev/pytest/issues/7409)
@@ -19,3 +20,131 @@ def pytest_exception_interact(call: pytest.CallInfo[Any]):
19
20
@pytest .hookimpl (tryfirst = True )
20
21
def pytest_internalerror (excinfo : pytest .ExceptionInfo [Any ]):
21
22
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