File size: 717 Bytes
2c3c408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from hypothesis import strategies as st
from hypothesis.strategies import composite

# Helpers for Hypothesis-Python based property tests
# (custom strategies, etc.)


@composite
def bounded_ntuple(draw, *, length=1, min_value=0, max_value=10):
    """hypothesis composite strategy that returns a `length` tuple of integers
    within the range (min_value, max_value)
    """

    return draw(st.tuples(*[st.integers(min_value, max_value) for _ in range(length)]))


@composite
def ranged_slices(draw, min_value=0, max_value=10):
    bdd = st.one_of(st.none(), st.integers(min_value=min_value, max_value=max_value))
    start = draw(bdd)
    stop = draw(bdd)
    step = draw(bdd)

    return slice(start, stop, step)