Skip to content

Commit

Permalink
Fix controller tests for new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jsouter committed Oct 9, 2024
1 parent faedcbb commit 1744560
Show file tree
Hide file tree
Showing 6 changed files with 1,168 additions and 982 deletions.
11 changes: 4 additions & 7 deletions src/fastcs_eiger/eiger_controller.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
from collections.abc import Coroutine
from collections.abc import Callable, Coroutine
from dataclasses import dataclass
from io import BytesIO
from typing import Any, Callable, Literal
from typing import Any, Literal

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

async def introspect_detector_subsystem(
self, connection: HTTPConnection
) -> list[EigerParameter]:
async def introspect(self, connection: HTTPConnection) -> list[EigerParameter]:
parameters = []
for mode in EIGER_PARAMETER_MODES:
subsystem_keys = [
Expand All @@ -352,7 +350,6 @@ async def introspect_detector_subsystem(
for key, response in zip(subsystem_keys, responses, strict=False)
]
)

return parameters

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

async def initialise(self) -> None:
parameters = await self.subsystem.introspect_detector_subsystem(self.connection)
parameters = await self.subsystem.introspect(self.connection)
await self._create_subcontrollers(parameters)
attributes = _create_attributes(parameters, _key_to_attribute_name)

Expand Down
3 changes: 2 additions & 1 deletion src/fastcs_eiger/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Callable, TypeVar
from collections.abc import Callable
from typing import TypeVar

T = TypeVar("T")

Expand Down
129 changes: 129 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any

import pytest
from pytest_mock import MockerFixture

# Prevent pytest from catching exceptions when debugging in vscode so that break on
# exception works correctly (see: https://github.com/pytest-dev/pytest/issues/7409)
Expand All @@ -19,3 +20,131 @@ def pytest_exception_interact(call: pytest.CallInfo[Any]):
@pytest.hookimpl(tryfirst=True)
def pytest_internalerror(excinfo: pytest.ExceptionInfo[Any]):
raise excinfo.value


_detector_config_keys = [
"auto_summation",
"beam_center_x",
"beam_center_y",
"bit_depth_image",
"bit_depth_readout",
"chi_increment",
"chi_start",
"compression",
"count_time",
"counting_mode",
"countrate_correction_applied",
"countrate_correction_count_cutoff",
"data_collection_date",
"description",
"detector_distance",
"detector_number",
"detector_readout_time",
"eiger_fw_version",
"element",
"extg_mode",
"fast_arm",
"flatfield_correction_applied",
"frame_count_time",
"frame_time",
"incident_energy",
"incident_particle_type",
"instrument_name",
"kappa_increment",
"kappa_start",
"mask_to_zero",
"nexpi",
"nimages",
"ntrigger",
"ntriggers_skipped",
"number_of_excluded_pixels",
"omega_increment",
"omega_start",
"phi_increment",
"phi_start",
"photon_energy",
"pixel_mask_applied",
"roi_mode",
"sample_name",
"sensor_material",
"sensor_thickness",
"software_version",
"source_name",
"threshold/1/energy",
"threshold/1/mode",
"threshold/1/number_of_excluded_pixels",
"threshold/2/energy",
"threshold/2/mode",
"threshold/2/number_of_excluded_pixels",
"threshold/difference/lower_threshold",
"threshold/difference/mode",
"threshold/difference/upper_threshold",
"threshold_energy",
"total_flux",
"trigger_mode",
"trigger_start_delay",
"two_theta_increment",
"two_theta_start",
"virtual_pixel_correction_applied",
"x_pixel_size",
"x_pixels_in_detector",
"y_pixel_size",
"y_pixels_in_detector",
]

_detector_status_keys = [
"humidity",
"link_0",
"link_1",
"series_unique_id",
"state",
"temperature",
"time",
]

_stream_config_keys = [
"format",
"header_appendix",
"header_detail",
"image_appendix",
"mode",
]
_stream_status_keys = ["dropped", "state"]
_monitor_config_keys = ["buffer_size", "discard_new", "mode"]
_monitor_status_keys = ["buffer_free", "dropped", "error", "state"]


@pytest.fixture
def detector_config_keys():
return _detector_config_keys


@pytest.fixture
def detector_status_keys():
return _detector_status_keys


@pytest.fixture
def mock_connection(mocker: MockerFixture):
connection = mocker.patch("fastcs_eiger.http_connection.HTTPConnection")
connection.get = mocker.AsyncMock()

async def _connection_get(uri):
if "detector/api/1.8.0/status/keys" in uri:
return _detector_status_keys
elif "detector/api/1.8.0/config/keys" in uri:
return _detector_config_keys
elif "monitor/api/1.8.0/status/keys" in uri:
return _monitor_status_keys
elif "monitor/api/1.8.0/config/keys" in uri:
return _monitor_config_keys
elif "stream/api/1.8.0/status/keys" in uri:
return _stream_status_keys
elif "stream/api/1.8.0/config/keys" in uri:
return _stream_config_keys
else:
# dummy response
return {"access_mode": "rw", "value": 0.0, "value_type": "float"}

connection.get.side_effect = _connection_get
return connection
Loading

0 comments on commit 1744560

Please sign in to comment.