summaryrefslogtreecommitdiff
path: root/jsonschema/tests/test_deprecations.py
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-08-25 18:34:29 +0100
committerJulian Berman <Julian@GrayVines.com>2021-08-25 18:34:29 +0100
commit996437f0693adf66ac6d24df7770057fc0fd9b15 (patch)
treed07f9d80d67799ffa85b62f7f0e07398ef94417e /jsonschema/tests/test_deprecations.py
parent452169710f20a38372bdd686f79680df1215d188 (diff)
downloadjsonschema-996437f0693adf66ac6d24df7770057fc0fd9b15.tar.gz
Add Validator.evolve, deprecating passing _schema to methods.
A Validator should be thought of as encapsulating validation with a single fixed schema. Previously, iter_errors and is_valid allowed passing a second argument, which was a different schema to use for one method call. This was mostly for convenience, since the second argument is often used during sub-validation whilst say, recursing. The correct way to do so now is to say: validator.evolve(schema=new_schema).iter_errors(...) validator.evolve(schema=new_schema).is_valid(...) instead, which is essentially equally convenient. Closes: #522
Diffstat (limited to 'jsonschema/tests/test_deprecations.py')
-rw-r--r--jsonschema/tests/test_deprecations.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/jsonschema/tests/test_deprecations.py b/jsonschema/tests/test_deprecations.py
index 0ddc375..c1f4c21 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 RefResolver
+from jsonschema.validators import Draft7Validator, RefResolver
class TestDeprecations(TestCase):
@@ -48,3 +48,37 @@ class TestDeprecations(TestCase):
"jsonschema.RefResolver.in_scope is deprecated ",
),
)
+
+ def test_Validator_is_valid_two_arguments(self):
+ """
+ As of v4.0.0, calling is_valid with two arguments (to provide a
+ different schema) is deprecated.
+ """
+
+ validator = Draft7Validator({})
+ with self.assertWarns(DeprecationWarning) as w:
+ result = validator.is_valid("foo", {"type": "number"})
+
+ self.assertFalse(result)
+ self.assertTrue(
+ str(w.warning).startswith(
+ "Passing a schema to Validator.is_valid is deprecated ",
+ ),
+ )
+
+ def test_Validator_iter_errors_two_arguments(self):
+ """
+ As of v4.0.0, calling iter_errors with two arguments (to provide a
+ different schema) is deprecated.
+ """
+
+ validator = Draft7Validator({})
+ with self.assertWarns(DeprecationWarning) as w:
+ error, = validator.iter_errors("foo", {"type": "number"})
+
+ self.assertEqual(error.validator, "type")
+ self.assertTrue(
+ str(w.warning).startswith(
+ "Passing a schema to Validator.iter_errors is deprecated ",
+ ),
+ )