How to use the hypothesis.strategies.composite 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 pyta-uoft / pyta / tests / custom_hypothesis_support.py View on Github external
@hs.composite
def ifexp_node(draw, test=const_node(hs.booleans()),
               expr=const_node(), orelse=const_node()):
    # TODO: Add an option for whether expr and orelse strategies produce the same type.
    test = draw(test)
    expr = draw(expr)
    node = astroid.IfExp()
    node.postinit(test, expr, expr)
    return node
github pyta-uoft / pyta / tests / custom_hypothesis_support.py View on Github external
@hs.composite
def simple_homogeneous_set_node(draw, **kwargs):
    t = draw(primitive_types)
    homogeneous_set = draw(set_node(const_node(t()), **kwargs))
    assume(homogeneous_set.elts != set())
    return homogeneous_set
github HPAC / matchpy / tests / test_utils.py View on Github external
@st.composite
def sequence_vars(draw):
    num_vars = draw(st.integers(min_value=1, max_value=4))

    variables = []
    for i in range(num_vars):
        name = 'var{:d}'.format(i)
        count = draw(st.integers(min_value=1, max_value=4))
        minimum = draw(st.integers(min_value=0, max_value=2))

        variables.append(VariableWithCount(name, count, minimum, None))

    return variables
github HypothesisWorks / hypothesis / tests / numpy / test_fill_values.py View on Github external
@st.composite
def distinct_integers(draw):
    used = draw(st.shared(st.builds(set), key='distinct_integers.used'))
    i = draw(st.integers(0, 2 ** 64 - 1).filter(lambda x: x not in used))
    used.add(i)
    return i
github nanograv / PINT / tests / test_precision.py View on Github external
@composite
def leap_sec_day_mjd(draw):
    i = draw(sampled_from(sorted(leap_sec_days)))
    f = draw(floats(0, 1, allow_nan=False))
    return (i, f)
github daffidwilde / matching / tests / stable_roommates / util.py View on Github external
@composite
def connections(draw, players_from=text(lower), min_size=3, max_size=8):
    """ A strategy for making a set of connections between players. """

    num_players = draw(integers(min_size, max_size))

    players = draw(
        lists(
            players_from,
            min_size=num_players,
            max_size=num_players,
            unique=True,
        )
    )

    preferences = {}
    for player in players:
github HypothesisWorks / hypothesis / tests / quality / test_zig_zagging.py View on Github external
@st.composite
def problem(draw):
    b = hbytes(draw(st.binary(min_size=1, max_size=8)))
    m = int_from_bytes(b) * 256
    assume(m > 0)
    marker = draw(st.binary(max_size=8))
    bound = draw(st.integers(0, m - 1))
    return (b, marker, bound)
github cog-imperial / suspect / tests / fixtures.py View on Github external
@st.composite
def variables(draw):
    domain = draw(st.sampled_from(
        Domain.REALS,
        Domain.INTEGERS,
        Domain.BINARY,
        ))
    lower_bound = draw(st.one_of(st.none(), st.floats()))
    upper_bound = draw(st.one_of(st.none(), st.floats(min_value=lower_bound)))
    return Variable(lower_bound, upper_bound, domain)
github HypothesisWorks / hypothesis / tests / pandas / test_data_frame.py View on Github external
@st.composite
def column_strategy(draw):
    name = draw(st.none() | st.text())
    dtype = draw(npst.scalar_dtypes().filter(supported_by_pandas))
    pass_dtype = not draw(st.booleans())
    if pass_dtype:
        pass_elements = not draw(st.booleans())
    else:
        pass_elements = True
    if pass_elements:
        elements = npst.from_dtype(dtype)
    else:
        elements = None

    unique = draw(st.booleans())
    fill = st.nothing() if draw(st.booleans()) else None
github burningmantech / ranger-ims-server / src / ims / model / strategies.py View on Github external
@composite
def incidentTypesText(draw: Callable) -> str:
    return draw(text(min_size=1))