def test_increasing_integers_from_sequence():
    n = 6
    lb = 50000
    xs = minimal(
        [integers_from(0)], lambda t: (
            n <= len(t) and
            all(t) and
            any(s >= lb for s in t) and
            length_of_longest_ordered_sequence(t) >= n
        ),
        timeout_after=20,
    )
    assert n <= len(xs) <= n + 2
Пример #2
0
def define_fraction_strategy(specifier, settings):
    return strategy((int, specifiers.integers_from(1))).map(
        lambda t: Fraction(*t)
    )
Пример #3
0
from tests.common.specifiers import Descriptor
from hypothesis.strategytests import TemplatesFor, strategy_test_suite
from hypothesis.internal.compat import text_type, binary_type
from hypothesis.searchstrategy.basic import basic_strategy
from hypothesis.searchstrategy.narytree import NAryTree

TestIntegerRange = strategy_test_suite(integers_in_range(0, 5))
TestGiantIntegerRange = strategy_test_suite(
    integers_in_range(-(2 ** 129), 2 ** 129)
)
TestFloatRange = strategy_test_suite(floats_in_range(0.5, 10))
TestSampled10 = strategy_test_suite(sampled_from(elements=list(range(10))))
TestSampled1 = strategy_test_suite(sampled_from(elements=(1,)))
TestSampled2 = strategy_test_suite(sampled_from(elements=(1, 2)))

TestIntegersFrom = strategy_test_suite(integers_from(13))

TestOneOf = strategy_test_suite(one_of((int, int, bool)))
TestOneOfSameType = strategy_test_suite(
    one_of((integers_in_range(1, 10), integers_in_range(8, 15)))
)
TestRandom = strategy_test_suite(Random)
TestInts = strategy_test_suite(int)
TestBoolLists = strategy_test_suite([bool])
TestDictionaries = strategy_test_suite(dictionary((int, int), bool))
TestOrderedDictionaries = strategy_test_suite(
    dictionary(int, int, OrderedDict)
)
TestString = strategy_test_suite(text_type)
BinaryString = strategy_test_suite(binary_type)
TestIntBool = strategy_test_suite((int, bool))
Пример #4
0
def test_minimizes_ints_from_down_to_boundary(boundary):
    assert find(integers_from(boundary - 10),
                lambda x: x >= boundary) == boundary

    assert find(integers_from(boundary), lambda x: True) == boundary
Пример #5
0
def test_integers_from_minizes_leftwards():
    assert minimal(integers_from(101)) == 101
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


@given(integers_from(100))
def test_integers_from_are_from(x):
    assert x >= 100


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()
Пример #7
0
def test_integers_from():
    assert find(s.integers_from(10), lambda x: True) == 10
Пример #8
0

ABC = namedtuple('ABC', ('a', 'b', 'c'))

standard_types = [
    Bitfields,
    [], (), set(), frozenset(), {},
    NAryTree(bool, bool, bool),
    ABC(bool, bool, bool),
    ABC(bool, bool, int),
    {'a': int, 'b': bool},
    one_of((int, (bool,))),
    sampled_from(range(10)),
    one_of((just('a'), just('b'), just('c'))),
    sampled_from(('a', 'b', 'c')),
    int, integers_from(3), integers_in_range(-2 ** 32, 2 ** 64),
    float, floats_in_range(-2.0, 3.0),
    text_type, binary_type,
    bool,
    (bool, bool),
    frozenset({int}),
    complex,
    Fraction,
    Decimal,
    [[bool]],
    OrderedPair, ConstantList(int),
    strategy(streaming(int)).map(lambda x: list(x[:2]) and x),
    strategy(int).filter(lambda x: abs(x) > 100),
    floats_in_range(-sys.float_info.max, sys.float_info.max),
    None, Random,
]
Пример #9
0
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


@given(integers_from(100))
def test_integers_from_are_from(x):
    assert x >= 100


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()
Пример #10
0
def ordered_pair_strategy(_, settings):
    return strategy(int, settings).flatmap(
        lambda right: strategy(integers_from(0), settings).map(
            lambda length: OrderedPair(right - length, right)))
Пример #11
0
 set(),
 frozenset(),
 {},
 NAryTree(bool, bool, bool),
 ABC(bool, bool, bool),
 ABC(bool, bool, int),
 {
     'a': int,
     'b': bool
 },
 one_of((int, (bool, ))),
 sampled_from(range(10)),
 one_of((just('a'), just('b'), just('c'))),
 sampled_from(('a', 'b', 'c')),
 int,
 integers_from(3),
 integers_in_range(-2**32, 2**64),
 float,
 floats_in_range(-2.0, 3.0),
 text_type,
 binary_type,
 bool,
 (bool, bool),
 frozenset({int}),
 complex,
 Fraction,
 Decimal,
 [[bool]],
 OrderedPair,
 ConstantList(int),
 strategy(streaming(int)).map(lambda x: list(x[:2]) and x),
Пример #12
0
def test_minimizes_ints_from_down_to_boundary(boundary):
    assert find(
        integers_from(boundary - 10), lambda x: x >= boundary) == boundary

    assert find(integers_from(boundary), lambda x: True) == boundary
Пример #13
0
def test_out_of_range_integers_are_bad():
    with pytest.raises(BadData):
        strategy(integers_in_range(0, 1)).from_basic(-1)

    with pytest.raises(BadData):
        strategy(integers_from(11)).from_basic(9)
Пример #14
0
def ordered_pair_strategy(_, settings):
    return strategy(int, settings).flatmap(
        lambda right: strategy(integers_from(0), settings).map(
            lambda length: OrderedPair(right - length, right)))
Пример #15
0
    integers_in_range
from tests.common.specifiers import Descriptor
from hypothesis.strategytests import TemplatesFor, strategy_test_suite
from hypothesis.internal.compat import text_type, binary_type
from hypothesis.searchstrategy.basic import basic_strategy
from hypothesis.searchstrategy.narytree import NAryTree

TestIntegerRange = strategy_test_suite(integers_in_range(0, 5))
TestGiantIntegerRange = strategy_test_suite(
    integers_in_range(-(2**129), 2**129))
TestFloatRange = strategy_test_suite(floats_in_range(0.5, 10))
TestSampled10 = strategy_test_suite(sampled_from(elements=list(range(10))))
TestSampled1 = strategy_test_suite(sampled_from(elements=(1, )))
TestSampled2 = strategy_test_suite(sampled_from(elements=(1, 2)))

TestIntegersFrom = strategy_test_suite(integers_from(13))

TestOneOf = strategy_test_suite(one_of((int, int, bool)))
TestOneOfSameType = strategy_test_suite(
    one_of((integers_in_range(1, 10), integers_in_range(8, 15))))
TestRandom = strategy_test_suite(Random)
TestInts = strategy_test_suite(int)
TestBoolLists = strategy_test_suite([bool])
TestDictionaries = strategy_test_suite(dictionary((int, int), bool))
TestOrderedDictionaries = strategy_test_suite(dictionary(
    int, int, OrderedDict))
TestString = strategy_test_suite(text_type)
BinaryString = strategy_test_suite(binary_type)
TestIntBool = strategy_test_suite((int, bool))
TestFloats = strategy_test_suite(float)
TestComplex = strategy_test_suite(complex)
Пример #16
0
def define_fraction_strategy(specifier, settings):
    return strategy((int, specifiers.integers_from(1))).map(
        lambda t: Fraction(*t)
    )
Пример #17
0
def test_integers_from():
    assert find(s.integers_from(10), lambda x: True) == 10
Пример #18
0
def test_integers_from_minizes_leftwards():
    assert minimal(integers_from(101)) == 101