Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_given_notices_missing_kwonly_args():
with pytest.raises(InvalidArgument):
@given(a=st.none())
def reqs_kwonly(*, a, b):
pass
def test_no_empty_examples():
with pytest.raises(InvalidArgument):
example()
def test_cannot_use_without_a_runner():
@given(st.runner())
def f(x):
pass
with pytest.raises(InvalidArgument):
f()
def test_decoding_may_fail(t):
try:
decode_failure(t)
reject()
except InvalidArgument:
pass
def test_float_free_interval_is_invalid():
lo = (2 ** 54) + 1
hi = lo + 2
assert float(lo) < lo < hi < float(hi), 'There are no floats in [lo .. hi]'
with pytest.raises(InvalidArgument):
st.floats(lo, hi).example()
def test_cannot_choose_empty():
with pytest.raises(InvalidArgument):
chooser([])
def get_lines_num(draw, lines_param):
raise InvalidArgument("Lines param must be an integer or None")
@check_function
def try_convert(typ, value, name):
if value is None:
return None
if isinstance(value, typ):
return value
try:
return typ(value)
except (TypeError, OverflowError, ValueError, ArithmeticError):
raise InvalidArgument(
"Cannot convert %s=%r of type %s to type %s"
% (name, value, type(value).__name__, typ.__name__)
)
def check_valid_bound(value, name):
"""Checks that value is either unspecified, or a valid interval bound.
Otherwise raises InvalidArgument.
"""
if value is None or isinstance(value, integer_types + (Rational,)):
return
if not isinstance(value, (Real, decimal.Decimal)):
raise InvalidArgument("%s=%r must be a real number." % (name, value))
if math.isnan(value):
raise InvalidArgument(u"Invalid end point %s=%r" % (name, value))
def check_valid_interval(lower_bound, upper_bound, lower_name, upper_name):
"""Checks that lower_bound and upper_bound are either unspecified, or they
define a valid interval on the number line.
Otherwise raises InvalidArgument.
"""
if lower_bound is None or upper_bound is None:
return
if upper_bound < lower_bound:
raise InvalidArgument(
"Cannot have %s=%r < %s=%r"
% (upper_name, upper_bound, lower_name, lower_bound)
)