From 4ac9587abcca2c3036f635381f9935ace1953eb3 Mon Sep 17 00:00:00 2001 From: David Perl Date: Wed, 8 Jul 2026 11:44:30 +0200 Subject: [PATCH 1/2] fix: crash on bec init failure; beamline must be set explicitly --- src/aarecommon/config/beamline.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/aarecommon/config/beamline.py b/src/aarecommon/config/beamline.py index 9f18142..8ca01e8 100644 --- a/src/aarecommon/config/beamline.py +++ b/src/aarecommon/config/beamline.py @@ -29,9 +29,13 @@ class BeamlineYAMLConfig: def mx_beamline() -> MXBeamline: name = os.getenv("BEAMLINE") if name is None: - return MXBeamline.SIMULATED + raise ValueError("Please set the BEAMLINE environment variable to run AareDAQ") name = name.strip().upper() - return MXBeamline[name] if name in MXBeamline.__members__ else MXBeamline.SIMULATED + if name in MXBeamline.__members__: + return MXBeamline[name] + raise ValueError( + f"{name} is not a valid value for BEAMLINE. Please set one of {MXBeamline.__members__}" + ) def get_jfjoch_url(bl: MXBeamline) -> str: -- 2.54.0 From 3764c987b063fadc4b95286536613e8ee7fded8b Mon Sep 17 00:00:00 2001 From: David Perl Date: Wed, 8 Jul 2026 11:48:46 +0200 Subject: [PATCH 2/2] test: update test for env var --- tests/test_beamline.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/test_beamline.py b/tests/test_beamline.py index acc8ea5..dadcb9c 100644 --- a/tests/test_beamline.py +++ b/tests/test_beamline.py @@ -1,14 +1,18 @@ import os from unittest.mock import patch -from aarecommon.models.beamline import MXBeamline +import pytest + from aarecommon.config.beamline import mx_beamline +from aarecommon.models.beamline import MXBeamline def test_mx_beamline_default(): with patch.dict(os.environ, {}, clear=True): - # If BEAMLINE is not set, it should return SIMULATED - assert mx_beamline() == MXBeamline.SIMULATED + with pytest.raises(ValueError) as e: + # If BEAMLINE is not set, it should raise + mx_beamline() + assert e.match("set the BEAMLINE") def test_mx_beamline_x10sa(): @@ -22,5 +26,7 @@ def test_mx_beamline_x06sa(): def test_mx_beamline_invalid(): - with patch.dict(os.environ, {"BEAMLINE": "INVALID"}): - assert mx_beamline() == MXBeamline.SIMULATED + with pytest.raises(ValueError) as e: + with patch.dict(os.environ, {"BEAMLINE": "INVALID"}): + mx_beamline() + assert e.match("not a valid value") -- 2.54.0