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
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)
def test_samples_from_a_range_directly(): s = cu.check_sample(range(10**1000), "") assert isinstance(s, range)
def test_valid_list_sample(): cu.check_sample([1, 2, 3], "array")
def test_invalid_set_sample(): with pytest.raises(InvalidArgument): cu.check_sample({1, 2, 3}, "array")
def test_valid_numpy_sample(): cu.check_sample(np.array([1, 2, 3]), "array")
def test_invalid_numpy_sample(): with pytest.raises(InvalidArgument): cu.check_sample(np.array([[1, 1], [1, 1]]), "array")
def __init__(self, elements): SearchStrategy.__init__(self) self.elements = cu.check_sample(elements, "sampled_from") assert self.elements
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
def __init__(self, elements): SearchStrategy.__init__(self) self.elements = d.check_sample(elements) assert self.elements
def __init__(self, elements): SearchStrategy.__init__(self) self.elements = d.check_sample(elements, 'sampled_from') assert self.elements
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