diff options
author | Julian Berman <Julian@GrayVines.com> | 2018-09-29 08:54:43 -0400 |
---|---|---|
committer | Julian Berman <Julian@GrayVines.com> | 2018-09-30 09:37:25 -0400 |
commit | 7c16622e291b516ee23e85a05b89a1a5be97b46a (patch) | |
tree | 5367786f6d8ed5f2f5ed7f6ea1f12a933088ddc8 /jsonschema/tests | |
parent | e0add0ee189d9aa97f8326a27da6a925e24a5cae (diff) | |
download | jsonschema-7c16622e291b516ee23e85a05b89a1a5be97b46a.tar.gz |
First step on Draft7 support.
Add everything that's the same in Draft6, which appears to just leave
out if/then/else.
Diffstat (limited to 'jsonschema/tests')
-rw-r--r-- | jsonschema/tests/test_jsonschema_test_suite.py | 34 | ||||
-rw-r--r-- | jsonschema/tests/test_validators.py | 30 |
2 files changed, 61 insertions, 3 deletions
diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index 110c5f4..e434f8a 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -12,9 +12,11 @@ from jsonschema import ( Draft3Validator, Draft4Validator, Draft6Validator, + Draft7Validator, draft3_format_checker, draft4_format_checker, draft6_format_checker, + draft7_format_checker, ) from jsonschema.tests._suite import Suite from jsonschema.validators import _DEPRECATED_DEFAULT_TYPES, create @@ -24,6 +26,7 @@ SUITE = Suite() DRAFT3 = SUITE.version(name="draft3") DRAFT4 = SUITE.version(name="draft4") DRAFT6 = SUITE.version(name="draft6") +DRAFT7 = SUITE.version(name="draft7") def skip_tests_containing_descriptions(**kwargs): @@ -139,6 +142,37 @@ TestDraft6 = DRAFT6.to_unittest_testcase( ) +TestDraft7 = DRAFT7.to_unittest_testcase( + DRAFT7.tests(), + DRAFT7.format_tests(), + DRAFT7.optional_tests_of(name="bignum"), + DRAFT7.optional_tests_of(name="zeroTerminatedFloats"), + Validator=Draft7Validator, + format_checker=draft7_format_checker, + skip=lambda test: ( + narrow_unicode_build(test) + or missing_format(draft7_format_checker)(test) + or skip_tests_containing_descriptions( + ref={ + "valid tree": "An actual bug, this needs fixing.", + }, + refRemote={ + "number is valid": "An actual bug, this needs fixing.", + "string is invalid": "An actual bug, this needs fixing.", + }, + )(test) + or skip_tests_containing_descriptions( + **{ + "date-time": { + "case-insensitive T and Z": + "Upstream bug in strict_rfc3339", + }, + } + )(test) + ), +) + + TestDraft3LegacyTypeCheck = DRAFT3.to_unittest_testcase( DRAFT3.tests_of(name="type"), name="TestDraft3LegacyTypeCheck", diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index 9ebff12..8bb3880 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -464,7 +464,7 @@ class TestValidationErrorMessages(TestCase): message = self.message_for( instance="something", schema=False, - cls=validators.Draft6Validator, + cls=validators.Draft7Validator, ) self.assertIn("False schema does not allow 'something'", message) @@ -1132,6 +1132,19 @@ class TestValidatorFor(TestCase): validators.Draft6Validator, ) + def test_draft_7(self): + schema = {"$schema": "http://json-schema.org/draft-07/schema"} + self.assertIs( + validators.validator_for(schema), + validators.Draft7Validator, + ) + + schema = {"$schema": "http://json-schema.org/draft-07/schema#"} + self.assertIs( + validators.validator_for(schema), + validators.Draft7Validator, + ) + def test_True(self): self.assertIs( validators.validator_for(True), @@ -1213,8 +1226,19 @@ class TestValidate(TestCase): Validator=validators.Draft6Validator, ) - def test_draft6_validator_is_the_default(self): - self.assertUses(schema={}, Validator=validators.Draft6Validator) + def test_draft7_validator_is_chosen(self): + self.assertUses( + schema={"$schema": "http://json-schema.org/draft-07/schema#"}, + Validator=validators.Draft7Validator, + ) + # Make sure it works without the empty fragment + self.assertUses( + schema={"$schema": "http://json-schema.org/draft-07/schema"}, + Validator=validators.Draft7Validator, + ) + + def test_draft7_validator_is_the_default(self): + self.assertUses(schema={}, Validator=validators.Draft7Validator) def test_validation_error_message(self): with self.assertRaises(ValidationError) as e: |