|
21 | 21 | from hypothesis.errors import FailedHealthCheck, HypothesisWarning, InvalidArgument
|
22 | 22 | from hypothesis.internal.compat import PYPY
|
23 | 23 | from hypothesis.internal.reflection import proxies
|
| 24 | +from hypothesis.strategies._internal.regex import IncompatibleWithAlphabet |
24 | 25 |
|
25 | 26 | from hypothesis_jsonschema._canonicalise import (
|
26 | 27 | HypothesisRefResolutionError,
|
@@ -311,10 +312,19 @@ def inner(*args, **kwargs):
|
311 | 312 | try:
|
312 | 313 | f(*args, **kwargs)
|
313 | 314 | 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() |
315 | 323 | if (
|
316 | 324 | isinstance(err, HypothesisRefResolutionError)
|
317 |
| - or isinstance(err._cause, HypothesisRefResolutionError) |
| 325 | + or isinstance( |
| 326 | + getattr(err, "_cause", None), HypothesisRefResolutionError |
| 327 | + ) |
318 | 328 | ) and (
|
319 | 329 | "does not fetch remote references" in str(err)
|
320 | 330 | or name in RECURSIVE_REFS
|
@@ -360,6 +370,28 @@ def test_cannot_generate_for_empty_test_suite_schema(name):
|
360 | 370 | strat.example()
|
361 | 371 |
|
362 | 372 |
|
| 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 | + |
363 | 395 | # This schema has overlapping patternProperties - this is OK, so long as they're
|
364 | 396 | # merged or otherwise handled correctly, with the exception of the key "ab" which
|
365 | 397 | # would have to be both an integer and a string (and is thus disallowed).
|
|
0 commit comments