def test_canonicalises_to_equivalent_fixpoint(schema_strategy, data): """Check that an object drawn from an arbitrary schema is valid.""" schema = data.draw(schema_strategy, label="schema") cc = canonicalish(schema) assert cc == canonicalish(cc) instance = data.draw(JSON_STRATEGY | from_schema(cc), label="instance") assert is_valid(instance, schema) == is_valid(instance, cc)
def test_merge_semantics(data, s1, s2): assume(canonicalish(s1) != FALSEY and canonicalish(s2) != FALSEY) combined = merged([s1, s2]) assume(combined is not None) assume(combined != FALSEY) note(combined) ic = data.draw(from_schema(combined), label="combined") i1 = data.draw(from_schema(s1), label="s1") i2 = data.draw(from_schema(s2), label="s2") assert is_valid(ic, s1) and is_valid(ic, s2) assert is_valid(i1, s2) == is_valid(i1, combined) assert is_valid(i2, s1) == is_valid(i2, combined)
def test_generated_data_matches_schema(schema_strategy, data): """Check that an object drawn from an arbitrary schema is valid.""" schema = data.draw(schema_strategy) try: value = data.draw(from_schema(schema), "value from schema") except InvalidArgument: reject() jsonschema.validate(value, schema) # This checks that our canonicalisation is semantically equivalent. jsonschema.validate(value, canonicalish(schema))
def test_self_merge_eq_canonicalish(schema): m = merged([schema, schema]) assert m == canonicalish(schema)
def test_canonicalises_to_expected(schema, expected): assert canonicalish(schema) == expected, (schema, canonicalish(schema), expected)
def test_canonicalises_to_empty(schema): assert canonicalish(schema) == {"not": {}}, (schema, canonicalish(schema))