Skip to content

Commit 98dc2df

Browse files
committed
Add tests for fixed Error.absolute_path
1 parent bee8d27 commit 98dc2df

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

jsonschema/tests/test_validators.py

+65
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,71 @@ def test_multiple_nesting(self):
425425
self.assertEqual(e5.validator, "minItems")
426426
self.assertEqual(e6.validator, "enum")
427427

428+
def test_recursive(self):
429+
schema = {
430+
"definitions": {
431+
"node": {
432+
"anyOf": [{
433+
"type": "object",
434+
"required": ["name", "children"],
435+
"properties": {
436+
"name": {
437+
"type": "string",
438+
},
439+
"children": {
440+
"type": "object",
441+
"patternProperties": {
442+
"^.*$": {
443+
"$ref": "#/definitions/node",
444+
},
445+
},
446+
},
447+
},
448+
}],
449+
},
450+
},
451+
"type": "object",
452+
"required": ["root"],
453+
"properties": {
454+
"root": {"$ref": "#/definitions/node"},
455+
}
456+
}
457+
458+
instance = {
459+
"root": {
460+
"name": "root",
461+
"children": {
462+
"a": {
463+
"name": "a",
464+
"children": {
465+
"ab": {
466+
"name": "ab",
467+
# missing "children"
468+
}
469+
}
470+
},
471+
},
472+
},
473+
}
474+
validator = Draft4Validator(schema)
475+
476+
e, = validator.iter_errors(instance)
477+
self.assertEqual(e.absolute_path, deque(["root"]))
478+
self.assertEqual(e.absolute_schema_path, deque(['properties', 'root', 'anyOf']))
479+
480+
e1, = e.context
481+
self.assertEqual(e1.absolute_path, deque(['root', 'children', 'a']))
482+
self.assertEqual(e1.absolute_schema_path,
483+
deque(['properties', 'root', 'anyOf', 0, 'properties',
484+
'children', 'patternProperties', '^.*$', 'anyOf']))
485+
486+
e2, = e1.context
487+
self.assertEqual(e2.absolute_path, deque(['root', 'children', 'a', 'children', 'ab']))
488+
self.assertEqual(e2.absolute_schema_path,
489+
deque(['properties', 'root', 'anyOf', 0, 'properties',
490+
'children', 'patternProperties', '^.*$', 'anyOf', 0, 'properties',
491+
'children', 'patternProperties', '^.*$', 'anyOf']))
492+
428493
def test_additionalProperties(self):
429494
instance = {"bar": "bar", "foo": 2}
430495
schema = {

0 commit comments

Comments
 (0)