Files
AareDAQ/tests/unit/common/test_error_codes.py
T
appleb_m f2581f0684
Build and Publish / test (push) Successful in 1m30s
Build and Publish / build (push) Successful in 18s
Build and Publish / Build and Deploy Docs (push) Successful in 39s
EXCEPTION REFACTOR: Large scale exception refactor mdipoint, to be tested. If broken scale back this commit and fix tests
2026-06-03 16:43:42 +02:00

83 lines
3.5 KiB
Python

from aare.common.error_codes import (
AuthErrorCode,
AareErrorCode,
code_for_exception_class,
error_code_help,
export_error_codes,
export_error_codes_grouped,
)
def test_error_code_help_returns_string():
help_text = error_code_help(AuthErrorCode.AUTHENTICATION_FAILED)
assert isinstance(help_text, str)
assert len(help_text) > 0
def test_error_code_help_unknown_code():
help_text = error_code_help("UNKNOWN_CODE")
assert help_text is None
def test_export_error_codes_contains_known_codes():
exported = export_error_codes()
assert AuthErrorCode.AUTHENTICATION_FAILED.name in exported
def test_code_for_exception_class_basic():
assert code_for_exception_class("TellCommunicationError") == "TELL_COMMUNICATION_ERROR"
assert code_for_exception_class("MountingFailed") == "MOUNTING_FAILED"
assert code_for_exception_class("LoopCenteringFailed") == "LOOP_CENTERING_FAILED"
def test_code_for_exception_class_acronyms():
assert code_for_exception_class("AXCFailed") == "AXC_FAILED"
assert code_for_exception_class("AareDBCommunicationError") == "AARE_DB_COMMUNICATION_ERROR"
assert code_for_exception_class("JFJochCommunicationError") == "JF_JOCH_COMMUNICATION_ERROR"
def test_code_for_each_concrete_exception_is_in_aare_error_code_enum():
"""Every code we'd produce from the rebuilt hierarchy must exist in the
AareErrorCode enum -- otherwise clients have no symbol to branch on."""
from aare.common.exception_handler import (
TellCommunicationError, TellConnectionException, CriticalTellException,
WarningTellException, TellCommandWhileBusyException,
MountingFailed, UnmountingFailed,
SmargonCommunicationError, AerotechCommunicationError,
JFJochCommunicationError, BECCommunicationError,
AareDBCommunicationError, StateTransitionFailed,
MaintenanceStateException, BeamlineBusyException,
BeamlineBusyTimeoutException, DataCollectionException,
RasterScanException, LoopCenteringFailed, AXCFailed,
AutoRasterSampleSkipped, TransformationInvalidException,
MagnetPositionSensorErorr, SmartMagnetFaultException,
ManualMountException, SampleException, AuthenticationException,
UserRightsException,
)
valid = {c.value for c in AareErrorCode}
classes = [
TellCommunicationError, TellConnectionException, CriticalTellException,
WarningTellException, TellCommandWhileBusyException,
MountingFailed, UnmountingFailed,
SmargonCommunicationError, AerotechCommunicationError,
JFJochCommunicationError, BECCommunicationError,
AareDBCommunicationError, StateTransitionFailed,
MaintenanceStateException, BeamlineBusyException,
BeamlineBusyTimeoutException, DataCollectionException,
RasterScanException, LoopCenteringFailed, AXCFailed,
AutoRasterSampleSkipped, TransformationInvalidException,
MagnetPositionSensorErorr, SmartMagnetFaultException,
ManualMountException, SampleException, AuthenticationException,
UserRightsException,
]
missing = []
for cls in classes:
code = code_for_exception_class(cls.__name__)
if code not in valid:
missing.append((cls.__name__, code))
assert not missing, f"Codes missing from AareErrorCode: {missing}"
def test_export_error_codes_grouped_includes_aare_error_code():
exported = export_error_codes_grouped()
assert "AareErrorCode" in exported
assert "AuthErrorCode" in exported
assert "TELL_COMMUNICATION_ERROR" in exported["AareErrorCode"]