85 lines
3.7 KiB
Python
85 lines
3.7 KiB
Python
from aare.common.error_codes import (
|
|
AuthErrorCode,
|
|
DAQErrorCode,
|
|
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,
|
|
TellMountFailedException, 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,
|
|
TellMountFailedException, 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 "DAQErrorCode" in exported
|
|
assert "AuthErrorCode" in exported
|
|
assert "TELL_COMMUNICATION_ERROR" in exported["AareErrorCode"]
|