Skip to content

Commit

Permalink
Some PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jobh committed Jun 4, 2023
1 parent b2202bf commit 714569a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 29 deletions.
6 changes: 4 additions & 2 deletions hypothesis-python/src/hypothesis/strategies/_internal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,9 @@ def everything_except(excluded_types):
rejected in a certain way.
"""
try:
return _from_type(thing, [])
with warnings.catch_warnings():
warnings.simplefilter("error")
return _from_type(thing, [])
except Exception:
return _from_type_deferred(thing)

Expand Down Expand Up @@ -1253,7 +1255,7 @@ def from_type_guarded(thing):
kwargs[k] = from_type_guarded(hints[k])
if p.default is not Parameter.empty and kwargs[k] is not ...:
kwargs[k] = just(p.default) | kwargs[k]
if not kwargs:
if not kwargs and params:
from_type_repr = repr_call(from_type, (thing,), {})
builds_repr = repr_call(builds, (thing,), {})
warnings.warn(
Expand Down
9 changes: 4 additions & 5 deletions hypothesis-python/tests/cover/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def test_attrs_inference_builds(c):
pass


with pytest.warns(SmallSearchSpaceWarning):

@given(st.from_type(Inferrables))
def test_attrs_inference_from_type(c):
pass
def test_attrs_inference_from_type():
s = st.from_type(Inferrables)
with pytest.warns(SmallSearchSpaceWarning):
s.example()
24 changes: 7 additions & 17 deletions hypothesis-python/tests/cover/test_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import string
import sys
import typing
import warnings
from inspect import signature
from numbers import Real

Expand Down Expand Up @@ -121,10 +122,6 @@ class Elem:
pass


# To avoid SmallSearchSpaceWarning
st.register_type_strategy(Elem, st.builds(Elem))


@pytest.mark.parametrize(
"typ,coll_type",
[
Expand Down Expand Up @@ -161,10 +158,6 @@ class ElemValue:
pass


# To avoid SmallSearchSpaceWarning
st.register_type_strategy(ElemValue, st.builds(ElemValue))


@pytest.mark.parametrize(
"typ,coll_type",
[
Expand Down Expand Up @@ -722,10 +715,6 @@ def foo(self):
pass


# To avoid SmallSearchSpaceWarning
st.register_type_strategy(ConcreteFoo, st.builds(ConcreteFoo))


@given(st.from_type(AbstractFoo))
def test_can_resolve_abstract_class(instance):
assert isinstance(instance, ConcreteFoo)
Expand Down Expand Up @@ -986,16 +975,17 @@ def test_from_type_can_be_default_or_annotation():

@pytest.mark.parametrize("t", BUILTIN_TYPES, ids=lambda t: t.__name__)
def test_resolves_builtin_types(t):
with pytest.warns(): # some types may warn SmallSearchSpaceWarning
with warnings.catch_warnings():
# Some types may warn SmallSearchSpaceWarning, ignore those
warnings.simplefilter("ignore")
v = st.from_type(t).example()
assert isinstance(v, t)
assert isinstance(v, t)


@pytest.mark.parametrize("t", BUILTIN_TYPES, ids=lambda t: t.__name__)
def test_resolves_forwardrefs_to_builtin_types(t):
with pytest.warns(): # some types may warn SmallSearchSpaceWarning
v = st.from_type(typing.ForwardRef(t.__name__)).example()
assert isinstance(v, t)
v = st.from_type(typing.ForwardRef(t.__name__)).example()
assert isinstance(v, t)


@pytest.mark.parametrize("t", BUILTIN_TYPES, ids=lambda t: t.__name__)
Expand Down
5 changes: 0 additions & 5 deletions hypothesis-python/tests/cover/test_lookup_py37.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ class Value:
pass


# To avoid SmallSearchSpaceWarning
st.register_type_strategy(Elem, st.builds(Elem))
st.register_type_strategy(Value, st.builds(Value))


def check(t, ex):
assert isinstance(ex, t)
assert all(isinstance(e, Elem) for e in ex)
Expand Down

0 comments on commit 714569a

Please sign in to comment.