Fixes Test and Reports

This commit is contained in:
2025-06-03 03:00:49 -03:00
parent 782e09d5e3
commit 3273fd84bf

View File

@@ -1,10 +1,12 @@
from jambo.parser._type_parser import GenericTypeParser from jambo.parser._type_parser import GenericTypeParser
import gc
from contextlib import contextmanager
from unittest import TestCase from unittest import TestCase
class TestGenericTypeParser(TestCase): @contextmanager
def setUp(self): def with_test_parser():
class InvalidGenericTypeParser(GenericTypeParser): class InvalidGenericTypeParser(GenericTypeParser):
mapped_type = str mapped_type = str
json_schema_type = "type:invalid" json_schema_type = "type:invalid"
@@ -13,26 +15,35 @@ class TestGenericTypeParser(TestCase):
self, name: str, properties: dict[str, any], required: bool = False self, name: str, properties: dict[str, any], required: bool = False
): ... ): ...
if hasattr(self, "InvalidGenericTypeParser"): try:
delattr(self, "InvalidGenericTypeParser") yield InvalidGenericTypeParser
self.InvalidGenericTypeParser = InvalidGenericTypeParser finally:
del InvalidGenericTypeParser
gc.collect()
def tearDown(self):
del self.InvalidGenericTypeParser
class TestGenericTypeParser(TestCase):
def test_invalid_get_impl(self): def test_invalid_get_impl(self):
# Assuming GenericTypeParser is imported from the module # Assuming GenericTypeParser is imported from the module
with self.assertRaises(ValueError): with (
with_test_parser(),
self.assertRaises(ValueError),
):
GenericTypeParser._get_impl({"type": "another_invalid_type"}) GenericTypeParser._get_impl({"type": "another_invalid_type"})
def test_invalid_json_schema_type(self): def test_invalid_json_schema_type(self):
self.InvalidGenericTypeParser.json_schema_type = None
# This is more for the developer's sanity check # This is more for the developer's sanity check
with self.assertRaises(RuntimeError): with (
with_test_parser() as InvalidGenericTypeParser,
self.assertRaises(RuntimeError),
):
InvalidGenericTypeParser.json_schema_type = None
GenericTypeParser._get_impl({"type": "another_invalid_type"}) GenericTypeParser._get_impl({"type": "another_invalid_type"})
def test_invalid_mappings_properties_builder(self): def test_invalid_mappings_properties_builder(self):
parser = self.InvalidGenericTypeParser() with (
with self.assertRaises(NotImplementedError): with_test_parser() as InvalidGenericTypeParser,
self.assertRaises(NotImplementedError),
):
parser = InvalidGenericTypeParser()
parser.mappings_properties_builder({}, required=False) parser.mappings_properties_builder({}, required=False)