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:
29
tests/parser/test_null_type_parser.py
Normal file
29
tests/parser/test_null_type_parser.py
Normal 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})
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user