summaryrefslogtreecommitdiff
path: root/jsonschema/tests/test_deprecations.py
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-08-26 13:30:53 +0100
committerJulian Berman <Julian@GrayVines.com>2021-08-26 13:30:53 +0100
commit836db7c4c7d9cede429a451201c1a4e059479f53 (patch)
treee4274d85150ee3a04689a3714a06c2b6185bb208 /jsonschema/tests/test_deprecations.py
parent1d275e9b07dbaa84f933a5e1c776a9a8574d1eef (diff)
downloadjsonschema-836db7c4c7d9cede429a451201c1a4e059479f53.tar.gz
Deprecate jsonschema.validators.validators and .meta_schemas.
Besides having confusing names, these expose mutable global state in a way that makes maintenance hard. Today, jsonschema.validators.validator_for(schema) can be used to look up an appropriate Validator given an arbitrary schema.
Diffstat (limited to 'jsonschema/tests/test_deprecations.py')
-rw-r--r--jsonschema/tests/test_deprecations.py40
1 files changed, 36 insertions, 4 deletions
diff --git a/jsonschema/tests/test_deprecations.py b/jsonschema/tests/test_deprecations.py
index c1f4c21..e7163b9 100644
--- a/jsonschema/tests/test_deprecations.py
+++ b/jsonschema/tests/test_deprecations.py
@@ -1,6 +1,6 @@
from unittest import TestCase
-from jsonschema.validators import Draft7Validator, RefResolver
+from jsonschema import validators
class TestDeprecations(TestCase):
@@ -33,12 +33,44 @@ class TestDeprecations(TestCase):
),
)
+ def test_validators_validators(self):
+ """
+ As of v4.0.0, accessing jsonschema.validators.validators is
+ deprecated.
+ """
+
+ with self.assertWarns(DeprecationWarning) as w:
+ value = validators.validators
+ self.assertEqual(value, validators._VALIDATORS)
+
+ self.assertTrue(
+ str(w.warning).startswith(
+ "Accessing jsonschema.validators.validators is deprecated",
+ ),
+ )
+
+ def test_validators_meta_schemas(self):
+ """
+ As of v4.0.0, accessing jsonschema.validators.meta_schemas is
+ deprecated.
+ """
+
+ with self.assertWarns(DeprecationWarning) as w:
+ value = validators.meta_schemas
+ self.assertEqual(value, validators._META_SCHEMAS)
+
+ self.assertTrue(
+ str(w.warning).startswith(
+ "Accessing jsonschema.validators.meta_schemas is deprecated",
+ ),
+ )
+
def test_RefResolver_in_scope(self):
"""
As of v4.0.0, RefResolver.in_scope is deprecated.
"""
- resolver = RefResolver.from_schema({})
+ resolver = validators.RefResolver.from_schema({})
with self.assertWarns(DeprecationWarning) as w:
with resolver.in_scope("foo"):
pass
@@ -55,7 +87,7 @@ class TestDeprecations(TestCase):
different schema) is deprecated.
"""
- validator = Draft7Validator({})
+ validator = validators.Draft7Validator({})
with self.assertWarns(DeprecationWarning) as w:
result = validator.is_valid("foo", {"type": "number"})
@@ -72,7 +104,7 @@ class TestDeprecations(TestCase):
different schema) is deprecated.
"""
- validator = Draft7Validator({})
+ validator = validators.Draft7Validator({})
with self.assertWarns(DeprecationWarning) as w:
error, = validator.iter_errors("foo", {"type": "number"})