summaryrefslogtreecommitdiff
path: root/jsonschema
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-08-18 10:05:04 +0100
committerJulian Berman <Julian@GrayVines.com>2021-08-18 10:05:04 +0100
commit8695165f422424fc592fc09925d4b6f988745c6b (patch)
tree29593778a3cbf641f15b779da5df1c29cf18b6f3 /jsonschema
parent22464af3b273df8ea84f5abf25030d7de80d5a46 (diff)
downloadjsonschema-8695165f422424fc592fc09925d4b6f988745c6b.tar.gz
Add a linter to ensure single quotes aren't added.
Diffstat (limited to 'jsonschema')
-rw-r--r--jsonschema/_utils.py2
-rw-r--r--jsonschema/_validators.py16
-rw-r--r--jsonschema/exceptions.py6
-rw-r--r--jsonschema/tests/test_cli.py2
-rw-r--r--jsonschema/tests/test_validators.py90
-rw-r--r--jsonschema/validators.py2
6 files changed, 59 insertions, 59 deletions
diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py
index 9b02513..9142cc5 100644
--- a/jsonschema/_utils.py
+++ b/jsonschema/_utils.py
@@ -64,7 +64,7 @@ def load_vocabulary(name):
"""
vocabulary = []
base_path = os.path.dirname(sys.modules["jsonschema"].__file__)
- pathlist = Path(os.path.join(base_path, 'schemas', name)).glob('*.json')
+ pathlist = Path(os.path.join(base_path, "schemas", name)).glob("*.json")
for path in pathlist:
with open(path) as data:
vocabulary.append(json.load(data))
diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py
index 75857f1..39680cf 100644
--- a/jsonschema/_validators.py
+++ b/jsonschema/_validators.py
@@ -73,15 +73,15 @@ def items(validator, items, instance, schema):
if not validator.is_type(instance, "array"):
return
- if validator.is_type(items, "boolean") and 'prefixItems' in schema:
+ if validator.is_type(items, "boolean") and "prefixItems" in schema:
if not items:
- if len(instance) > len(schema['prefixItems']):
+ if len(instance) > len(schema["prefixItems"]):
yield ValidationError(
"%r has more items than defined in prefixItems" % instance,
)
else:
- non_prefixed_items = instance[len(schema['prefixItems']):] \
- if 'prefixItems' in schema else instance
+ non_prefixed_items = instance[len(schema["prefixItems"]):] \
+ if "prefixItems" in schema else instance
for index, item in enumerate(non_prefixed_items):
for error in validator.descend(item, items, path=index):
@@ -119,11 +119,11 @@ def contains(validator, contains, instance, schema):
min_contains = max_contains = None
- if 'minContains' in schema:
- min_contains = schema['minContains']
+ if "minContains" in schema:
+ min_contains = schema["minContains"]
- if 'maxContains' in schema:
- max_contains = schema['maxContains']
+ if "maxContains" in schema:
+ max_contains = schema["maxContains"]
# minContains set to 0 will ignore contains
if min_contains == 0:
diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py
index 9cfbb7f..e8da352 100644
--- a/jsonschema/exceptions.py
+++ b/jsonschema/exceptions.py
@@ -112,12 +112,12 @@ class _Error(Exception):
@property
def json_path(self):
- path = '$'
+ path = "$"
for elem in self.absolute_path:
if isinstance(elem, int):
- path += '[' + str(elem) + ']'
+ path += "[" + str(elem) + "]"
else:
- path += '.' + elem
+ path += "." + elem
return path
def _set(self, **kwargs):
diff --git a/jsonschema/tests/test_cli.py b/jsonschema/tests/test_cli.py
index fa29b48..ce2d298 100644
--- a/jsonschema/tests/test_cli.py
+++ b/jsonschema/tests/test_cli.py
@@ -699,7 +699,7 @@ class TestCLI(TestCase):
schema = f'{{"$ref": "{ref_path.name}#definitions/num"}}'
self.assertOutputs(
- files=dict(some_schema=schema, some_instance='1'),
+ files=dict(some_schema=schema, some_instance="1"),
argv=[
"-i", "some_instance",
"--base-uri", ref_path.parent.as_uri() + "/",
diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py
index 820952d..68bc5de 100644
--- a/jsonschema/tests/test_validators.py
+++ b/jsonschema/tests/test_validators.py
@@ -446,7 +446,7 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e.path, deque([]))
self.assertEqual(e.relative_path, deque([]))
self.assertEqual(e.absolute_path, deque([]))
- self.assertEqual(e.json_path, '$')
+ self.assertEqual(e.json_path, "$")
self.assertEqual(e.schema_path, deque(["anyOf"]))
self.assertEqual(e.relative_schema_path, deque(["anyOf"]))
@@ -465,7 +465,7 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e1.path, deque([]))
self.assertEqual(e1.absolute_path, deque([]))
self.assertEqual(e1.relative_path, deque([]))
- self.assertEqual(e1.json_path, '$')
+ self.assertEqual(e1.json_path, "$")
self.assertEqual(e1.schema_path, deque([0, "minimum"]))
self.assertEqual(e1.relative_schema_path, deque([0, "minimum"]))
@@ -484,7 +484,7 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e2.path, deque([]))
self.assertEqual(e2.relative_path, deque([]))
self.assertEqual(e2.absolute_path, deque([]))
- self.assertEqual(e2.json_path, '$')
+ self.assertEqual(e2.json_path, "$")
self.assertEqual(e2.schema_path, deque([1, "type"]))
self.assertEqual(e2.relative_schema_path, deque([1, "type"]))
@@ -518,7 +518,7 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e.path, deque([]))
self.assertEqual(e.relative_path, deque([]))
self.assertEqual(e.absolute_path, deque([]))
- self.assertEqual(e.json_path, '$')
+ self.assertEqual(e.json_path, "$")
self.assertEqual(e.schema_path, deque(["type"]))
self.assertEqual(e.relative_schema_path, deque(["type"]))
@@ -537,7 +537,7 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e1.path, deque([]))
self.assertEqual(e1.relative_path, deque([]))
self.assertEqual(e1.absolute_path, deque([]))
- self.assertEqual(e1.json_path, '$')
+ self.assertEqual(e1.json_path, "$")
self.assertEqual(e1.schema_path, deque([0, "type"]))
self.assertEqual(e1.relative_schema_path, deque([0, "type"]))
@@ -554,7 +554,7 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e2.path, deque(["foo"]))
self.assertEqual(e2.relative_path, deque(["foo"]))
self.assertEqual(e2.absolute_path, deque(["foo"]))
- self.assertEqual(e2.json_path, '$.foo')
+ self.assertEqual(e2.json_path, "$.foo")
self.assertEqual(
e2.schema_path, deque([1, "properties", "foo", "enum"]),
@@ -598,10 +598,10 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e3.absolute_path, deque(["baz"]))
self.assertEqual(e4.absolute_path, deque(["foo"]))
- self.assertEqual(e1.json_path, '$.bar')
- self.assertEqual(e2.json_path, '$.baz')
- self.assertEqual(e3.json_path, '$.baz')
- self.assertEqual(e4.json_path, '$.foo')
+ self.assertEqual(e1.json_path, "$.bar")
+ self.assertEqual(e2.json_path, "$.baz")
+ self.assertEqual(e3.json_path, "$.baz")
+ self.assertEqual(e4.json_path, "$.foo")
self.assertEqual(e1.validator, "minItems")
self.assertEqual(e2.validator, "enum")
@@ -638,12 +638,12 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e5.path, deque([1, "bar", "baz"]))
self.assertEqual(e6.path, deque([1, "foo"]))
- self.assertEqual(e1.json_path, '$')
- self.assertEqual(e2.json_path, '$[0]')
- self.assertEqual(e3.json_path, '$[1].bar')
- self.assertEqual(e4.json_path, '$[1].bar.bar')
- self.assertEqual(e5.json_path, '$[1].bar.baz')
- self.assertEqual(e6.json_path, '$[1].foo')
+ self.assertEqual(e1.json_path, "$")
+ self.assertEqual(e2.json_path, "$[0]")
+ self.assertEqual(e3.json_path, "$[1].bar")
+ self.assertEqual(e4.json_path, "$[1].bar.bar")
+ self.assertEqual(e5.json_path, "$[1].bar.baz")
+ self.assertEqual(e6.json_path, "$[1].foo")
self.assertEqual(e1.schema_path, deque(["type"]))
self.assertEqual(e2.schema_path, deque(["items", "type"]))
@@ -720,7 +720,7 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(
e.absolute_schema_path, deque(["properties", "root", "anyOf"]),
)
- self.assertEqual(e.json_path, '$.root')
+ self.assertEqual(e.json_path, "$.root")
e1, = e.context
self.assertEqual(e1.absolute_path, deque(["root", "children", "a"]))
@@ -739,7 +739,7 @@ class TestValidationErrorDetails(TestCase):
],
),
)
- self.assertEqual(e1.json_path, '$.root.children.a')
+ self.assertEqual(e1.json_path, "$.root.children.a")
e2, = e1.context
self.assertEqual(
@@ -768,7 +768,7 @@ class TestValidationErrorDetails(TestCase):
],
),
)
- self.assertEqual(e2.json_path, '$.root.children.a.children.ab')
+ self.assertEqual(e2.json_path, "$.root.children.a.children.ab")
def test_additionalProperties(self):
instance = {"bar": "bar", "foo": 2}
@@ -781,8 +781,8 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e1.path, deque(["bar"]))
self.assertEqual(e2.path, deque(["foo"]))
- self.assertEqual(e1.json_path, '$.bar')
- self.assertEqual(e2.json_path, '$.foo')
+ self.assertEqual(e1.json_path, "$.bar")
+ self.assertEqual(e2.json_path, "$.foo")
self.assertEqual(e1.validator, "type")
self.assertEqual(e2.validator, "minimum")
@@ -803,8 +803,8 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e1.path, deque(["bar"]))
self.assertEqual(e2.path, deque(["foo"]))
- self.assertEqual(e1.json_path, '$.bar')
- self.assertEqual(e2.json_path, '$.foo')
+ self.assertEqual(e1.json_path, "$.bar")
+ self.assertEqual(e2.json_path, "$.foo")
self.assertEqual(e1.validator, "type")
self.assertEqual(e2.validator, "minimum")
@@ -823,8 +823,8 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e1.path, deque([0]))
self.assertEqual(e2.path, deque([1]))
- self.assertEqual(e1.json_path, '$[0]')
- self.assertEqual(e2.json_path, '$[1]')
+ self.assertEqual(e1.json_path, "$[0]")
+ self.assertEqual(e2.json_path, "$[1]")
self.assertEqual(e1.validator, "type")
self.assertEqual(e2.validator, "minimum")
@@ -843,8 +843,8 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(e1.path, deque([1]))
self.assertEqual(e2.path, deque([2]))
- self.assertEqual(e1.json_path, '$[1]')
- self.assertEqual(e2.json_path, '$[2]')
+ self.assertEqual(e1.json_path, "$[1]")
+ self.assertEqual(e2.json_path, "$[2]")
self.assertEqual(e1.validator, "type")
self.assertEqual(e2.validator, "minimum")
@@ -862,7 +862,7 @@ class TestValidationErrorDetails(TestCase):
"%r is not allowed for %r" % ({"const": "foo"}, "foo"),
)
self.assertEqual(error.path, deque([]))
- self.assertEqual(error.json_path, '$')
+ self.assertEqual(error.json_path, "$")
self.assertEqual(error.schema_path, deque(["propertyNames", "not"]))
def test_if_then(self):
@@ -877,7 +877,7 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(error.validator, "const")
self.assertEqual(error.message, "13 was expected")
self.assertEqual(error.path, deque([]))
- self.assertEqual(error.json_path, '$')
+ self.assertEqual(error.json_path, "$")
self.assertEqual(error.schema_path, deque(["then", "const"]))
def test_if_else(self):
@@ -892,7 +892,7 @@ class TestValidationErrorDetails(TestCase):
self.assertEqual(error.validator, "const")
self.assertEqual(error.message, "13 was expected")
self.assertEqual(error.path, deque([]))
- self.assertEqual(error.json_path, '$')
+ self.assertEqual(error.json_path, "$")
self.assertEqual(error.schema_path, deque(["else", "const"]))
def test_boolean_schema_False(self):
@@ -916,7 +916,7 @@ class TestValidationErrorDetails(TestCase):
12,
False,
deque([]),
- '$',
+ "$",
),
)
@@ -947,7 +947,7 @@ class TestValidationErrorDetails(TestCase):
deque(["foo"]),
{"type": "integer"},
deque(["additionalProperties", "type"]),
- '$.foo',
+ "$.foo",
),
)
@@ -1129,7 +1129,7 @@ class ValidatorTestMixin(MetaSchemaTestsMixin, object):
Allow array to validate against another defined sequence type
"""
schema = {"type": "array", "uniqueItems": True}
- MyMapping = namedtuple('MyMapping', 'a, b')
+ MyMapping = namedtuple("MyMapping", "a, b")
Validator = validators.extend(
self.Validator,
type_checker=self.Validator.TYPE_CHECKER.redefine_many(
@@ -1146,20 +1146,20 @@ class ValidatorTestMixin(MetaSchemaTestsMixin, object):
validator = Validator(schema)
valid_instances = [
- deque(['a', None, '1', '', True]),
+ deque(["a", None, "1", "", True]),
deque([[False], [0]]),
[deque([False]), deque([0])],
[[deque([False])], [deque([0])]],
[[[[[deque([False])]]]], [[[[deque([0])]]]]],
[deque([deque([False])]), deque([deque([0])])],
- [MyMapping('a', 0), MyMapping('a', False)],
+ [MyMapping("a", 0), MyMapping("a", False)],
[
- MyMapping('a', [deque([0])]),
- MyMapping('a', [deque([False])]),
+ MyMapping("a", [deque([0])]),
+ MyMapping("a", [deque([False])]),
],
[
- MyMapping('a', [MyMapping('a', deque([0]))]),
- MyMapping('a', [MyMapping('a', deque([False]))]),
+ MyMapping("a", [MyMapping("a", deque([0]))]),
+ MyMapping("a", [MyMapping("a", deque([False]))]),
],
[deque(deque(deque([False]))), deque(deque(deque([0])))],
]
@@ -1168,20 +1168,20 @@ class ValidatorTestMixin(MetaSchemaTestsMixin, object):
validator.validate(instance)
invalid_instances = [
- deque(['a', 'b', 'a']),
+ deque(["a", "b", "a"]),
deque([[False], [False]]),
[deque([False]), deque([False])],
[[deque([False])], [deque([False])]],
[[[[[deque([False])]]]], [[[[deque([False])]]]]],
[deque([deque([False])]), deque([deque([False])])],
- [MyMapping('a', False), MyMapping('a', False)],
+ [MyMapping("a", False), MyMapping("a", False)],
[
- MyMapping('a', [deque([False])]),
- MyMapping('a', [deque([False])]),
+ MyMapping("a", [deque([False])]),
+ MyMapping("a", [deque([False])]),
],
[
- MyMapping('a', [MyMapping('a', deque([False]))]),
- MyMapping('a', [MyMapping('a', deque([False]))]),
+ MyMapping("a", [MyMapping("a", deque([False]))]),
+ MyMapping("a", [MyMapping("a", deque([False]))]),
],
[deque(deque(deque([False]))), deque(deque(deque([False])))],
]
diff --git a/jsonschema/validators.py b/jsonschema/validators.py
index 295cf6f..c3f7ff9 100644
--- a/jsonschema/validators.py
+++ b/jsonschema/validators.py
@@ -733,7 +733,7 @@ class RefResolver(object):
for subschema in self._finditem(schema, "$id"):
target_uri = self._urljoin_cache(
- self.resolution_scope, subschema['$id'],
+ self.resolution_scope, subschema["$id"],
)
if target_uri.rstrip("/") == uri.rstrip("/"):
if fragment: