summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2021-08-25 11:33:12 +0100
committerJulian Berman <Julian@GrayVines.com>2021-08-25 11:33:12 +0100
commit15ddd2f5d902007ca2c303180473b87375955671 (patch)
treeb49ebca5053a1cc66a1c932cabe72944b47b5104
parent53820379c4e9b44ae69790947a0793267a04d47d (diff)
downloadjsonschema-15ddd2f5d902007ca2c303180473b87375955671.tar.gz
Bit of coverage tweaking.v4.0.0a6
-rw-r--r--jsonschema/tests/test_cli.py6
-rw-r--r--jsonschema/tests/test_jsonschema_test_suite.py6
-rw-r--r--jsonschema/tests/test_types.py31
3 files changed, 25 insertions, 18 deletions
diff --git a/jsonschema/tests/test_cli.py b/jsonschema/tests/test_cli.py
index eafc05d..f9c8c62 100644
--- a/jsonschema/tests/test_cli.py
+++ b/jsonschema/tests/test_cli.py
@@ -10,9 +10,9 @@ import subprocess
import sys
import tempfile
-try:
+try: # pragma: no cover
from importlib import metadata
-except ImportError:
+except ImportError: # pragma: no cover
import importlib_metadata as metadata
from pyrsistent import m
@@ -36,7 +36,7 @@ def fake_validator(*errors):
def iter_errors(self, instance):
if errors:
return errors.pop()
- return []
+ return [] # pragma: no cover
@classmethod
def check_schema(self, schema):
diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py
index 23a34c9..6a367dd 100644
--- a/jsonschema/tests/test_jsonschema_test_suite.py
+++ b/jsonschema/tests/test_jsonschema_test_suite.py
@@ -42,7 +42,7 @@ def skip(message, **kwargs):
def missing_format(checker):
- def missing_format(test):
+ def missing_format(test): # pragma: no cover
schema = test.schema
if (
schema is True
@@ -93,7 +93,7 @@ else:
return
-if sys.version_info < (3, 9):
+if sys.version_info < (3, 9): # pragma: no cover
message = "Rejecting leading zeros is 3.9+"
allowed_leading_zeros = skip(
message=message,
@@ -103,7 +103,7 @@ if sys.version_info < (3, 9):
),
)
else:
- def allowed_leading_zeros(test):
+ def allowed_leading_zeros(test): # pragma: no cover
return
diff --git a/jsonschema/tests/test_types.py b/jsonschema/tests/test_types.py
index 21e8312..8a4537c 100644
--- a/jsonschema/tests/test_types.py
+++ b/jsonschema/tests/test_types.py
@@ -28,18 +28,6 @@ def is_object_or_named_tuple(checker, instance):
return is_namedtuple(instance)
-def coerce_named_tuple(fn):
- def coerced(validator, value, instance, schema):
- if is_namedtuple(instance):
- instance = instance._asdict()
- return fn(validator, value, instance, schema)
- return coerced
-
-
-required = coerce_named_tuple(_validators.required)
-properties = coerce_named_tuple(_validators.properties)
-
-
class TestTypeChecker(TestCase):
def test_is_type(self):
checker = TypeChecker({"two": equals_2})
@@ -139,6 +127,9 @@ class TestCustomTypes(TestCase):
with self.assertRaises(ValidationError):
validator.validate(4.4)
+ with self.assertRaises(ValidationError):
+ validator.validate("foo")
+
def test_object_can_be_extended(self):
schema = {"type": "object"}
@@ -179,6 +170,16 @@ class TestCustomTypes(TestCase):
"object", is_object_or_named_tuple,
)
+ def coerce_named_tuple(fn):
+ def coerced(validator, value, instance, schema):
+ if is_namedtuple(instance):
+ instance = instance._asdict()
+ return fn(validator, value, instance, schema)
+ return coerced
+
+ required = coerce_named_tuple(_validators.required)
+ properties = coerce_named_tuple(_validators.properties)
+
CustomValidator = extend(
Draft4Validator,
type_checker=type_checker,
@@ -194,6 +195,12 @@ class TestCustomTypes(TestCase):
with self.assertRaises(ValidationError):
validator.validate(Point(x="not an integer", y=5))
+ # As well as still handle objects.
+ validator.validate({"x": 4, "y": 5})
+
+ with self.assertRaises(ValidationError):
+ validator.validate({"x": "not an integer", "y": 5})
+
def test_unknown_type(self):
with self.assertRaises(UnknownType) as e:
Draft4Validator({}).is_type(12, "some unknown type")