Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tybug committed Oct 13, 2024
1 parent 5dd6c7e commit ee057ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
15 changes: 0 additions & 15 deletions hypothesis-python/tests/conjecture/test_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,6 @@ def test_can_mark_invalid():
assert x.status == Status.INVALID


@given(st.data(), st.integers(1, 100))
def test_can_draw_weighted_integer_range(data, n):
weights = [1] * n + [0] * n
for _ in range(10):
# If the weights are working, then we'll never draw a value with weight=0
x = data.conjecture_data.draw_integer(1, 2 * n, weights=weights)
assert x <= n


@given(st.binary(min_size=10))
def test_can_draw_weighted_integer_range_2(buffer):
data = ConjectureData.for_buffer(buffer)
data.draw_integer(0, 7, weights=[1] * 8, shrink_towards=6)


def test_can_mark_invalid_with_why():
x = ConjectureData.for_buffer(b"")
with pytest.raises(StopTest):
Expand Down
4 changes: 3 additions & 1 deletion hypothesis-python/tests/conjecture/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def test_single_bounds(lo, hi, to):
def test_bounds_and_weights():
for to in (0, 1, 2):
data = ConjectureData.for_buffer([0] * 100 + [2] * 100)
val = data.draw_integer(0, 2, shrink_towards=to, weights=[1, 1, 1])
val = data.draw_integer(
0, 2, shrink_towards=to, weights={0: 0.2, 1: 0.2, 2: 0.2}
)
assert val == to, to


Expand Down
21 changes: 10 additions & 11 deletions hypothesis-python/tests/cover/test_filtered_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@
# obtain one at https://mozilla.org/MPL/2.0/.

import hypothesis.strategies as st
from hypothesis.control import BuildContext
from hypothesis.internal.conjecture.data import ConjectureData
from hypothesis.strategies._internal.strategies import FilteredStrategy

from tests.conjecture.common import run_to_buffer


def test_filter_iterations_are_marked_as_discarded():
variable_equal_to_zero = 0 # non-local references disables filter-rewriting
x = st.integers(0, 255).filter(lambda x: x == variable_equal_to_zero)

data = ConjectureData.for_buffer([0, 2, 1, 0])
x = st.integers().filter(lambda x: x == variable_equal_to_zero)

with BuildContext(data):
assert data.draw(x) == 0
@run_to_buffer
def buf(data):
data.draw_integer(forced=1)
data.draw_integer(forced=0)
data.mark_interesting()

data = ConjectureData.for_buffer(buf)
assert data.draw(x) == 0
assert data.has_discards


def test_filtered_branches_are_all_filtered():
s = FilteredStrategy(st.integers() | st.text(), (bool,))
assert all(isinstance(x, FilteredStrategy) for x in s.branches)


def test_filter_conditions_may_be_empty():
s = FilteredStrategy(st.integers(), conditions=())
s.condition(0)
Expand Down

0 comments on commit ee057ad

Please sign in to comment.