Skip to content

Commit 6fb4102

Browse files
committed
add testcase for 601
1 parent d967cae commit 6fb4102

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"top_left": { "$ref": "point.json" },
5+
"top_right": { "$ref": "point.json" },
6+
"bottom_left": { "$ref": "point.json" },
7+
"bottom_right": { "$ref": "point.json" }
8+
},
9+
"required": ["top_left", "top_right", "bottom_left", "bottom_right"]
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"center": { "$ref": "point.json" },
5+
"radius": {"type": "number"}
6+
},
7+
"required": ["center", "radius"]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "object",
3+
4+
"allOf": [
5+
{ "$ref": "basic_shapes/complex_layer2-1.json" }
6+
],
7+
8+
"properties": {
9+
"hole": { "$ref": "basic_shapes/complex_layer2-2.json" }
10+
},
11+
"required": ["hole"]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"x": { "type": "number" },
5+
"y": { "type": "number" }
6+
},
7+
"required": ["x", "y"]
8+
}

jsonschema/tests/test_validators.py

+20
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,26 @@ def test_ref(self):
11351135
),
11361136
)
11371137

1138+
def test_complex_ref(self):
1139+
filename = "../../../../jsonschema/schemas/complex_schemas/"
1140+
with open(filename + "complex_shapes/complex_layer1.json") as file:
1141+
schema = json.load(file)
1142+
if os.name == 'nt':
1143+
file_prefix = "file:///{}/"
1144+
else:
1145+
file_prefix = "file://{}/"
1146+
base_uri = file_prefix.format(os.path.abspath(filename))
1147+
resolver = validators.RefResolver(base_uri=base_uri, referrer=schema)
1148+
1149+
data = {
1150+
"top_left": {"x": 10, "y": 10},
1151+
"top_right": {"x": 20, "y": 10},
1152+
"bottom_left": {"x": 10, "y": 20},
1153+
"bottom_right": {"x": 20, "y": 20},
1154+
"hole": {"center": {"x": 20, "y": 20}, "radius": 7},
1155+
}
1156+
self.assertIsNone(validators.validate(data, schema, resolver=resolver))
1157+
11381158

11391159
class MetaSchemaTestsMixin(object):
11401160
# TODO: These all belong upstream

0 commit comments

Comments
 (0)