mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
Add jsonschema extension to populate defaults.
This commit is contained in:
parent
5f4996645c
commit
b23ad5d6a3
2 changed files with 83 additions and 0 deletions
51
tests/jsonschema_extensions_test.py
Normal file
51
tests/jsonschema_extensions_test.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
|
||||
|
||||
def test_apply_defaults_copies_object():
|
||||
input = {}
|
||||
ret = apply_defaults(input, {})
|
||||
assert ret is not input
|
||||
|
||||
|
||||
def test_apply_default_does_not_touch_schema_without_defaults():
|
||||
ret = apply_defaults(
|
||||
{'foo': 'bar'},
|
||||
{'type': 'object', 'properties': {'foo': {}, 'baz': {}}},
|
||||
)
|
||||
assert ret == {'foo': 'bar'}
|
||||
|
||||
|
||||
def test_apply_defaults_applies_defaults():
|
||||
ret = apply_defaults(
|
||||
{'foo': 'bar'},
|
||||
{
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'foo': {'default': 'biz'},
|
||||
'baz': {'default': 'herp'},
|
||||
}
|
||||
}
|
||||
)
|
||||
assert ret == {'foo': 'bar', 'baz': 'herp'}
|
||||
|
||||
|
||||
def test_apply_defaults_deep():
|
||||
ret = apply_defaults(
|
||||
{'foo': {'bar': {}}},
|
||||
{
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'foo': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'bar': {
|
||||
'type': 'object',
|
||||
'properties': {'baz': {'default': 'herp'}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
assert ret == {'foo': {'bar': {'baz': 'herp'}}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue