import pytest from ocpp.exceptions import ( FormatViolationError, ProtocolError, TypeConstraintViolationError, ) from ocpp.messages import Call, validate_payload def test_exception_with_error_details(): exception = ProtocolError("Some error", {"key": "value"}) assert exception.description == "Some error" assert exception.details == {"key": "value"} def test_exception_without_error_details(): exception = ProtocolError() assert exception.description == "Payload for Action is incomplete" assert exception.details == {} def test_exception_show_triggered_message_type_constraint(): # chargePointVendor should be a string, not an integer, # so this should raise a TypeConstraintViolationError call = Call( unique_id=123456, action="BootNotification", payload={"chargePointVendor": 1, "chargePointModel": "SingleSocketCharger"}, ) ocpp_message = ( "'ocpp_message':