|
3 | 3 | import subprocess
|
4 | 4 | import sys
|
5 | 5 |
|
| 6 | +import referencing.exceptions |
| 7 | + |
6 | 8 | from jsonschema import FormatChecker, exceptions, validators
|
7 | 9 |
|
8 | 10 |
|
@@ -169,6 +171,38 @@ def test_RefResolutionError(self):
|
169 | 171 | self.assertEqual(RefResolutionError, exceptions._RefResolutionError)
|
170 | 172 | self.assertEqual(w.filename, __file__)
|
171 | 173 |
|
| 174 | + def test_catching_Unresolvable_directly(self): |
| 175 | + """ |
| 176 | + This behavior is the intended behavior (i.e. it's not deprecated), but |
| 177 | + given we do "tricksy" things in the iterim to wrap exceptions in a |
| 178 | + multiple inheritance subclass, we need to be extra sure it works and |
| 179 | + stays working. |
| 180 | + """ |
| 181 | + validator = validators.Draft202012Validator({"$ref": "http://foo.com"}) |
| 182 | + |
| 183 | + with self.assertRaises(referencing.exceptions.Unresolvable) as e: |
| 184 | + validator.validate(12) |
| 185 | + |
| 186 | + expected = referencing.exceptions.Unresolvable(ref="http://foo.com") |
| 187 | + self.assertEqual(e.exception, expected) |
| 188 | + |
| 189 | + def test_catching_Unresolvable_via_RefResolutionError(self): |
| 190 | + """ |
| 191 | + Until RefResolutionError is removed, it is still possible to catch |
| 192 | + exceptions from reference resolution using it, even though they may |
| 193 | + have been raised by referencing. |
| 194 | + """ |
| 195 | + with self.assertWarns(DeprecationWarning): |
| 196 | + from jsonschema import RefResolutionError |
| 197 | + |
| 198 | + validator = validators.Draft202012Validator({"$ref": "http://foo.com"}) |
| 199 | + |
| 200 | + with self.assertRaises(referencing.exceptions.Unresolvable): |
| 201 | + validator.validate(12) |
| 202 | + |
| 203 | + with self.assertRaises(RefResolutionError): |
| 204 | + validator.validate(12) |
| 205 | + |
172 | 206 | def test_Validator_subclassing(self):
|
173 | 207 | """
|
174 | 208 | As of v4.12.0, subclassing a validator class produces an explicit
|
|
0 commit comments