Skip to content

Commit

Permalink
Bit of coverage tweaking.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Aug 25, 2021
1 parent 5382037 commit 15ddd2f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
6 changes: 3 additions & 3 deletions jsonschema/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
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
Expand All @@ -36,7 +36,7 @@ def __init__(self, *args, **kwargs):
def iter_errors(self, instance):
if errors:
return errors.pop()
return []
return [] # pragma: no cover

@classmethod
def check_schema(self, schema):
Expand Down
6 changes: 3 additions & 3 deletions jsonschema/tests/test_jsonschema_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def skipper(test):


def missing_format(checker):
def missing_format(test):
def missing_format(test): # pragma: no cover
schema = test.schema
if (
schema is True
Expand Down Expand Up @@ -93,7 +93,7 @@ def narrow_unicode_build(test): # pragma: no cover
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,
Expand All @@ -103,7 +103,7 @@ def narrow_unicode_build(test): # pragma: no cover
),
)
else:
def allowed_leading_zeros(test):
def allowed_leading_zeros(test): # pragma: no cover
return


Expand Down
31 changes: 19 additions & 12 deletions jsonschema/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -139,6 +127,9 @@ def int_or_str_int(checker, instance):
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"}

Expand Down Expand Up @@ -179,6 +170,16 @@ def test_object_extensions_can_handle_custom_validators(self):
"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,
Expand All @@ -194,6 +195,12 @@ def test_object_extensions_can_handle_custom_validators(self):
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")
Expand Down

0 comments on commit 15ddd2f

Please sign in to comment.