exception hadnling updates
This commit is contained in:
1 parent
3654e126e6
commit
3801c11e8d
3 files changed
+510
-349
No files matched your search
@@ -1,4 +1,12 @@
|
||||
from aare.common.error_codes import AuthErrorCode, DAQErrorCode, error_code_help, export_error_codes
|
||||
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)
|
||||
@@ -12,3 +20,65 @@ def test_error_code_help_unknown_code():
|
||||
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"]
|
||||
Reference in new issue
Block a user