Skip to content

Commit 24d9fd9

Browse files
committed
Add all the Draft 6 tests, makin' em fail.
1 parent d0381d5 commit 24d9fd9

5 files changed

Lines changed: 193 additions & 7 deletions

File tree

jsonschema/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@
1313
ErrorTree, FormatError, RefResolutionError, SchemaError, ValidationError
1414
)
1515
from jsonschema._format import (
16-
FormatChecker, draft3_format_checker, draft4_format_checker,
16+
FormatChecker,
17+
draft3_format_checker,
18+
draft4_format_checker,
19+
draft6_format_checker,
1720
)
1821
from jsonschema.validators import (
19-
Draft3Validator, Draft4Validator, RefResolver, validate
22+
Draft3Validator,
23+
Draft4Validator,
24+
Draft6Validator,
25+
RefResolver,
26+
validate,
2027
)
2128

2229
from jsonschema._version import __version__

jsonschema/_format.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def conforms(self, instance, format):
129129
return True
130130

131131

132-
_draft_checkers = {"draft3": [], "draft4": []}
132+
_draft_checkers = {"draft3": [], "draft4": [], "draft6": []}
133133

134134

135135
def _checks_drafts(both=None, draft3=None, draft4=None, raises=()):
@@ -269,3 +269,4 @@ def is_css3_color(instance):
269269

270270
draft3_format_checker = FormatChecker(_draft_checkers["draft3"])
271271
draft4_format_checker = FormatChecker(_draft_checkers["draft4"])
272+
draft6_format_checker = FormatChecker(_draft_checkers["draft6"])

jsonschema/schemas/draft6.json

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-06/schema#",
3+
"$id": "http://json-schema.org/draft-06/schema#",
4+
"title": "Core schema meta-schema",
5+
"definitions": {
6+
"schemaArray": {
7+
"type": "array",
8+
"minItems": 1,
9+
"items": { "$ref": "#" }
10+
},
11+
"nonNegativeInteger": {
12+
"type": "integer",
13+
"minimum": 0
14+
},
15+
"nonNegativeIntegerDefault0": {
16+
"allOf": [
17+
{ "$ref": "#/definitions/nonNegativeInteger" },
18+
{ "default": 0 }
19+
]
20+
},
21+
"simpleTypes": {
22+
"enum": [
23+
"array",
24+
"boolean",
25+
"integer",
26+
"null",
27+
"number",
28+
"object",
29+
"string"
30+
]
31+
},
32+
"stringArray": {
33+
"type": "array",
34+
"items": { "type": "string" },
35+
"uniqueItems": true,
36+
"default": []
37+
}
38+
},
39+
"type": ["object", "boolean"],
40+
"properties": {
41+
"$id": {
42+
"type": "string",
43+
"format": "uri-reference"
44+
},
45+
"$schema": {
46+
"type": "string",
47+
"format": "uri"
48+
},
49+
"$ref": {
50+
"type": "string",
51+
"format": "uri-reference"
52+
},
53+
"title": {
54+
"type": "string"
55+
},
56+
"description": {
57+
"type": "string"
58+
},
59+
"default": {},
60+
"multipleOf": {
61+
"type": "number",
62+
"exclusiveMinimum": 0
63+
},
64+
"maximum": {
65+
"type": "number"
66+
},
67+
"exclusiveMaximum": {
68+
"type": "number"
69+
},
70+
"minimum": {
71+
"type": "number"
72+
},
73+
"exclusiveMinimum": {
74+
"type": "number"
75+
},
76+
"maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
77+
"minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
78+
"pattern": {
79+
"type": "string",
80+
"format": "regex"
81+
},
82+
"additionalItems": { "$ref": "#" },
83+
"items": {
84+
"anyOf": [
85+
{ "$ref": "#" },
86+
{ "$ref": "#/definitions/schemaArray" }
87+
],
88+
"default": {}
89+
},
90+
"maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
91+
"minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
92+
"uniqueItems": {
93+
"type": "boolean",
94+
"default": false
95+
},
96+
"contains": { "$ref": "#" },
97+
"maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
98+
"minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
99+
"required": { "$ref": "#/definitions/stringArray" },
100+
"additionalProperties": { "$ref": "#" },
101+
"definitions": {
102+
"type": "object",
103+
"additionalProperties": { "$ref": "#" },
104+
"default": {}
105+
},
106+
"properties": {
107+
"type": "object",
108+
"additionalProperties": { "$ref": "#" },
109+
"default": {}
110+
},
111+
"patternProperties": {
112+
"type": "object",
113+
"additionalProperties": { "$ref": "#" },
114+
"default": {}
115+
},
116+
"dependencies": {
117+
"type": "object",
118+
"additionalProperties": {
119+
"anyOf": [
120+
{ "$ref": "#" },
121+
{ "$ref": "#/definitions/stringArray" }
122+
]
123+
}
124+
},
125+
"propertyNames": { "$ref": "#" },
126+
"const": {},
127+
"enum": {
128+
"type": "array",
129+
"minItems": 1,
130+
"uniqueItems": true
131+
},
132+
"type": {
133+
"anyOf": [
134+
{ "$ref": "#/definitions/simpleTypes" },
135+
{
136+
"type": "array",
137+
"items": { "$ref": "#/definitions/simpleTypes" },
138+
"minItems": 1,
139+
"uniqueItems": true
140+
}
141+
]
142+
},
143+
"format": { "type": "string" },
144+
"allOf": { "$ref": "#/definitions/schemaArray" },
145+
"anyOf": { "$ref": "#/definitions/schemaArray" },
146+
"oneOf": { "$ref": "#/definitions/schemaArray" },
147+
"not": { "$ref": "#" }
148+
},
149+
"default": {}
150+
}

jsonschema/tests/test_jsonschema_test_suite.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
from jsonschema import (
2828
FormatError, SchemaError, ValidationError, Draft3Validator,
29-
Draft4Validator, FormatChecker, draft3_format_checker,
30-
draft4_format_checker, validate,
29+
Draft4Validator, Draft6Validator, FormatChecker, draft3_format_checker,
30+
draft4_format_checker, draft6_format_checker, validate,
3131
)
3232
from jsonschema.compat import PY3
3333
from jsonschema.tests.compat import mock
@@ -291,6 +291,21 @@ def test_minItems_invalid_string(self):
291291
validate([1], {"minItems": "1"}, cls=self.validator_class)
292292

293293

294+
@load_json_cases(
295+
"draft6/*.json",
296+
skip=narrow_unicode_build,
297+
ignore_glob="draft6/refRemote.json",
298+
)
299+
@load_json_cases(
300+
"draft6/optional/format.json", skip=missing_format(draft6_format_checker)
301+
)
302+
@load_json_cases("draft6/optional/bignum.json")
303+
@load_json_cases("draft6/optional/zeroTerminatedFloats.json")
304+
class TestDraft6(unittest.TestCase, TypesMixin, DecimalMixin, FormatMixin):
305+
validator_class = Draft6Validator
306+
validator_kwargs = {"format_checker": draft6_format_checker}
307+
308+
294309
class RemoteRefResolutionMixin(object):
295310
def setUp(self):
296311
patch = mock.patch("jsonschema.validators.requests")
@@ -318,3 +333,8 @@ class Draft3RemoteResolution(RemoteRefResolutionMixin, unittest.TestCase):
318333
)
319334
class Draft4RemoteResolution(RemoteRefResolutionMixin, unittest.TestCase):
320335
validator_class = Draft4Validator
336+
337+
338+
@load_json_cases("draft6/refRemote.json")
339+
class Draft6RemoteResolution(RemoteRefResolutionMixin, unittest.TestCase):
340+
validator_class = Draft6Validator

jsonschema/validators.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def extend(validator, validators, version=None):
206206
u"$ref": _validators.ref,
207207
u"additionalItems": _validators.additionalItems,
208208
u"additionalProperties": _validators.additionalProperties,
209-
u"allOf": _validators.allOf_draft4,
209+
u"allOf": _validators.allOf,
210210
u"anyOf": _validators.anyOf_draft4,
211211
u"dependencies": _validators.dependencies,
212212
u"enum": _validators.enum,
@@ -227,13 +227,21 @@ def extend(validator, validators, version=None):
227227
u"patternProperties": _validators.patternProperties,
228228
u"properties": _validators.properties_draft4,
229229
u"required": _validators.required_draft4,
230-
u"type": _validators.type_draft4,
230+
u"type": _validators.type,
231231
u"uniqueItems": _validators.uniqueItems,
232232
},
233233
version="draft4",
234234
)
235235

236236

237+
Draft6Validator = create(
238+
meta_schema=_utils.load_schema("draft6"),
239+
validators={
240+
},
241+
version="draft6",
242+
)
243+
244+
237245
class RefResolver(object):
238246
"""
239247
Resolve JSON References.

0 commit comments

Comments
 (0)