Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@example('(int,bool,)', 11)
@example('(int,(address,uint256[][])', 27)
def test_parsing_invalid_type_str_causes_parse_error(type_str, error_col):
if error_col is not None:
pattern = r'Parse error at .* \(column {}\)'.format(error_col)
else:
pattern = r'Parse error at .*'
with pytest.raises(ParseError, match=pattern):
parse(type_str)
@example(b'\x00\x00\x01', 2)
@example(b'\x00\x00\x00', 1)
@example(b'\0\0', 1)
@given(st.binary(min_size=1), st.integers(0, 10))
def test_satshrink_to_one(b, n):
assume(n <= len(b))
x = satshrink(b, lambda s: len(s) >= n)
assert len(x) == n
@hypothesis.example(number=125, base=5)
def test_ceil_log_hypothesis(number, base):
exponent = utils.ceil_log(number, base)
assert base ** exponent >= number
# With base=2, number=1 we get exponent=1
# 2**1 > 1, but 2**0 == 1.
if exponent > 1:
assert base ** (exponent - 1) < number
@example('0xa1') # valid hexadecimal is still interpreted as unicode characters
def test_text_if_str_on_text(val):
to_type = Mock(return_value='zoot')
assert text_if_str(to_type, val) == 'zoot'
assert to_type.call_args == ((None, ), {'text': val})
@example(10121071034790721094712093712037123)
def test_roundtrip_int(i):
"""We can round trip what, in Python 2, would be a long."""
assert_roundtrip(i)
@example("e8")
@example(".")
@example("a" * 1050)
def test_returns_false_if_given_non_number_string(self, x):
assert not fastnumbers.isint(x)
@example(0)
@example(int(generator_256.order()))
def test_precompute(self, mul):
precomp = PointJacobi.from_affine(generator_256, True)
pj = PointJacobi.from_affine(generator_256)
a = precomp * mul
b = pj * mul
self.assertEqual(a, b)
@hypothesis.example(ts1=TimeSpan(), ts2=timespans().example())
def test_intersection_commutable(ts1, ts2):
# Commutable
assert ts2 * ts1 == (ts1 & ts2)
@example(-1)
@given(integers())
def test_positive(x):
assert x > 0
def add_examples(test: Callable, endpoint: Endpoint) -> Callable:
"""Add examples to the Hypothesis test, if they are specified in the schema."""
for case in get_examples(endpoint):
test = hypothesis.example(case)(test)
return test