summaryrefslogtreecommitdiff
path: root/jsonschema/tests
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2022-09-09 11:55:56 +0300
committerJulian Berman <Julian@GrayVines.com>2022-09-09 11:55:56 +0300
commitee024ffc61bee56b25e816f489d7365fe1445c6d (patch)
tree3e2bb6cde1aec4cd489f018fbc46c354b5accc7b /jsonschema/tests
parentbd4306a00ffecc715567d3117ce0ecc949f5dcc0 (diff)
downloadjsonschema-ee024ffc61bee56b25e816f489d7365fe1445c6d.tar.gz
Deprecate jsonschema.draftN_format_checker attributes.v4.16.0
Format support / enablement will change with vocabulary support, but in the interim, now that #905 is merged, these objects are better accessed by retrieving them directly from the corresponding validator. In other words: don't do: from jsonschema import draft202012_format_checker just do from jsonschema import Draft202012Validator do_whatever_with(Draft202012Validator.FORMAT_CHECKER)
Diffstat (limited to 'jsonschema/tests')
-rw-r--r--jsonschema/tests/test_deprecations.py99
-rw-r--r--jsonschema/tests/test_jsonschema_test_suite.py28
2 files changed, 113 insertions, 14 deletions
diff --git a/jsonschema/tests/test_deprecations.py b/jsonschema/tests/test_deprecations.py
index afa2658..54e2267 100644
--- a/jsonschema/tests/test_deprecations.py
+++ b/jsonschema/tests/test_deprecations.py
@@ -162,3 +162,102 @@ class TestDeprecations(TestCase):
self.assertTrue(
str(w.warning).startswith("FormatChecker.cls_checks "),
)
+
+ def test_draftN_format_checker(self):
+ """
+ As of v4.16.0, accessing jsonschema.draftn_format_checker is deprecated
+ in favor of Validator.FORMAT_CHECKER.
+ """
+
+ with self.assertWarns(DeprecationWarning) as w:
+ from jsonschema import draft202012_format_checker # noqa
+
+ self.assertIs(
+ draft202012_format_checker,
+ validators.Draft202012Validator.FORMAT_CHECKER,
+ )
+ self.assertEqual(w.filename, __file__)
+ self.assertTrue(
+ str(w.warning).startswith(
+ "Accessing jsonschema.draft202012_format_checker is ",
+ ),
+ msg=w.warning,
+ )
+
+ with self.assertWarns(DeprecationWarning) as w:
+ from jsonschema import draft201909_format_checker # noqa
+
+ self.assertIs(
+ draft201909_format_checker,
+ validators.Draft201909Validator.FORMAT_CHECKER,
+ )
+ self.assertEqual(w.filename, __file__)
+ self.assertTrue(
+ str(w.warning).startswith(
+ "Accessing jsonschema.draft201909_format_checker is ",
+ ),
+ msg=w.warning,
+ )
+
+ with self.assertWarns(DeprecationWarning) as w:
+ from jsonschema import draft7_format_checker # noqa
+
+ self.assertIs(
+ draft7_format_checker,
+ validators.Draft7Validator.FORMAT_CHECKER,
+ )
+ self.assertEqual(w.filename, __file__)
+ self.assertTrue(
+ str(w.warning).startswith(
+ "Accessing jsonschema.draft7_format_checker is ",
+ ),
+ msg=w.warning,
+ )
+
+ with self.assertWarns(DeprecationWarning) as w:
+ from jsonschema import draft6_format_checker # noqa
+
+ self.assertIs(
+ draft6_format_checker,
+ validators.Draft6Validator.FORMAT_CHECKER,
+ )
+ self.assertEqual(w.filename, __file__)
+ self.assertTrue(
+ str(w.warning).startswith(
+ "Accessing jsonschema.draft6_format_checker is ",
+ ),
+ msg=w.warning,
+ )
+
+ with self.assertWarns(DeprecationWarning) as w:
+ from jsonschema import draft4_format_checker # noqa
+
+ self.assertIs(
+ draft4_format_checker,
+ validators.Draft4Validator.FORMAT_CHECKER,
+ )
+ self.assertEqual(w.filename, __file__)
+ self.assertTrue(
+ str(w.warning).startswith(
+ "Accessing jsonschema.draft4_format_checker is ",
+ ),
+ msg=w.warning,
+ )
+
+ with self.assertWarns(DeprecationWarning) as w:
+ from jsonschema import draft3_format_checker # noqa
+
+ self.assertIs(
+ draft3_format_checker,
+ validators.Draft3Validator.FORMAT_CHECKER,
+ )
+ self.assertEqual(w.filename, __file__)
+ self.assertTrue(
+ str(w.warning).startswith(
+ "Accessing jsonschema.draft3_format_checker is ",
+ ),
+ msg=w.warning,
+ )
+
+ with self.assertRaises(ImportError):
+ from jsonschema import draft1234_format_checker # noqa
diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py
index 43debbb..1e58365 100644
--- a/jsonschema/tests/test_jsonschema_test_suite.py
+++ b/jsonschema/tests/test_jsonschema_test_suite.py
@@ -28,14 +28,14 @@ def skip(message, **kwargs):
return skipper
-def missing_format(checker):
+def missing_format(Validator):
def missing_format(test): # pragma: no cover
schema = test.schema
if (
schema is True
or schema is False
or "format" not in schema
- or schema["format"] in checker.checkers
+ or schema["format"] in Validator.FORMAT_CHECKER.checkers
or test.valid
):
return
@@ -150,10 +150,10 @@ TestDraft3 = DRAFT3.to_unittest_testcase(
DRAFT3.optional_tests_of(name="non-bmp-regex"),
DRAFT3.optional_tests_of(name="zeroTerminatedFloats"),
Validator=jsonschema.Draft3Validator,
- format_checker=jsonschema.draft3_format_checker,
+ format_checker=jsonschema.Draft3Validator.FORMAT_CHECKER,
skip=lambda test: (
narrow_unicode_build(test)
- or missing_format(jsonschema.draft3_format_checker)(test)
+ or missing_format(jsonschema.Draft3Validator)(test)
or complex_email_validation(test)
or skip(
message=bug(),
@@ -175,12 +175,12 @@ TestDraft4 = DRAFT4.to_unittest_testcase(
DRAFT4.optional_tests_of(name="non-bmp-regex"),
DRAFT4.optional_tests_of(name="zeroTerminatedFloats"),
Validator=jsonschema.Draft4Validator,
- format_checker=jsonschema.draft4_format_checker,
+ format_checker=jsonschema.Draft4Validator.FORMAT_CHECKER,
skip=lambda test: (
narrow_unicode_build(test)
or allowed_leading_zeros(test)
or leap_second(test)
- or missing_format(jsonschema.draft4_format_checker)(test)
+ or missing_format(jsonschema.Draft4Validator)(test)
or complex_email_validation(test)
or skip(
message=bug(),
@@ -236,12 +236,12 @@ TestDraft6 = DRAFT6.to_unittest_testcase(
DRAFT6.optional_tests_of(name="float-overflow"),
DRAFT6.optional_tests_of(name="non-bmp-regex"),
Validator=jsonschema.Draft6Validator,
- format_checker=jsonschema.draft6_format_checker,
+ format_checker=jsonschema.Draft6Validator.FORMAT_CHECKER,
skip=lambda test: (
narrow_unicode_build(test)
or allowed_leading_zeros(test)
or leap_second(test)
- or missing_format(jsonschema.draft6_format_checker)(test)
+ or missing_format(jsonschema.Draft6Validator)(test)
or complex_email_validation(test)
or skip(
message=bug(),
@@ -260,12 +260,12 @@ TestDraft7 = DRAFT7.to_unittest_testcase(
DRAFT7.optional_tests_of(name="float-overflow"),
DRAFT7.optional_tests_of(name="non-bmp-regex"),
Validator=jsonschema.Draft7Validator,
- format_checker=jsonschema.draft7_format_checker,
+ format_checker=jsonschema.Draft7Validator.FORMAT_CHECKER,
skip=lambda test: (
narrow_unicode_build(test)
or allowed_leading_zeros(test)
or leap_second(test)
- or missing_format(jsonschema.draft7_format_checker)(test)
+ or missing_format(jsonschema.Draft7Validator)(test)
or complex_email_validation(test)
or skip(
message=bug(),
@@ -408,12 +408,12 @@ TestDraft201909 = DRAFT201909.to_unittest_testcase(
TestDraft201909Format = DRAFT201909.to_unittest_testcase(
DRAFT201909.format_tests(),
Validator=jsonschema.Draft201909Validator,
- format_checker=jsonschema.draft201909_format_checker,
+ format_checker=jsonschema.Draft201909Validator.FORMAT_CHECKER,
skip=lambda test: (
complex_email_validation(test)
or allowed_leading_zeros(test)
or leap_second(test)
- or missing_format(jsonschema.draft201909_format_checker)(test)
+ or missing_format(jsonschema.Draft201909Validator)(test)
or complex_email_validation(test)
),
)
@@ -533,12 +533,12 @@ TestDraft202012 = DRAFT202012.to_unittest_testcase(
TestDraft202012Format = DRAFT202012.to_unittest_testcase(
DRAFT202012.format_tests(),
Validator=jsonschema.Draft202012Validator,
- format_checker=jsonschema.draft202012_format_checker,
+ format_checker=jsonschema.Draft202012Validator.FORMAT_CHECKER,
skip=lambda test: (
complex_email_validation(test)
or allowed_leading_zeros(test)
or leap_second(test)
- or missing_format(jsonschema.draft202012_format_checker)(test)
+ or missing_format(jsonschema.Draft202012Validator)(test)
or complex_email_validation(test)
),
)