Better Object Internal Structure and Type Selection

This commit is contained in:
2025-06-03 00:15:19 -03:00
parent 894969332d
commit bef42e4cdb
12 changed files with 140 additions and 140 deletions

View File

@@ -3,29 +3,34 @@ from jambo.parser._type_parser import GenericTypeParser
from unittest import TestCase
class InvalidGenericTypeParser(GenericTypeParser):
mapped_type = str
json_schema_type = "invalid"
def from_properties(
self, name: str, properties: dict[str, any], required: bool = False
): ...
class TestGenericTypeParser(TestCase):
def setUp(self):
class InvalidGenericTypeParser(GenericTypeParser):
mapped_type = str
json_schema_type = "type:invalid"
def from_properties(
self, name: str, properties: dict[str, any], required: bool = False
): ...
self.InvalidGenericTypeParser = InvalidGenericTypeParser
def tearDown(self):
del self.InvalidGenericTypeParser
def test_invalid_get_impl(self):
# Assuming GenericTypeParser is imported from the module
with self.assertRaises(ValueError):
GenericTypeParser.get_impl("another_invalid_type")
GenericTypeParser._get_impl({"type": "another_invalid_type"})
def test_invalid_json_schema_type(self):
InvalidGenericTypeParser.json_schema_type = None
self.InvalidGenericTypeParser.json_schema_type = None
# This is more for the developer's sanity check
with self.assertRaises(RuntimeError):
GenericTypeParser.get_impl("another_invalid_type")
GenericTypeParser._get_impl({"type": "another_invalid_type"})
def test_invalid_mappings_properties_builder(self):
parser = InvalidGenericTypeParser()
parser = self.InvalidGenericTypeParser()
with self.assertRaises(NotImplementedError):
parser.mappings_properties_builder({}, required=False)

View File

@@ -24,20 +24,6 @@ class TestSchemaConverter(TestCase):
with self.assertRaises(ValueError):
SchemaConverter.build(schema)
def test_build_expects_valid_schema(self):
invalid_schema = {
"type": "object",
"properties": {
"name": {
"type": "strng"
} # typo: "strng" is not a valid JSON Schema type
},
"required": ["name"],
}
with self.assertRaises(ValueError):
SchemaConverter.build_object("placeholder", invalid_schema)
def test_build_expects_object(self):
schema = {
"title": "Person",
@@ -61,8 +47,9 @@ class TestSchemaConverter(TestCase):
# 'required': ['name', 'age', 'is_active', 'friends', 'address'],
}
with self.assertRaises(ValueError):
with self.assertRaises(ValueError) as context:
SchemaConverter.build(schema)
self.assertTrue("Unknown type" in str(context.exception))
def test_jsonschema_to_pydantic(self):
schema = {