feat: fixes tests to validate the type of exception thrown

This commit is contained in:
2025-09-14 00:47:24 -03:00
parent 30290771b1
commit e31002af32
17 changed files with 179 additions and 124 deletions

View File

@@ -1,5 +1,10 @@
from .internal_assertion_exception import InternalAssertionException
from .invalid_schema_exception import InvalidSchemaException
from .unsupported_schema_exception import UnsupportedSchemaException
__all__ = ["InvalidSchemaException", "UnsupportedSchemaException"]
__all__ = [
"InternalAssertionException",
"InvalidSchemaException",
"UnsupportedSchemaException",
]

View File

@@ -0,0 +1,16 @@
class InternalAssertionException(AssertionError):
"""Exception raised for internal assertions."""
def __init__(
self,
message: str,
) -> None:
# Normalize message by stripping redundant prefix if present
message = message.removeprefix("Internal Assertion Failed: ")
super().__init__(message)
def __str__(self) -> str:
return (
f"Internal Assertion Failed: {super().__str__()}\n"
"This is likely a bug in Jambo. Please report it at"
)

View File

@@ -1,4 +1,4 @@
from jambo.exceptions import InvalidSchemaException
from jambo.exceptions import InternalAssertionException, InvalidSchemaException
from jambo.parser import GenericTypeParser
from jambo.types.json_schema_type import JSONSchema
from jambo.types.type_parser_options import TypeParserOptions
@@ -22,17 +22,15 @@ class RefTypeParser(GenericTypeParser):
f"Missing $ref in properties for {name}", invalid_field="$ref"
)
context = kwargs.get("context")
if context is None:
raise InvalidSchemaException(
f"Missing `context` in properties for {name}", invalid_field="context"
if kwargs.get("context") is None:
raise InternalAssertionException(
"`context` must be provided in kwargs for RefTypeParser"
)
ref_cache = kwargs.get("ref_cache")
if ref_cache is None:
raise InvalidSchemaException(
f"Missing `ref_cache` in properties for {name}",
invalid_field="ref_cache",
raise InternalAssertionException(
"`ref_cache` must be provided in kwargs for RefTypeParser"
)
mapped_properties = self.mappings_properties_builder(properties, **kwargs)

View File

@@ -23,19 +23,19 @@ class StringTypeParser(GenericTypeParser):
}
format_type_mapping = {
# 7.3.1. Dates, Times, and Duration
# [7.3.1](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.7.3.1). Dates, Times, and Duration
"date": date,
"time": time,
"date-time": datetime,
"duration": timedelta,
# 7.3.2. Email Addresses
# [7.3.2](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.7.3.2). Email Addresses
"email": EmailStr,
# 7.3.3. Hostnames
# [7.3.3](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.7.3.3). Hostnames
"hostname": str,
# 7.3.4. IP Addresses
# [7.3.4](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.7.3.4). IP Addresses
"ipv4": IPv4Address,
"ipv6": IPv6Address,
# 7.3.5. Resource Identifiers
# [7.3.5](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.7.3.5). Resource Identifiers
"uri": AnyUrl,
# "iri" # Not supported by pydantic and currently not supported by jambo
"uuid": UUID,