Пример #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)
        ))
    )
Пример #2
0
 def steps(self):
     strategies = []
     for rule in self.rules():
         converted_arguments = {}
         valid = True
         if rule.precondition is not None and not rule.precondition(self):
             continue
         for k, v in rule.arguments.items():
             if isinstance(v, Bundle):
                 bundle = self.bundle(v.name)
                 if not bundle:
                     valid = False
                     break
                 else:
                     v = SimpleSampledFromStrategy(bundle)
             converted_arguments[k] = v
         if valid:
             strategies.append(
                 TupleStrategy((JustStrategy(rule),
                                FixedKeysDictStrategy(converted_arguments)),
                               tuple))
     if not strategies:
         raise InvalidDefinition(u'No progress can be made from state %r' %
                                 (self, ))
     return one_of_strategies(strategies)
Пример #3
0
def just(value):
    """Return a strategy which only generates value.

    Note: value is not copied. Be wary of using mutable values.

    """
    from hypothesis.searchstrategy.misc import JustStrategy
    return JustStrategy(value)
Пример #4
0
def just(value):
    """Return a strategy which only generates value.

    Note: value is not copied. Be wary of using mutable values.

    """
    from hypothesis.searchstrategy.misc import JustStrategy
    return ReprWrapperStrategy(
        JustStrategy(value), u'just(%s)' % (unicode_safe_repr(value),))
Пример #5
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
    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)
Пример #6
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)