Files
CoreRasurae e828acf175
CI / lint (push) Successful in 1m32s
CI / typecheck (push) Successful in 1m38s
CI / lint (pull_request) Successful in 1m30s
CI / typecheck (pull_request) Successful in 1m30s
CI / behave (3.11) (pull_request) Successful in 1m39s
CI / behave (3.12) (pull_request) Successful in 1m39s
CI / build (pull_request) Successful in 1m29s
CI / behave (3.13) (pull_request) Successful in 1m39s
CI / behave (3.11) (push) Successful in 1m39s
CI / behave (3.12) (push) Successful in 1m41s
CI / behave (3.13) (push) Successful in 1m37s
CI / build (push) Successful in 1m30s
feat: Initial version of CleverRDFLib
ISSUES CLOSED: #1
2025-12-19 22:26:14 +00:00

188 lines
5.7 KiB
Python

"""
Step definitions for exception handling feature tests.
This module implements tests for exception classes,
ensuring they are properly instantiated and can be used.
"""
from __future__ import annotations
from typing import Any
from behave import given, then, when
from cleverrdf_lib.core.exceptions import (
ClassConversionException,
ClassHierarchyBuildException,
ClassNodeNotFoundException,
CleverRDFLibException,
DataTypeConversionException,
GraphLoaderHandlerInsertionFailed,
InconsistentClassHierarchyException,
PropertyConversionException,
PropertyDomainObjectNotFoundException,
PropertyRangeObjectNotFoundException,
)
@given("I create a CleverRDFLibException with a non-exception cause")
def step_create_exception_with_non_exception_cause(context: Any) -> None:
"""
Create a CleverRDFLibException with a non-exception cause.
This tests the branch where cause is not an exception.
"""
context.exception = CleverRDFLibException("Test message", cause="non-exception cause")
@when("I access the exception message")
def step_access_exception_message(context: Any) -> None:
"""
Access the exception message.
This tests message retrieval.
"""
context.exception_message = str(context.exception)
@then("I should receive the message with the cause appended")
def step_receive_message_with_cause(context: Any) -> None:
"""
Verify that the message includes the cause.
This checks message formatting.
"""
assert "non-exception cause" in context.exception_message, "Message should include cause"
@given("I create a CleverRDFLibException with an exception cause")
def step_create_exception_with_exception_cause(context: Any) -> None:
"""
Create a CleverRDFLibException with an exception cause.
This tests the branch where cause is an exception.
"""
cause = ValueError("Underlying error")
context.exception = CleverRDFLibException("Test message", cause=cause)
@when("I call get_cause on the exception")
def step_call_get_cause(context: Any) -> None:
"""
Call get_cause on the exception.
This tests cause retrieval.
"""
context.retrieved_cause = context.exception.get_cause()
@then("I should receive the underlying exception")
def step_receive_underlying_exception(context: Any) -> None:
"""
Verify that the underlying exception was returned.
This checks cause retrieval.
"""
assert context.retrieved_cause is not None, "Cause should not be None"
assert isinstance(context.retrieved_cause, ValueError), "Cause should be ValueError"
@given("I create a ClassNodeNotFoundException")
def step_create_class_node_not_found_exception(context: Any) -> None:
"""
Create a ClassNodeNotFoundException instance.
This tests exception instantiation.
"""
context.exception = ClassNodeNotFoundException("Class not found")
@then("the exception should be a CleverRDFLibException")
def step_exception_is_cleverrdf_lib_exception(context: Any) -> None:
"""
Verify that the exception is a CleverRDFLibException.
This checks exception inheritance.
"""
assert isinstance(context.exception, CleverRDFLibException), "Exception should be CleverRDFLibException"
@given("I create a PropertyDomainObjectNotFoundException")
def step_create_property_domain_not_found_exception(context: Any) -> None:
"""
Create a PropertyDomainObjectNotFoundException instance.
This tests exception instantiation.
"""
context.exception = PropertyDomainObjectNotFoundException("Domain object not found")
@given("I create a PropertyRangeObjectNotFoundException")
def step_create_property_range_not_found_exception(context: Any) -> None:
"""
Create a PropertyRangeObjectNotFoundException instance.
This tests exception instantiation.
"""
context.exception = PropertyRangeObjectNotFoundException("Range object not found")
@given("I create a GraphLoaderHandlerInsertionFailed exception")
def step_create_graph_loader_handler_insertion_failed(context: Any) -> None:
"""
Create a GraphLoaderHandlerInsertionFailed exception instance.
This tests exception instantiation.
"""
context.exception = GraphLoaderHandlerInsertionFailed("Handler insertion failed")
@given("I create a ClassHierarchyBuildException")
def step_create_class_hierarchy_build_exception(context: Any) -> None:
"""
Create a ClassHierarchyBuildException instance.
This tests exception instantiation.
"""
context.exception = ClassHierarchyBuildException("Build failed")
@given("I create a ClassConversionException")
def step_create_class_conversion_exception(context: Any) -> None:
"""
Create a ClassConversionException instance.
This tests exception instantiation.
"""
context.exception = ClassConversionException("Class conversion failed")
@given("I create a PropertyConversionException")
def step_create_property_conversion_exception(context: Any) -> None:
"""
Create a PropertyConversionException instance.
This tests exception instantiation.
"""
context.exception = PropertyConversionException("Property conversion failed")
@given("I create a DataTypeConversionException")
def step_create_datatype_conversion_exception(context: Any) -> None:
"""
Create a DataTypeConversionException instance.
This tests exception instantiation.
"""
context.exception = DataTypeConversionException("DataType conversion failed")
@given("I create an InconsistentClassHierarchyException")
def step_create_inconsistent_class_hierarchy_exception(context: Any) -> None:
"""
Create an InconsistentClassHierarchyException instance.
This tests exception instantiation.
"""
context.exception = InconsistentClassHierarchyException("Inconsistent hierarchy")