Skip to content

Commit

Permalink
Canonicalise deps to fixpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Jul 17, 2020
1 parent cf548f2 commit 718e70a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hypothesis_jsonschema/_canonicalise.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ def canonicalish(schema: JSONType) -> Dict[str, Any]:
# TODO: else merge schema-dependencies of required properties
# into the base schema after adding required back in and being
# careful to avoid an infinite loop...
if not schema["dependencies"]:
schema.pop("dependencies")
schema["required"] = sorted(reqs)
max_ = schema.get("maxProperties", float("inf"))
assert isinstance(max_, (int, float))
Expand Down
8 changes: 8 additions & 0 deletions tests/test_canonicalise.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def test_canonicalises_to_equivalent_fixpoint(schema_strategy, data):
jsonschema.validators.validator_for(schema).check_schema(schema)


def test_dependencies_canonicalises_to_fixpoint():
"""Check that an object drawn from an arbitrary schema is valid."""
cc = canonicalish(
{"required": [""], "properties": {"": {}}, "dependencies": {"": [""]}}
)
assert cc == canonicalish(cc)


@pytest.mark.parametrize(
"schema",
[
Expand Down

0 comments on commit 718e70a

Please sign in to comment.