Skip to content

Commit b234ae8

Browse files
committed
Minor style change on imports.
1 parent b318f33 commit b234ae8

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

jsonschema/tests/test_validators.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@
1414

1515
from jsonschema import (
1616
FormatChecker,
17-
SchemaError,
18-
ValidationError,
1917
TypeChecker,
2018
_types,
19+
exceptions,
2120
validators,
2221
)
2322
from jsonschema.compat import PY3, pathname2url
2423

2524

2625
def startswith(validator, startswith, instance, schema):
2726
if not instance.startswith(startswith):
28-
yield ValidationError(u"Whoops!")
27+
yield exceptions.ValidationError(u"Whoops!")
2928

3029

3130
class TestCreateAndExtend(SynchronousTestCase):
@@ -75,7 +74,7 @@ def test_iter_errors(self):
7574
errors = list(iter_errors(u"hello"))
7675
self.assertEqual(errors, [])
7776

78-
expected_error = ValidationError(
77+
expected_error = exceptions.ValidationError(
7978
u"Whoops!",
8079
instance=u"goodbye",
8180
schema=schema,
@@ -339,7 +338,7 @@ def test_iter_errors_multiple_failures_one_validator(self):
339338
class TestValidationErrorMessages(TestCase):
340339
def message_for(self, instance, schema, *args, **kwargs):
341340
kwargs.setdefault("cls", validators.Draft3Validator)
342-
with self.assertRaises(ValidationError) as e:
341+
with self.assertRaises(exceptions.ValidationError) as e:
343342
validators.validate(instance, schema, *args, **kwargs)
344343
return e.exception.message
345344

@@ -887,11 +886,11 @@ def test_additionalItems_with_items(self):
887886
class MetaSchemaTestsMixin(object):
888887
# TODO: These all belong upstream
889888
def test_invalid_properties(self):
890-
with self.assertRaises(SchemaError):
889+
with self.assertRaises(exceptions.SchemaError):
891890
self.Validator.check_schema({"properties": {"test": object()}})
892891

893892
def test_minItems_invalid_string(self):
894-
with self.assertRaises(SchemaError):
893+
with self.assertRaises(exceptions.SchemaError):
895894
# needs to be an integer
896895
self.Validator.check_schema({"minItems": "1"})
897896

@@ -919,7 +918,7 @@ def test_it_delegates_to_a_ref_resolver(self):
919918
resolver = validators.RefResolver("", {}, store={ref: schema})
920919
validator = self.Validator({"$ref": ref}, resolver=resolver)
921920

922-
with self.assertRaises(ValidationError):
921+
with self.assertRaises(exceptions.ValidationError):
923922
validator.validate(None)
924923

925924
def test_it_delegates_to_a_legacy_ref_resolver(self):
@@ -938,7 +937,7 @@ def resolving(this, ref):
938937
resolver = LegacyRefResolver()
939938
schema = {"$ref": "the ref"}
940939

941-
with self.assertRaises(ValidationError):
940+
with self.assertRaises(exceptions.ValidationError):
942941
self.Validator(schema, resolver=resolver).validate(None)
943942

944943
def test_is_type_is_true_for_valid_type(self):
@@ -1004,7 +1003,7 @@ def check(value):
10041003
)
10051004

10061005
validator.validate("good")
1007-
with self.assertRaises(ValidationError) as cm:
1006+
with self.assertRaises(exceptions.ValidationError) as cm:
10081007
validator.validate("bad")
10091008

10101009
# Make sure original cause is attached
@@ -1035,7 +1034,7 @@ def test_it_properly_formats_tuples_in_errors(self):
10351034
lambda checker, thing: isinstance(thing, tuple),
10361035
)
10371036
)
1038-
with self.assertRaises(ValidationError) as e:
1037+
with self.assertRaises(exceptions.ValidationError) as e:
10391038
TupleValidator({"uniqueItems": True}).validate((1, 1))
10401039
self.assertIn("(1, 1) has non-unique elements", str(e.exception))
10411040

@@ -1046,12 +1045,12 @@ class AntiDraft6LeakMixin(object):
10461045
"""
10471046

10481047
def test_True_is_not_a_schema(self):
1049-
with self.assertRaises(SchemaError) as e:
1048+
with self.assertRaises(exceptions.SchemaError) as e:
10501049
self.Validator.check_schema(True)
10511050
self.assertIn("True is not of type", str(e.exception))
10521051

10531052
def test_False_is_not_a_schema(self):
1054-
with self.assertRaises(SchemaError) as e:
1053+
with self.assertRaises(exceptions.SchemaError) as e:
10551054
self.Validator.check_schema(False)
10561055
self.assertIn("False is not of type", str(e.exception))
10571056

@@ -1089,7 +1088,7 @@ def test_any_type_is_redefinable(self):
10891088
)
10901089
validator = Crazy({"type": "any"})
10911090
validator.validate(12)
1092-
with self.assertRaises(ValidationError):
1091+
with self.assertRaises(exceptions.ValidationError):
10931092
validator.validate("foo")
10941093

10951094
def test_is_type_is_true_for_any_type(self):
@@ -1310,15 +1309,15 @@ def test_draft7_validator_is_the_default(self):
13101309
self.assertUses(schema={}, Validator=validators.Draft7Validator)
13111310

13121311
def test_validation_error_message(self):
1313-
with self.assertRaises(ValidationError) as e:
1312+
with self.assertRaises(exceptions.ValidationError) as e:
13141313
validators.validate(12, {"type": "string"})
13151314
self.assertRegexpMatches(
13161315
str(e.exception),
13171316
"(?s)Failed validating u?'.*' in schema.*On instance",
13181317
)
13191318

13201319
def test_schema_error_message(self):
1321-
with self.assertRaises(SchemaError) as e:
1320+
with self.assertRaises(exceptions.SchemaError) as e:
13221321
validators.validate(12, {"type": 12})
13231322
self.assertRegexpMatches(
13241323
str(e.exception),
@@ -1499,15 +1498,15 @@ def handler(url):
14991498

15001499
ref = "foo://bar"
15011500
resolver = validators.RefResolver("", {}, handlers={"foo": handler})
1502-
with self.assertRaises(validators.RefResolutionError) as err:
1501+
with self.assertRaises(exceptions.RefResolutionError) as err:
15031502
with resolver.resolving(ref):
15041503
self.fail("Shouldn't get this far!") # pragma: no cover
1505-
self.assertEqual(err.exception, validators.RefResolutionError(error))
1504+
self.assertEqual(err.exception, exceptions.RefResolutionError(error))
15061505

15071506
def test_helpful_error_message_on_failed_pop_scope(self):
15081507
resolver = validators.RefResolver("", {})
15091508
resolver.pop_scope()
1510-
with self.assertRaises(validators.RefResolutionError) as exc:
1509+
with self.assertRaises(exceptions.RefResolutionError) as exc:
15111510
resolver.pop_scope()
15121511
self.assertIn("Failed to pop the scope", str(exc.exception))
15131512

jsonschema/validators.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from six import add_metaclass
99

10-
from jsonschema import _utils, _validators, _types
10+
from jsonschema import _utils, _validators, _types, exceptions
1111
from jsonschema.compat import (
1212
Sequence,
1313
int_types,
@@ -20,13 +20,6 @@
2020
urlopen,
2121
urlsplit,
2222
)
23-
from jsonschema.exceptions import (
24-
RefResolutionError,
25-
SchemaError,
26-
UnknownType,
27-
UndefinedTypeCheck,
28-
ValidationError,
29-
)
3023

3124
# Sigh. https://gitlab.com/pycqa/flake8/issues/280
3225
# https://github.com/pyga/ebb-lint/issues/7
@@ -259,7 +252,7 @@ def __init__(
259252
@classmethod
260253
def check_schema(cls, schema):
261254
for error in cls(cls.META_SCHEMA).iter_errors(schema):
262-
raise SchemaError.create_from(error)
255+
raise exceptions.SchemaError.create_from(error)
263256

264257
def iter_errors(self, instance, _schema=None):
265258
if _schema is None:
@@ -268,7 +261,7 @@ def iter_errors(self, instance, _schema=None):
268261
if _schema is True:
269262
return
270263
elif _schema is False:
271-
yield ValidationError(
264+
yield exceptions.ValidationError(
272265
"False schema does not allow %r" % (instance,),
273266
)
274267
return
@@ -319,8 +312,8 @@ def validate(self, *args, **kwargs):
319312
def is_type(self, instance, type):
320313
try:
321314
return self.TYPE_CHECKER.is_type(instance, type)
322-
except UndefinedTypeCheck:
323-
raise UnknownType(type, instance, self.schema)
315+
except exceptions.UndefinedTypeCheck:
316+
raise exceptions.UnknownType(type, instance, self.schema)
324317

325318
def is_valid(self, instance, _schema=None):
326319
error = next(self.iter_errors(instance, _schema), None)
@@ -662,7 +655,7 @@ def pop_scope(self):
662655
try:
663656
self._scopes_stack.pop()
664657
except IndexError:
665-
raise RefResolutionError(
658+
raise exceptions.RefResolutionError(
666659
"Failed to pop the scope from an empty stack. "
667660
"`pop_scope()` should only be called once for every "
668661
"`push_scope()`"
@@ -719,7 +712,7 @@ def resolve_from_url(self, url):
719712
try:
720713
document = self.resolve_remote(url)
721714
except Exception as exc:
722-
raise RefResolutionError(exc)
715+
raise exceptions.RefResolutionError(exc)
723716

724717
return self.resolve_fragment(document, fragment)
725718

@@ -754,7 +747,7 @@ def resolve_fragment(self, document, fragment):
754747
try:
755748
document = document[part]
756749
except (TypeError, LookupError):
757-
raise RefResolutionError(
750+
raise exceptions.RefResolutionError(
758751
"Unresolvable JSON pointer: %r" % fragment
759752
)
760753

0 commit comments

Comments
 (0)