| 1 |
# This file is part of Hypothesis, which may be found at |
| 2 |
# https://github.com/HypothesisWorks/hypothesis/ |
| 3 |
# |
| 4 |
# Copyright the Hypothesis Authors. |
| 5 |
# Individual contributors are listed in AUTHORS.rst and the git log. |
| 6 |
# |
| 7 |
# This Source Code Form is subject to the terms of the Mozilla Public License, |
| 8 |
# v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 9 |
# obtain one at https://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
import pytest |
| 12 |
|
| 13 |
from hypothesis import given, settings, strategies as st |
| 14 |
from hypothesis._settings import note_deprecation |
| 15 |
from hypothesis.errors import HypothesisDeprecationWarning |
| 16 |
|
| 17 |
from tests.common.utils import Why, xfail_on_crosshair |
| 18 |
|
| 19 |
|
| 20 |
def test_note_deprecation_blames_right_code_issue_652(): |
| 21 |
msg = "this is an arbitrary deprecation warning message" |
| 22 |
|
| 23 |
@st.composite |
| 24 |
def deprecated_strategy(draw): |
| 25 |
draw(st.none()) |
| 26 |
note_deprecation(msg, since="RELEASEDAY", has_codemod=False) |
| 27 |
|
| 28 |
@given(deprecated_strategy()) |
| 29 |
def f(x): |
| 30 |
pass |
| 31 |
|
| 32 |
with pytest.warns(HypothesisDeprecationWarning) as log: |
| 33 |
f() |
| 34 |
|
| 35 |
assert len(log) == 1 |
| 36 |
(record,) = log |
| 37 |
# We got the warning we expected, from the right file |
| 38 |
assert isinstance(record.message, HypothesisDeprecationWarning) |
| 39 |
assert record.message.args == (msg,) |
| 40 |
assert record.filename == __file__ |
| 41 |
|
| 42 |
|
| 43 |
@given( |
| 44 |
x=st.one_of(st.just(0) | st.just(1)), |
| 45 |
y=st.one_of(st.just(0) | st.just(1) | st.just(2)), |
| 46 |
) |
| 47 |
def test_performance_issue_2027(x, y): |
| 48 |
pass |
| 49 |
|
| 50 |
|
| 51 |
@given( |
| 52 |
st.lists( |
| 53 |
st.floats(allow_infinity=False), |
| 54 |
unique=True, |
| 55 |
) |
| 56 |
) |
| 57 |
def test_unique_floats_with_nan_is_not_flaky_3926(ls): |
| 58 |
pass |
| 59 |
|
| 60 |
|
| 61 |
# this will take a while to find the regression, but will eventually trigger it. |
| 62 |
# min_value=0 is critical to trigger the probing behavior which exhausts our buffer. |
| 63 |
# https://github.com/pschanely/CrossHair/issues/285 for an upstream fix. |
| 64 |
@xfail_on_crosshair(Why.other, strict=False) |
| 65 |
@given(st.integers(min_value=0, max_value=1 << 25_000)) |
| 66 |
def test_overrun_during_datatree_simulation_3874(n): |
| 67 |
pass |
| 68 |
|
| 69 |
|
| 70 |
def test_explain_phase_label_assertion_4339(): |
| 71 |
# st.composite causes a re-creation of the SampledFromStrategy each time |
| 72 |
# (one_of is implemented using sampled_from internally), which previously |
| 73 |
# had different labels which triggered an assertion in the explain code. |
| 74 |
@st.composite |
| 75 |
def g(draw): |
| 76 |
draw(st.none() | st.booleans()) |
| 77 |
|
| 78 |
@given(g(), st.none() | st.booleans()) |
| 79 |
@settings(database=None) |
| 80 |
def f(a, b): |
| 81 |
raise ValueError("marker") |
| 82 |
|
| 83 |
with pytest.raises(ValueError, match="marker"): |
| 84 |
f() |