Skip to content

Commit 041a734

Browse files
committed
covering test for deffered strategy draw
1 parent 2e522b2 commit 041a734

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

hypothesis-python/tests/cover/test_searchstrategy.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@
1717
import attr
1818
import pytest
1919

20-
from hypothesis import given
20+
from hypothesis import given, strategies as st
2121
from hypothesis.errors import InvalidArgument, Unsatisfiable
2222
from hypothesis.internal.conjecture.data import ConjectureData
2323
from hypothesis.internal.reflection import get_pretty_function_description
24-
from hypothesis.strategies import booleans, data, integers, just, lists, none, tuples
2524
from hypothesis.strategies._internal.utils import to_jsonable
2625

2726
from tests.common.debug import assert_simple_property, check_can_generate_examples
2827
from tests.common.utils import checks_deprecated_behaviour
2928

3029

3130
def test_or_errors_when_given_non_strategy():
32-
bools = tuples(booleans())
31+
bools = st.tuples(st.booleans())
3332
with pytest.raises(ValueError):
3433
bools | "foo"
3534

@@ -49,29 +48,29 @@ class WeirdRepr:
4948
def __repr__(self):
5049
return "ABCDEFG"
5150

52-
assert repr(just(WeirdRepr())) == f"just({WeirdRepr()!r})"
51+
assert repr(st.just(WeirdRepr())) == f"just({WeirdRepr()!r})"
5352

5453

5554
def test_just_strategy_does_not_draw():
5655
data = ConjectureData.for_choices([])
57-
s = just("hello")
56+
s = st.just("hello")
5857
assert s.do_draw(data) == "hello"
5958

6059

6160
def test_none_strategy_does_not_draw():
6261
data = ConjectureData.for_choices([])
63-
s = none()
62+
s = st.none()
6463
assert s.do_draw(data) is None
6564

6665

6766
def test_can_map():
68-
s = integers().map(pack=lambda t: "foo")
67+
s = st.integers().map(pack=lambda t: "foo")
6968
assert_simple_property(s, lambda v: v == "foo")
7069

7170

7271
def test_example_raises_unsatisfiable_when_too_filtered():
7372
with pytest.raises(Unsatisfiable):
74-
check_can_generate_examples(integers().filter(lambda x: False))
73+
check_can_generate_examples(st.integers().filter(lambda x: False))
7574

7675

7776
def nameless_const(x):
@@ -83,20 +82,20 @@ def f(u, v):
8382

8483
def test_can_map_nameless():
8584
f = nameless_const(2)
86-
assert get_pretty_function_description(f) in repr(integers().map(f))
85+
assert get_pretty_function_description(f) in repr(st.integers().map(f))
8786

8887

8988
def test_can_flatmap_nameless():
90-
f = nameless_const(just(3))
91-
assert get_pretty_function_description(f) in repr(integers().flatmap(f))
89+
f = nameless_const(st.just(3))
90+
assert get_pretty_function_description(f) in repr(st.integers().flatmap(f))
9291

9392

9493
def test_flatmap_with_invalid_expand():
9594
with pytest.raises(InvalidArgument):
96-
check_can_generate_examples(just(100).flatmap(lambda n: "a"))
95+
check_can_generate_examples(st.just(100).flatmap(lambda n: "a"))
9796

9897

99-
_bad_random_strategy = lists(integers(), min_size=1).map(random.choice)
98+
_bad_random_strategy = st.lists(st.integers(), min_size=1).map(random.choice)
10099

101100

102101
@checks_deprecated_behaviour
@@ -106,7 +105,7 @@ def test_use_of_global_random_is_deprecated_in_given():
106105

107106
@checks_deprecated_behaviour
108107
def test_use_of_global_random_is_deprecated_in_interactive_draws():
109-
@given(data())
108+
@given(st.data())
110109
def inner(d):
111110
d.draw(_bad_random_strategy)
112111

@@ -178,3 +177,8 @@ def test_jsonable_override():
178177
obj = HasCustomJsonFormat("expected")
179178
assert to_jsonable(obj, avoid_realization=False) == "surprise!"
180179
assert to_jsonable(obj, avoid_realization=True) == "<symbolic>"
180+
181+
182+
def test_deferred_strategy_draw():
183+
strategy = st.deferred(lambda: st.integers())
184+
assert strategy.do_draw(ConjectureData.for_choices([0])) == 0

0 commit comments

Comments
 (0)