fix: crash on bec init failure; beamline must be set explicitly #6
@@ -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:
|
||||
|
||||
+11
-5
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user