def __call__(self, values): if not values: raise IndexError('Cannot choose from empty sequence') result = choice(self.data, values) with self.build_context.local(): self.choice_count += 1 note('Choice #%d: %r' % (self.choice_count, result)) return result
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 draw(self, strategy, label=None): self.data.mark_bind() result = self.data.draw(strategy) self.count += 1 if label is not None: note('Draw %d (%s): %r' % (self.count, label, result)) else: note('Draw %d: %r' % (self.count, result)) return result
def inner(*args, **kwargs): if data.frozen: raise InvalidState( "This generated %s function can only be called within the " "scope of the @given that created it." % (nicerepr(self.like), )) val = data.draw(self.returns) note("Called function: %s(%s) -> %r" % (nicerepr( self.like), arg_string(self.like, args, kwargs), val)) return val
def inner(*args, **kwargs): if data.frozen: raise InvalidState( "This generated %s function can only be called within the " "scope of the @given that created it." % (nicerepr(self.like),) ) data.can_reproduce_example_from_repr = False val = data.draw(self.returns) note( "Called function: %s(%s) -> %r" % (nicerepr(self.like), arg_string(self.like, args, kwargs), val) ) return val
def run(data): from hypothesis.control import note with BuildContext(is_final=is_final): seed = data.draw(random_module()).seed if seed != 0: note("random.seed(%d)" % (seed,)) args, kwargs = data.draw(search_strategy) if print_example: report(lambda: "Falsifying example: %s(%s)" % (test.__name__, arg_string(test, args, kwargs))) elif current_verbosity() >= Verbosity.verbose: report(lambda: "Trying example: %s(%s)" % (test.__name__, arg_string(test, args, kwargs))) return test(*args, **kwargs)
def inner(*args, **kwargs): if data.frozen: raise InvalidState( "This generated %s function can only be called within the " "scope of the @given that created it." % (nicerepr(self.like), )) if self.pure: args, kwargs = convert_positional_arguments( self.like, args, kwargs) key = (inner, args, frozenset(kwargs.items())) val = data.draw(SharedStrategy(base=self.returns, key=key)) else: val = data.draw(self.returns) note("Called function: %s(%s) -> %r" % (nicerepr( self.like), arg_string(self.like, args, kwargs), val)) return val
def run(data): from hypothesis.control import note with BuildContext(is_final=is_final): seed = data.draw(random_module()).seed if seed != 0: note('random.seed(%d)' % (seed, )) args, kwargs = data.draw(search_strategy) if print_example: report(lambda: 'Falsifying example: %s(%s)' % (test.__name__, arg_string(test, args, kwargs))) elif current_verbosity() >= Verbosity.verbose: report(lambda: 'Trying example: %s(%s)' % (test.__name__, arg_string(test, args, kwargs))) return test(*args, **kwargs)
def choice(values): if not values: raise IndexError('Cannot choose from empty sequence') k = len(values) - 1 if k == 0: chosen = 0 else: mask = _right_saturate(k) while True: index[0] += 1 probe = stream[index[0]] & mask if probe <= k: chosen = probe break choice_count[0] += 1 result = values[chosen] with context.local(): note('Choice #%d: %r' % (choice_count[0], result)) return result
def inner(*args, **kwargs): if data.frozen: raise InvalidState( f"This generated {nicerepr(self.like)} function can only " "be called within the scope of the @given that created it." ) if self.pure: args, kwargs = convert_positional_arguments( self.like, args, kwargs) key = (args, frozenset(kwargs.items())) cache = self._cache.setdefault(inner, {}) if key not in cache: cache[key] = data.draw(self.returns) rep = repr_call(self.like, args, kwargs, reorder=False) note(f"Called function: {rep} -> {cache[key]!r}") return cache[key] else: val = data.draw(self.returns) rep = repr_call(self.like, args, kwargs, reorder=False) note(f"Called function: {rep} -> {val!r}") return val
def test(x): generated_integers.append(x) note(notefmt(x)) assert x < 5
def test(x): msg = 'x -> %d' % (x,) note(msg) messages.add(msg) assert x < 5
def test_raises_if_note_out_of_context(): with pytest.raises(InvalidArgument): note('Hi')
def test(x): msg = f"x -> {x}" note(msg) messages.add(msg) assert x < 5
def draw(self, strategy): result = self.data.draw(strategy) self.count += 1 note('Draw %d: %r' % (self.count, result)) return result
def test(x): msg = 'x -> %d' % (x, ) note(msg) messages.add(msg) assert x < 5