Skip to content

Commit 4eb0b50

Browse files
committed
remove warning-compensatory changes to test suite
1 parent e84d050 commit 4eb0b50

File tree

5 files changed

+60
-89
lines changed

5 files changed

+60
-89
lines changed

hypothesis-python/tests/common/utils.py

-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import contextlib
1212
import sys
13-
import warnings
1413
from io import StringIO
1514
from types import SimpleNamespace
1615

@@ -86,16 +85,6 @@ def capture_out():
8685
sys.stdout = old_out
8786

8887

89-
class catch_sampled_from_strategies_warning(warnings.catch_warnings):
90-
def __enter__(self):
91-
warnings.filterwarnings(
92-
action="ignore",
93-
message="sample_from was given a collection of strategies; was one_of intended?",
94-
category=UserWarning,
95-
)
96-
super().__enter__()
97-
98-
9988
class ExcInfo:
10089
pass
10190

hypothesis-python/tests/cover/test_lookup.py

+9-18
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@
4242
find_any,
4343
minimal,
4444
)
45-
from tests.common.utils import (
46-
catch_sampled_from_strategies_warning,
47-
fails_with,
48-
temp_registered,
49-
)
45+
from tests.common.utils import fails_with, temp_registered
5046

5147
sentinel = object()
5248
BUILTIN_TYPES = tuple(
@@ -319,24 +315,19 @@ class Baz(Foo):
319315
[
320316
# Expect a warning exactly when the type constraint/bound should trigger
321317
# passing a strategy to sampled_from.
322-
(typing.TypeVar("V"), object, False),
323-
(typing.TypeVar("V", bound=int), int, False),
324-
(typing.TypeVar("V", bound=Foo), (Bar, Baz), True),
325-
(typing.TypeVar("V", bound=typing.Union[int, str]), (int, str), True),
326-
(typing.TypeVar("V", int, str), (int, str), False),
318+
(typing.TypeVar("V"), object),
319+
(typing.TypeVar("V", bound=int), int),
320+
(typing.TypeVar("V", bound=Foo), (Bar, Baz)),
321+
(typing.TypeVar("V", bound=typing.Union[int, str]), (int, str)),
322+
(typing.TypeVar("V", int, str), (int, str)),
327323
],
328324
)
329325
@settings(suppress_health_check=[HealthCheck.too_slow])
330326
@given(data=st.data())
331-
def test_typevar_type_is_consistent(data, var, expected, exp_warn):
327+
def test_typevar_type_is_consistent(data, var, expected):
332328
strat = st.from_type(var)
333-
if exp_warn:
334-
with catch_sampled_from_strategies_warning():
335-
v1 = data.draw(strat)
336-
v2 = data.draw(strat)
337-
else:
338-
v1 = data.draw(strat)
339-
v2 = data.draw(strat)
329+
v1 = data.draw(strat)
330+
v2 = data.draw(strat)
340331
assume(v1 != v2) # Values may vary, just not types
341332
assert type(v1) == type(v2)
342333
assert isinstance(v1, expected)

hypothesis-python/tests/nocover/test_pretty_repr.py

+31-33
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
from hypothesis.control import reject
1717
from hypothesis.errors import HypothesisDeprecationWarning, InvalidArgument
1818

19-
from tests.common.utils import catch_sampled_from_strategies_warning
20-
2119

2220
def foo(x):
2321
pass
@@ -53,39 +51,39 @@ def splat(value):
5351

5452
values = st.integers() | st.text()
5553

56-
with catch_sampled_from_strategies_warning():
57-
Strategies = st.recursive(
58-
st.one_of(
59-
st.sampled_from(
60-
[
61-
st.none(),
62-
st.booleans(),
63-
st.randoms(use_true_random=True),
64-
st.complex_numbers(),
65-
st.randoms(use_true_random=True),
66-
st.fractions(),
67-
st.decimals(),
68-
]
69-
),
70-
st.builds(st.just, values),
71-
st.builds(st.sampled_from, st.lists(values, min_size=1)),
72-
builds_ignoring_invalid(st.floats, st.floats(), st.floats()),
54+
55+
Strategies = st.recursive(
56+
st.one_of(
57+
st.sampled_from(
58+
[
59+
st.none(),
60+
st.booleans(),
61+
st.randoms(use_true_random=True),
62+
st.complex_numbers(),
63+
st.randoms(use_true_random=True),
64+
st.fractions(),
65+
st.decimals(),
66+
]
7367
),
74-
lambda x: st.one_of(
75-
builds_ignoring_invalid(st.lists, x, **size_strategies),
76-
builds_ignoring_invalid(st.sets, x, **size_strategies),
77-
builds_ignoring_invalid(lambda v: st.tuples(*v), st.lists(x)),
78-
builds_ignoring_invalid(lambda v: st.one_of(*v), st.lists(x, min_size=1)),
79-
builds_ignoring_invalid(
80-
st.dictionaries,
81-
x,
82-
x,
83-
dict_class=st.sampled_from([dict, OrderedDict]),
84-
**size_strategies,
85-
),
86-
st.builds(lambda s, f: s.map(f), x, st.sampled_from(fns)),
68+
st.builds(st.just, values),
69+
st.builds(st.sampled_from, st.lists(values, min_size=1)),
70+
builds_ignoring_invalid(st.floats, st.floats(), st.floats()),
71+
),
72+
lambda x: st.one_of(
73+
builds_ignoring_invalid(st.lists, x, **size_strategies),
74+
builds_ignoring_invalid(st.sets, x, **size_strategies),
75+
builds_ignoring_invalid(lambda v: st.tuples(*v), st.lists(x)),
76+
builds_ignoring_invalid(lambda v: st.one_of(*v), st.lists(x, min_size=1)),
77+
builds_ignoring_invalid(
78+
st.dictionaries,
79+
x,
80+
x,
81+
dict_class=st.sampled_from([dict, OrderedDict]),
82+
**size_strategies,
8783
),
88-
)
84+
st.builds(lambda s, f: s.map(f), x, st.sampled_from(fns)),
85+
),
86+
)
8987

9088

9189
strategy_globals = {k: getattr(st, k) for k in dir(st)}

hypothesis-python/tests/nocover/test_reusable_values.py

+18-21
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
from hypothesis import example, given, strategies as st
1414
from hypothesis.errors import InvalidArgument
1515

16-
from tests.common.utils import catch_sampled_from_strategies_warning
17-
1816
# Be aware that tests in this file pass strategies as arguments to @example.
1917
# That's normally a mistake, but for these tests it's intended.
2018
# If one of these tests fails, Hypothesis will complain about the
@@ -47,25 +45,24 @@
4745
def reusable():
4846
"""Meta-strategy that produces strategies that should have
4947
``.has_reusable_values == True``."""
50-
with catch_sampled_from_strategies_warning():
51-
return st.one_of(
52-
# This looks like it should be `one_of`, but `sampled_from` is correct
53-
# because we want this meta-strategy to yield strategies as its values.
54-
st.sampled_from(base_reusable_strategies),
55-
# This sometimes produces invalid combinations of arguments, which
56-
# we filter out further down with an explicit validation check.
57-
st.builds(
58-
st.floats,
59-
min_value=st.none() | st.floats(allow_nan=False),
60-
max_value=st.none() | st.floats(allow_nan=False),
61-
allow_infinity=st.booleans(),
62-
allow_nan=st.booleans(),
63-
),
64-
st.builds(st.just, st.builds(list)),
65-
st.builds(st.sampled_from, st.lists(st.builds(list), min_size=1)),
66-
st.lists(reusable).map(st.one_of),
67-
st.lists(reusable).map(lambda ls: st.tuples(*ls)),
68-
)
48+
return st.one_of(
49+
# This looks like it should be `one_of`, but `sampled_from` is correct
50+
# because we want this meta-strategy to yield strategies as its values.
51+
st.sampled_from(base_reusable_strategies),
52+
# This sometimes produces invalid combinations of arguments, which
53+
# we filter out further down with an explicit validation check.
54+
st.builds(
55+
st.floats,
56+
min_value=st.none() | st.floats(allow_nan=False),
57+
max_value=st.none() | st.floats(allow_nan=False),
58+
allow_infinity=st.booleans(),
59+
allow_nan=st.booleans(),
60+
),
61+
st.builds(st.just, st.builds(list)),
62+
st.builds(st.sampled_from, st.lists(st.builds(list), min_size=1)),
63+
st.lists(reusable).map(st.one_of),
64+
st.lists(reusable).map(lambda ls: st.tuples(*ls)),
65+
)
6966

7067

7168
def is_valid(s):

hypothesis-python/tests/nocover/test_strategy_state.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
tuples,
3535
)
3636

37-
from tests.common.utils import catch_sampled_from_strategies_warning
38-
3937
AVERAGE_LIST_LENGTH = 2
4038

4139

@@ -185,8 +183,7 @@ def repr_is_good(self, strat):
185183

186184
MAIN = __name__ == "__main__"
187185

188-
with catch_sampled_from_strategies_warning():
189-
TestHypothesis = HypothesisSpec.TestCase
186+
TestHypothesis = HypothesisSpec.TestCase
190187

191188
TestHypothesis.settings = settings(
192189
TestHypothesis.settings,
@@ -196,5 +193,4 @@ def repr_is_good(self, strat):
196193
)
197194

198195
if MAIN:
199-
with catch_sampled_from_strategies_warning():
200-
TestHypothesis().runTest()
196+
TestHypothesis().runTest()

0 commit comments

Comments
 (0)