Merge pull request #32 from fredsonnenwald/add-null

Add null type parser
This commit was merged in pull request #32.
This commit is contained in:
2025-08-18 23:39:11 -03:00
committed by GitHub
4 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
from jambo.parser import NullTypeParser
from unittest import TestCase
class TestNullTypeParser(TestCase):
def test_null_parser_no_options(self):
parser = NullTypeParser()
properties = {"type": "null"}
type_parsing, type_validator = parser.from_properties_impl(
"placeholder", properties
)
self.assertEqual(type_parsing, type(None))
self.assertEqual(type_validator, {"default": None})
def test_null_parser_with_invalid_default(self):
parser = NullTypeParser()
properties = {"type": "null", "default": "invalid"}
type_parsing, type_validator = parser.from_properties_impl(
"placeholder", properties
)
self.assertEqual(type_parsing, type(None))
self.assertEqual(type_validator, {"default": None})

View File

@@ -700,3 +700,23 @@ class TestSchemaConverter(TestCase):
with self.assertRaises(ValueError):
Model(name="Canada")
def test_null_type_parser(self):
schema = {
"title": "Test",
"type": "object",
"properties": {
"a_thing": {"type": "null"},
},
}
Model = SchemaConverter.build(schema)
obj = Model()
self.assertIsNone(obj.a_thing)
obj = Model(a_thing=None)
self.assertIsNone(obj.a_thing)
with self.assertRaises(ValueError):
Model(a_thing="not none")