|
30 | 30 | from hypothesis.internal.floats import SMALLEST_SUBNORMAL, next_down, next_up
|
31 | 31 | from hypothesis.internal.intervalsets import IntervalSet
|
32 | 32 |
|
33 |
| -from tests.conjecture.common import fresh_data, ir_types_and_kwargs |
| 33 | +from tests.conjecture.common import fresh_data, ir_types_and_kwargs, kwargs_strategy |
34 | 34 |
|
35 | 35 |
|
36 | 36 | def draw_value(ir_type, kwargs):
|
@@ -366,19 +366,33 @@ def test_data_with_empty_ir_tree_is_overrun():
|
366 | 366 |
|
367 | 367 |
|
368 | 368 | @given(st.data())
|
369 |
| -def test_data_with_misaligned_ir_tree_is_invalid(data): |
| 369 | +@settings(suppress_health_check=[HealthCheck.too_slow]) |
| 370 | +def test_node_with_different_ir_type_is_invalid(data): |
370 | 371 | node = data.draw(ir_nodes())
|
371 | 372 | (ir_type, kwargs) = data.draw(ir_types_and_kwargs())
|
372 | 373 |
|
| 374 | + # drawing a node with a different ir type should cause a misalignment. |
| 375 | + assume(ir_type != node.ir_type) |
| 376 | + |
373 | 377 | data = ConjectureData.for_ir_tree([node])
|
374 | 378 | draw_func = getattr(data, f"draw_{ir_type}")
|
375 |
| - # a misalignment occurs when we try and draw a node with a different ir |
376 |
| - # type, or with the same ir type but a non-compatible value. |
377 |
| - assume( |
378 |
| - ir_type != node.ir_type |
379 |
| - or not ir_value_permitted(node.value, node.ir_type, kwargs) |
380 |
| - ) |
| 379 | + with pytest.raises(StopTest): |
| 380 | + draw_func(**kwargs) |
| 381 | + |
| 382 | + assert data.status is Status.INVALID |
381 | 383 |
|
| 384 | + |
| 385 | +@given(st.data()) |
| 386 | +def test_node_with_same_ir_type_but_different_value_is_invalid(data): |
| 387 | + node = data.draw(ir_nodes()) |
| 388 | + kwargs = data.draw(kwargs_strategy(node.ir_type)) |
| 389 | + |
| 390 | + # drawing a node with the same ir type, but a non-compatible value, should |
| 391 | + # also cause a misalignment. |
| 392 | + assume(not ir_value_permitted(node.value, node.ir_type, kwargs)) |
| 393 | + |
| 394 | + data = ConjectureData.for_ir_tree([node]) |
| 395 | + draw_func = getattr(data, f"draw_{node.ir_type}") |
382 | 396 | with pytest.raises(StopTest):
|
383 | 397 | draw_func(**kwargs)
|
384 | 398 |
|
|
0 commit comments