From dbbb8e04191fc933def275f18be4a04e4f51224f Mon Sep 17 00:00:00 2001 From: Vitor Hideyoshi Date: Wed, 4 Jun 2025 01:21:23 -0300 Subject: [PATCH] Fixes Tests --- jambo/parser/_type_parser.py | 1 - tests/parser/test_type_parser.py | 48 ++++++++++---------------------- 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/jambo/parser/_type_parser.py b/jambo/parser/_type_parser.py index 1dc07d3..dbe098a 100644 --- a/jambo/parser/_type_parser.py +++ b/jambo/parser/_type_parser.py @@ -30,7 +30,6 @@ class GenericTypeParser(ABC, Generic[T]): :param kwargs: Additional options for type parsing. :return: A tuple containing the type and its properties. """ - pass def from_properties( self, name: str, properties: dict[str, Any], **kwargs: Unpack[TypeParserOptions] diff --git a/tests/parser/test_type_parser.py b/tests/parser/test_type_parser.py index 1bf2687..195297b 100644 --- a/tests/parser/test_type_parser.py +++ b/tests/parser/test_type_parser.py @@ -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"}) \ No newline at end of file