Skip to content

Commit

Permalink
Merge pull request #2844 from benjeffery/fix-jsonschema-2
Browse files Browse the repository at this point in the history
Fix jsonschema validators error
  • Loading branch information
benjeffery authored Oct 4, 2023
2 parents f80e085 + 8b03221 commit e594a66
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 3 additions & 2 deletions python/tests/test_combinatorics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# MIT License
#
# Copyright (c) 2020-2022 Tskit Developers
# Copyright (c) 2020-2023 Tskit Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -27,6 +27,7 @@
import io
import itertools
import json
import math
import random

import msprime
Expand Down Expand Up @@ -1057,7 +1058,7 @@ def num_leaf_labelled_binary_trees(n):
https://oeis.org/A005373/
"""
return int(np.math.factorial(2 * n - 3) / (2 ** (n - 2) * np.math.factorial(n - 2)))
return int(math.factorial(2 * n - 3) / (2 ** (n - 2) * math.factorial(n - 2)))


class TestPolytomySplitting:
Expand Down
4 changes: 2 additions & 2 deletions python/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1603,13 +1603,13 @@ def test_bad_indexes(self, table):
table[[5.5]]
with pytest.raises(TypeError, match="Cannot convert"):
table[[None]]
with pytest.raises(TypeError, match="not supported between instances"):
with pytest.raises(TypeError, match="not supported|did not contain"):
table[["foobar"]]
with pytest.raises(TypeError, match="Index must be integer, slice or iterable"):
table[5.5]
with pytest.raises(TypeError, match="Cannot convert to a rectangular array"):
table[None]
with pytest.raises(TypeError, match="not supported between instances"):
with pytest.raises(TypeError, match="not supported|did not contain"):
table["foobar"]


Expand Down
16 changes: 13 additions & 3 deletions python/tskit/metadata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License
#
# Copyright (c) 2020-2022 Tskit Developers
# Copyright (c) 2020-2023 Tskit Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -193,7 +193,11 @@ def binary_format_validator(validator, types, instance, schema):
# generators of exceptions, hence the yielding

# Make sure the normal type validation gets done
yield from jsonschema._validators.type(validator, types, instance, schema)
try:
yield from jsonschema._validators.type(validator, types, instance, schema)
except AttributeError:
# Needed since jsonschema==4.19.1
yield from jsonschema._keywords.type(validator, types, instance, schema)

# Non-composite types must have a binaryFormat
if validator.is_type(instance, "object"):
Expand Down Expand Up @@ -222,7 +226,13 @@ def binary_format_validator(validator, types, instance, schema):

def required_validator(validator, required, instance, schema):
# Do the normal validation
yield from jsonschema._validators.required(validator, required, instance, schema)
try:
yield from jsonschema._validators.required(
validator, required, instance, schema
)
except AttributeError:
# Needed since jsonschema==4.19.1
yield from jsonschema._keywords.required(validator, required, instance, schema)

# For struct codec if a property is not required, then it must have a default
for prop, sub_schema in instance["properties"].items():
Expand Down

0 comments on commit e594a66

Please sign in to comment.