How to use the hypothesis.strategies.one_of 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 PTB-PSt1 / PyDynamic / test / test_interpolation.py View on Github external
The drawn sample to match desired fill_value.
        """
        float_strategy = st.floats(**float_generic_params)
        tuple_strategy = st.tuples(float_strategy, float_strategy)
        string_strategy = st.just("extrapolate")
        nan_strategy = st.just(np.nan)
        if strategy_spec == "float":
            fill_strategy = float_strategy
        elif strategy_spec == "tuple":
            fill_strategy = tuple_strategy
        elif strategy_spec == "str":
            fill_strategy = string_strategy
        elif strategy_spec == "nan":
            fill_strategy = nan_strategy
        else:
            fill_strategy = st.one_of(
                float_strategy, tuple_strategy, string_strategy, nan_strategy
            )
        return draw(fill_strategy)
github PromyLOPh / crocoite / crocoite / test_browser.py View on Github external
def urls ():
    """ Build http/https URL """
    scheme = st.sampled_from (['http', 'https'])
    # Path must start with a slash
    pathSt = st.builds (lambda x: '/' + x, st.text ())
    args = st.fixed_dictionaries ({
            'scheme': scheme,
            'host': domains (),
            'port': st.one_of (st.none (), st.integers (min_value=1, max_value=2**16-1)),
            'path': pathSt,
            'query_string': st.text (),
            'fragment': st.text (),
            })
    return st.builds (lambda x: URL.build (**x), args)
github fau-fablab / FabLabKasse / FabLabKasse / cashPayment / server / helpers / test_coin_payout_helper.py View on Github external
def st_coins(draw):
    """ generator for random coin status """
    st_usual_denominations = st.sets(st.sampled_from([200, 100, 50, 20, 10, 5, 2, 1]))
    st_strange_denominations_and_duplicates = st.lists(st.integers(1, 200), average_size=8)
    coin_values = draw(st.one_of(st_usual_denominations, st_strange_denominations_and_duplicates))
    # sort descending by coin value, and convert to list
    coin_values = sorted(coin_values, reverse=True)
    coin_list = [(value, draw(st.integers(min_value=0, max_value=10))) for value in coin_values]
    return coin_list
github Phynix / yamlloader / tests / test_ordereddict.py View on Github external
def dict_val_strat(ascii_only=False):
    blacklist_characters = []
    if ascii_only:
        max_codepoint = ASCII_CODEPOINT
        blacklist_characters = ['u', "'", '"']
    else:
        max_codepoint = None
    text = st.text(alphabet=st.characters(max_codepoint=max_codepoint,
                                          blacklist_characters=blacklist_characters),
                   # avoid u'str'!
                   average_size=10, min_size=1,
                   max_size=100000)
    return st.one_of(text, st.integers(),
                     st.floats(allow_nan=False, allow_infinity=False),
                     st.lists(st.one_of(st.text(max_size=10),
                                        st.floats(allow_nan=False, allow_infinity=False),
                                        st.integers())))
github RazerM / parver / tests / strategies.py View on Github external
words = ['post']
    if not strict:
        words.extend(['r', 'rev'])

    sep1 = separator(strict=strict, optional=not strict)
    word = sampled_from(words)

    blank = just('')

    sep2 = separator(strict=strict, optional=True)
    if strict:
        sep2 = blank

    num_part = sep2.map(lambda s: s + draw(num_str))
    if not strict:
        num_part = one_of(blank, num_part)

    post = sep1.map(lambda s: s + draw(word) + draw(num_part))

    if strict:
        return draw(post)

    post_implicit = num_str.map(lambda s: '-' + s)

    return draw(one_of(blank, post_implicit, post))
github burningmantech / ranger-ims-server / src / ims / model / strategies.py View on Github external
def incidentSummaries() -> SearchStrategy:  # str
    """
    Strategy that generates incident summaries.
    """
    return one_of(none(), text())
github remorses / skema / skema / fake_data / hypo_schema.py View on Github external
def gen_any_of(prop, customs):
    possible_values = []
    for value in prop["anyOf"]:
        possible_values.append(get_generator(value, customs))

    return hs.one_of(possible_values)
github mlakewood / hypo_schema / hyposchema / hypo_schema.py View on Github external
def gen_one_of(prop):
    possible_values = []
    for value in prop["oneOf"]:
        possible_values.append(get_generator(value))

    return hs.one_of(possible_values)