Beispiel #1
0
def sampled_from(elements):
    """Returns a strategy which generates any value present in the iterable
    elements.

    Note that as with just, values will not be copied and thus you
    should be careful of using mutable data

    """

    from hypothesis.searchstrategy.misc import SampledFromStrategy, \
        JustStrategy
    elements = tuple(iter(elements))
    if not elements:
        raise InvalidArgument(
            u'sampled_from requires at least one value'
        )
    if len(elements) == 1:
        result = JustStrategy(elements[0])
    else:
        result = SampledFromStrategy(elements)
    return ReprWrapperStrategy(
        result, u'sampled_from((%s))' % (u', '.join(
            map(unicode_safe_repr, elements)
        ))
    )
Beispiel #2
0
def sampled_from(elements):
    """Returns a strategy which generates any value present in the iterable
    elements.

    Note that as with just, values will not be copied and thus you
    should be careful of using mutable data

    """

    from hypothesis.searchstrategy.misc import SampledFromStrategy
    elements = tuple(iter(elements))
    if not elements:
        raise InvalidArgument('sampled_from requires at least one value')
    if len(elements) == 1:
        return just(elements[0])
    return SampledFromStrategy(elements)
def sampled_from(elements):
    """Returns a strategy which generates any value present in the iterable
    elements.

    Note that as with just, values will not be copied and thus you
    should be careful of using mutable data.

    """

    from hypothesis.searchstrategy.misc import SampledFromStrategy, \
        JustStrategy
    from hypothesis.internal.conjecture.utils import check_sample
    elements = check_sample(elements)
    if not elements:
        return nothing()
    if len(elements) == 1:
        return JustStrategy(elements[0])
    return SampledFromStrategy(elements)
Beispiel #4
0
def sampled_from(elements):
    """Returns a strategy which generates any value present in the iterable
    elements.

    Note that as with just, values will not be copied and thus you
    should be careful of using mutable data

    """

    from hypothesis.searchstrategy.misc import SampledFromStrategy, \
        JustStrategy
    elements = tuple(iter(elements))
    if not elements:
        return nothing()
    if len(elements) == 1:
        return JustStrategy(elements[0])
    else:
        return SampledFromStrategy(elements)