Fixes Tests

This commit is contained in:
2025-06-04 01:21:23 -03:00
parent 4bbb896c46
commit dbbb8e0419
2 changed files with 14 additions and 35 deletions

View File

@@ -1,41 +1,21 @@
from jambo.parser import StringTypeParser
from jambo.parser._type_parser import GenericTypeParser
import gc
from contextlib import contextmanager
from unittest import TestCase
@contextmanager
def with_test_parser():
class InvalidGenericTypeParser(GenericTypeParser):
mapped_type = str
json_schema_type = "type:invalid"
def from_properties_impl(
self, name: str, properties: dict[str, any], required: bool = False
): ...
try:
yield InvalidGenericTypeParser
finally:
del InvalidGenericTypeParser
gc.collect()
class TestGenericTypeParser(TestCase):
def test_invalid_get_impl(self):
# Assuming GenericTypeParser is imported from the module
with (
with_test_parser(),
self.assertRaises(ValueError),
):
GenericTypeParser._get_impl({"type": "another_invalid_type"})
def test_get_impl(self):
parser = GenericTypeParser._get_impl({"type": "string"})
def test_invalid_json_schema_type(self):
# This is more for the developer's sanity check
with (
with_test_parser() as InvalidGenericTypeParser,
self.assertRaises(RuntimeError),
):
InvalidGenericTypeParser.json_schema_type = None
GenericTypeParser._get_impl({"type": "another_invalid_type"})
self.assertIsInstance(parser(), StringTypeParser)
def test_get_impl_invalid_json_schema(self):
with self.assertRaises(RuntimeError):
StringTypeParser.json_schema_type = None
GenericTypeParser._get_impl({"type": "string"})
StringTypeParser.json_schema_type = "type:string"
def test_get_impl_invalid_type(self):
with self.assertRaises(ValueError):
GenericTypeParser._get_impl({"type": "invalid_type"})