Ejemplo n.º 1
0
def test_can_falsify_types_without_default_productions():
    strategies = StrategyTable()
    strategies.define_specification_for(
        Bar, lambda s, d: BarStrategy(
            s.strategy(descriptors.integers_in_range(0, 100))))

    with pytest.raises(MissingSpecification):
        StrategyTable.default().strategy(Bar)

    verifier = Verifier(strategy_table=strategies)
    assert verifier.falsify(
        lambda x: False,
        Bar,
    )[0] == Bar()
    assert verifier.falsify(lambda x: x.size() < 3, Bar)[0] == Bar(Bar(Bar()))
Ejemplo n.º 2
0
def define_binary_strategy(strategies, descriptor):
    return strat.BinaryStringStrategy(
        strategy=strategies.strategy([descriptors.integers_in_range(0, 255)]),
        descriptor=binary_type,
    )
Ejemplo n.º 3
0
def test_can_produce_and_minimize_long_lists_of_only_one_element():
    def is_a_monoculture(xs):
        assume(len(xs) >= 10)
        return len(set(xs)) > 1

    falsify(is_a_monoculture, [descriptors.integers_in_range(0, 10)])
Ejemplo n.º 4
0
    assert x == 42


@fails
@given(text_type, text_type)
def test_text_addition_is_not_commutative(x, y):
    assert x + y == y + x


@fails
@given(binary_type, binary_type)
def test_binary_addition_is_not_commutative(x, y):
    assert x + y == y + x


@given(integers_in_range(1, 10))
def test_integers_are_in_range(x):
    assert 1 <= x <= 10


def test_does_not_catch_interrupt_during_falsify():
    calls = [0]

    @given(int)
    def flaky_base_exception(x):
        if not calls[0]:
            calls[0] = 1
            raise KeyboardInterrupt()

    with pytest.raises(KeyboardInterrupt):
        flaky_base_exception()