How to use the hypothesis.example function in hypothesis

To help you get started, we’ve selected a few hypothesis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethereum / eth-abi / tests / test_grammar.py View on Github external
@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)
github DRMacIver / structureshrink / tests / test_sat.py View on Github external
@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
github qutebrowser / qutebrowser / tests / unit / utils / test_utils.py View on Github external
@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
github ethereum / web3.py / tests / core / utilities / test_encoding.py View on Github external
@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})
github lordmauve / chopsticks / tests / test_pencode.py View on Github external
@example(10121071034790721094712093712037123)
def test_roundtrip_int(i):
    """We can round trip what, in Python 2, would be a long."""
    assert_roundtrip(i)
github SethMMorton / fastnumbers / tests / test_fastnumbers.py View on Github external
    @example("e8")
    @example(".")
    @example("a" * 1050)
    def test_returns_false_if_given_non_number_string(self, x):
        assert not fastnumbers.isint(x)
github warner / python-ecdsa / src / ecdsa / test_jacobi.py View on Github external
    @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)
github merchise / xoutil / tests / test_datetime.py View on Github external
@hypothesis.example(ts1=TimeSpan(), ts2=timespans().example())
def test_intersection_commutable(ts1, ts2):
    # Commutable
    assert ts2 * ts1 == (ts1 & ts2)
github HypothesisWorks / hypothesis / tests / cover / test_explicit_examples.py View on Github external
    @example(-1)
    @given(integers())
    def test_positive(x):
        assert x > 0
github kiwicom / schemathesis / src / schemathesis / _hypothesis.py View on Github external
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