Files
AareDAQ/tests/unit/utils/test_beamline_dispatch.py
T
perl_d 721e019eae
CI / lint (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
CI / test-with-beamline-plugins (pxi_bec) (push) Skipped
CI / test-with-beamline-plugins (pxii_bec) (push) Skipped
CI / test-with-beamline-plugins (pxiii_bec) (push) Skipped
CI / lint (pull_request) Successful in 41s
CI / test (3.12) (pull_request) Successful in 1m2s
CI / test (3.13) (pull_request) Successful in 1m4s
CI / test (3.14) (pull_request) Successful in 1m11s
CI / test-with-beamline-plugins (pxi_bec) (pull_request) Successful in 1m5s
CI / test-with-beamline-plugins (pxii_bec) (pull_request) Successful in 1m14s
CI / test-with-beamline-plugins (pxiii_bec) (pull_request) Failing after 1m24s
CI / test-with-coverage (pull_request) Successful in 1m43s
CI / coverage-analysis (pull_request) Failing after 9s
feat: add pxiii flux from lookup table
2026-09-10 16:31:26 +02:00

89 lines
3.3 KiB
Python

import importlib.util
from unittest.mock import patch
import numpy as np
import pytest
from aare.beamline_dispatch.beamline_dispatch import get_beamline_dispatch
from aare.beamline_dispatch.simulated import SimulatedDispatch
from aare.beamline_dispatch.x06da import X06daDispatch
from aare.beamline_dispatch.x10sa import X10saDispatch
def test_dispatch_cannot_be_instantiated_without_env():
with patch.dict("os.environ", {}, clear=True), pytest.raises(ValueError) as e:
_ = get_beamline_dispatch()
assert e.match("Please set the BEAMLINE environment variable")
def test_simulated_dispatch_can_be_instantiated():
with patch.dict("os.environ", {"BEAMLINE": "SIMULATED"}):
dispatch = get_beamline_dispatch()
assert isinstance(dispatch, SimulatedDispatch)
@pytest.mark.skipif(importlib.util.find_spec("pxi_bec") is None, reason="run only for pxi flavour")
def test_pxi_dispatch_can_be_instantiated():
with patch.dict("os.environ", {"BEAMLINE": "X06SA"}), pytest.raises(TypeError) as e:
_ = get_beamline_dispatch()
assert e.match("Can't instantiate abstract class")
@pytest.mark.skipif(
importlib.util.find_spec("pxii_bec") is None, reason="run only for pxii flavour"
)
def test_pxii_dispatch_can_be_instantiated():
with patch.dict("os.environ", {"BEAMLINE": "X10SA"}):
dispatch = get_beamline_dispatch()
assert isinstance(dispatch, X10saDispatch)
@pytest.mark.skipif(
importlib.util.find_spec("pxii_bec") is None, reason="run only for pxii flavour"
)
def test_pxii_dispatch_beam_center():
with patch.dict("os.environ", {"BEAMLINE": "X10SA"}):
dispatch = get_beamline_dispatch()
beam_center = dispatch.geo.beam_centre_model.predict(300, 62)
assert np.isclose(beam_center[0][0], 2081.8, atol=1)
assert np.isclose(beam_center[1][0], 2242.05, atol=1)
@pytest.mark.skipif(
importlib.util.find_spec("pxii_bec") is None, reason="run only for pxii flavour"
)
def test_poni_rot_is_0():
with patch.dict("os.environ", {"BEAMLINE": "X10SA"}):
dispatch = get_beamline_dispatch()
assert dispatch.geo.detector_tilt == (0, 0)
@pytest.mark.skipif(
importlib.util.find_spec("pxiii_bec") is None, reason="run only for pxiii flavour"
)
def test_pxiii_dispatch_can_be_instantiated():
with patch.dict("os.environ", {"BEAMLINE": "X06DA"}):
dispatch = get_beamline_dispatch()
assert isinstance(dispatch, X06daDispatch)
@pytest.mark.skipif(
importlib.util.find_spec("pxiii_bec") is None, reason="run only for pxiii flavour"
)
def test_poni_rot_is_not_0():
with patch.dict("os.environ", {"BEAMLINE": "X06DA"}):
dispatch = get_beamline_dispatch()
assert dispatch.geo.detector_tilt != (0, 0)
@pytest.mark.skipif(
importlib.util.find_spec("pxiii_bec") is None, reason="run only for pxiii flavour"
)
def test_flux_table():
with patch.dict("os.environ", {"BEAMLINE": "X06DA"}):
dispatch = get_beamline_dispatch()
with patch.object(dispatch.bec_macros, "get_current_energy", lambda: 4100):
assert np.isclose(dispatch.bec_macros.full_flux_ph_per_s(), 9.6319e09)
with patch.object(dispatch.bec_macros, "get_current_energy", lambda: 15000):
assert np.isclose(dispatch.bec_macros.full_flux_ph_per_s(), 5.0923e10)