Files
AareDAQ/tests/unit/common/test_exception_handler.py
T

138 lines
4.2 KiB
Python

import pytest
from aare.common.exception_handler import (
DataCollectionException,
AuthenticationException,
AuthErrorCode,
TellCommunicationError,
TransformationInvalidException,
RasterScanException,
LoopCenteringFailed,
UnmountingFailed,
MountingFailed,
ManualMountException,
SmartMagnetFaultException,
TellMountFailedException,
TellCommandWhileBusyException,
TellConnectionException,
WarningTellException,
CriticalTellException,
AXCFailed,
BeamlineBusyException,
SampleException,
UserRightsException,
SmargonCommunicationError,
JFJochCommunicationError,
AareDBCommunicationError,
AerotechCommunicationError,
MagnetPositionSensorErorr
)
def test_data_collection_exception_message():
exc = DataCollectionException("Custom error")
assert str(exc) == "Custom error"
def test_data_collection_exception_default_message():
exc = DataCollectionException()
assert str(exc) == "Data collection failed"
def test_authentication_exception_properties():
exc = AuthenticationException("Failed", status_code=403, code=AuthErrorCode.FORBIDDEN)
assert exc.status_code == 403
assert exc.code == AuthErrorCode.FORBIDDEN
assert "Failed" in str(exc)
def test_tell_communication_error_str():
exc = TellCommunicationError("Timeout", endpoint="/state", operation="GET")
assert str(exc) == "Timeout"
assert exc.endpoint == "/state"
assert exc.operation == "GET"
def test_transformation_invalid_exception():
exc = TransformationInvalidException()
assert "Transformation is not implemented" in str(exc)
def test_raster_scan_exception():
exc = RasterScanException("Raster failed")
assert "Raster failed" in str(exc)
def test_loop_centering_failed():
exc = LoopCenteringFailed()
assert "Loop Centering did not detect a sample" in str(exc)
def test_unmounting_failed():
exc = UnmountingFailed()
assert "A sample was not unmounted" in str(exc)
def test_mounting_failed():
exc = MountingFailed()
assert "A sample was not mounted" in str(exc)
def test_manual_mount_exception():
exc = ManualMountException()
assert "Manual mounting failed" in str(exc)
def test_smart_magnet_fault_exception():
exc = SmartMagnetFaultException()
assert "Smart magnet fault" in str(exc)
def test_tell_mount_failed_exception():
exc = TellMountFailedException()
assert "Tell mount failed" in str(exc)
def test_tell_command_while_busy_exception():
exc = TellCommandWhileBusyException()
assert "Tell is busy" in str(exc)
def test_tell_connection_exception():
exc = TellConnectionException()
assert "Lost connection to Tell" in str(exc)
def test_warning_tell_exception():
exc = WarningTellException()
assert "Warning error in TELL" in str(exc)
def test_critical_tell_exception():
exc = CriticalTellException()
assert "Critical error in TELL" in str(exc)
def test_axc_failed():
exc = AXCFailed()
assert "Auto X-ray centering failed" in str(exc)
def test_beamline_busy_exception():
exc = BeamlineBusyException()
assert "Beamline is in busy state" in str(exc)
def test_sample_exception():
exc = SampleException()
assert "Sample not found" in str(exc)
def test_user_rights_exception():
exc = UserRightsException(code=AuthErrorCode.NOT_STAFF)
assert exc.status_code == 403
assert exc.code == AuthErrorCode.NOT_STAFF
assert "User does not have rights" in str(exc)
def test_smargon_communication_error():
exc = SmargonCommunicationError("Conn error", endpoint="/move", status_code=500)
assert str(exc) == "Conn error"
assert exc.endpoint == "/move"
assert exc.status_code == 500
def test_jfjoch_communication_error():
exc = JFJochCommunicationError("JFJoch error", operation="POST")
assert str(exc) == "JFJoch error"
assert exc.operation == "POST"
def test_aaredb_communication_error():
exc = AareDBCommunicationError("DB error")
assert "DB error" in str(exc)
def test_aerotech_communication_error():
exc = AerotechCommunicationError("Aerotech error")
assert "Aerotech error" in str(exc)
def test_magnet_position_sensor_error():
exc = MagnetPositionSensorErorr()
assert "Magnet position sensor error" in str(exc)