Skip to content

Commit db93f41

Browse files
committed
Another test for #105
1 parent 79c51c9 commit db93f41

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

tests/test_from_schema.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from hypothesis.errors import FailedHealthCheck, HypothesisWarning, InvalidArgument
2222
from hypothesis.internal.compat import PYPY
2323
from hypothesis.internal.reflection import proxies
24+
from hypothesis.strategies._internal.regex import IncompatibleWithAlphabet
2425

2526
from hypothesis_jsonschema._canonicalise import (
2627
HypothesisRefResolutionError,
@@ -311,10 +312,19 @@ def inner(*args, **kwargs):
311312
try:
312313
f(*args, **kwargs)
313314
assert name not in RECURSIVE_REFS
314-
except jsonschema.exceptions._RefResolutionError as err:
315+
except (
316+
jsonschema.exceptions._RefResolutionError,
317+
wre := getattr(jsonschema.exceptions, "_WrappedReferencingError", ()),
318+
) as err:
319+
if isinstance(err, wre) and isinstance(
320+
err._wrapped, jsonschema.exceptions._Unresolvable
321+
):
322+
pytest.xfail()
315323
if (
316324
isinstance(err, HypothesisRefResolutionError)
317-
or isinstance(err._cause, HypothesisRefResolutionError)
325+
or isinstance(
326+
getattr(err, "_cause", None), HypothesisRefResolutionError
327+
)
318328
) and (
319329
"does not fetch remote references" in str(err)
320330
or name in RECURSIVE_REFS
@@ -360,6 +370,28 @@ def test_cannot_generate_for_empty_test_suite_schema(name):
360370
strat.example()
361371

362372

373+
@pytest.mark.parametrize("name", to_name_params(suite))
374+
@settings(
375+
suppress_health_check=[HealthCheck.too_slow, HealthCheck.data_too_large],
376+
deadline=None,
377+
max_examples=20,
378+
)
379+
@given(data=st.data())
380+
@xfail_on_reference_resolve_error
381+
def test_constrained_alphabet_generation(data, name):
382+
note(f"{suite[name]=}")
383+
try:
384+
value = data.draw(from_schema(suite[name], codec="ascii"))
385+
except IncompatibleWithAlphabet:
386+
pytest.skip()
387+
note(f"{value=}")
388+
try:
389+
jsonschema.validate(value, suite[name])
390+
except jsonschema.exceptions.SchemaError:
391+
jsonschema.Draft4Validator(suite[name]).validate(value)
392+
json.dumps(value).encode("ascii")
393+
394+
363395
# This schema has overlapping patternProperties - this is OK, so long as they're
364396
# merged or otherwise handled correctly, with the exception of the key "ab" which
365397
# would have to be both an integer and a string (and is thus disallowed).

0 commit comments

Comments
 (0)