|
19 | 19 | from hypothesis.internal.conjecture.providers import BytestringProvider
|
20 | 20 | from hypothesis.internal.intervalsets import IntervalSet
|
21 | 21 |
|
22 |
| -from tests.conjecture.common import float_kw, integer_kw, ir_types_and_kwargs, string_kw |
| 22 | +from tests.conjecture.common import ( |
| 23 | + float_kw, |
| 24 | + integer_kw, |
| 25 | + ir_types_and_kwargs, |
| 26 | + nodes, |
| 27 | + string_kw, |
| 28 | +) |
23 | 29 |
|
24 | 30 |
|
25 | 31 | @example(b"\x00" * 100, [("integer", integer_kw())])
|
@@ -50,20 +56,16 @@ def test_provider_contract_bytestring(bytestring, ir_type_and_kwargs):
|
50 | 56 | except StopTest:
|
51 | 57 | return
|
52 | 58 |
|
53 |
| - # ir_value_permitted is currently restricted to what *could* be generated |
54 |
| - # by the buffer. once we're fully on the TCS, we can drop this restriction. |
55 |
| - # until then, the BytestringProvider can theoretically generate values |
56 |
| - # that aren't forcable to a buffer - but this requires an enormous shrink_towards |
57 |
| - # value and is such an edge case that I'm just going to bank on nobody hitting |
58 |
| - # it before we're off the bytestring. |
59 |
| - integer_edge_case = ( |
60 |
| - ir_type == "integer" |
61 |
| - and kwargs["shrink_towards"] is not None |
62 |
| - and kwargs["shrink_towards"].bit_length() > 100 |
63 |
| - ) |
64 |
| - assert choice_permitted(value, kwargs) or integer_edge_case |
65 |
| - |
| 59 | + assert choice_permitted(value, kwargs) |
66 | 60 | kwargs["forced"] = choice_from_index(0, ir_type, kwargs)
|
67 | 61 | assert choice_equal(
|
68 | 62 | kwargs["forced"], getattr(data, f"draw_{ir_type}")(**kwargs)
|
69 | 63 | )
|
| 64 | + |
| 65 | + |
| 66 | +@given(st.lists(nodes()), st.randoms()) |
| 67 | +def test_provider_contract_hypothesis(nodes, random): |
| 68 | + data = ConjectureData(random=random) |
| 69 | + for node in nodes: |
| 70 | + value = getattr(data, f"draw_{node.ir_type}")(**node.kwargs) |
| 71 | + assert choice_permitted(value, node.kwargs) |
0 commit comments