Пример #1
0
 def __call__(self, values):
     if not values:
         raise IndexError('Cannot choose from empty sequence')
     result = choice(self.data, check_sample(values))
     with self.build_context.local():
         self.choice_count += 1
         note('Choice #%d: %r' % (self.choice_count, result))
     return result
Пример #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, \
        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)
Пример #3
0
def test_samples_from_a_range_directly():
    s = cu.check_sample(range(10**1000), "")
    assert isinstance(s, range)
Пример #4
0
def test_valid_list_sample():
    cu.check_sample([1, 2, 3], "array")
Пример #5
0
def test_invalid_set_sample():
    with pytest.raises(InvalidArgument):
        cu.check_sample({1, 2, 3}, "array")
Пример #6
0
def test_valid_numpy_sample():
    cu.check_sample(np.array([1, 2, 3]), "array")
Пример #7
0
def test_invalid_numpy_sample():
    with pytest.raises(InvalidArgument):
        cu.check_sample(np.array([[1, 1], [1, 1]]), "array")
Пример #8
0
 def __init__(self, elements):
     SearchStrategy.__init__(self)
     self.elements = cu.check_sample(elements, "sampled_from")
     assert self.elements
Пример #9
0
 def __init__(self, elements, repr_=None, transformations=()):
     SearchStrategy.__init__(self)
     self.elements = cu.check_sample(elements, "sampled_from")
     assert self.elements
     self.repr_ = repr_
     self._transformations = transformations
Пример #10
0
 def __init__(self, elements):
     SearchStrategy.__init__(self)
     self.elements = d.check_sample(elements)
     assert self.elements
Пример #11
0
 def __init__(self, elements):
     SearchStrategy.__init__(self)
     self.elements = d.check_sample(elements, 'sampled_from')
     assert self.elements
Пример #12
0
 def __init__(self, elements, repr_=None, transformations=()):
     super().__init__()
     self.elements = cu.check_sample(elements, "sampled_from")
     assert self.elements
     self.repr_ = repr_
     self._transformations = transformations