def debug_data(self, data): self.debug(u'%d bytes %s -> %s, %s' % ( data.index, unicode_safe_repr(list(data.buffer[:data.index])), unicode_safe_repr(data.status), data.output, ))
def arg_string(f, args, kwargs): args, kwargs = convert_positional_arguments(f, args, kwargs) argspec = inspect.getargspec(f) bits = [] for a in argspec.args: if a in kwargs: bits.append(u'%s=%s' % (a, unicode_safe_repr(kwargs.pop(a)))) if kwargs: for a in sorted(kwargs): bits.append(u'%s=%s' % (a, unicode_safe_repr(kwargs[a]))) return u', '.join([unicode_safe_repr(x) for x in args] + bits)
def nicerepr(v): if inspect.isfunction(v): return get_pretty_function_description(v) elif isinstance(v, type): return v.__name__ else: return unicode_safe_repr(v)
def __repr__(self): try: return super(reprmangledtuple, self).__repr__() except UnicodeEncodeError: # pragma: no cover if len(self) == 1: return u"(%s,)" % (unicode_safe_repr(self[0]), ) else: return u"(%s)" % (u", ".join(map(unicode_safe_repr, self)))
def arg_string(f, args, kwargs): args, kwargs = convert_positional_arguments(f, args, kwargs) argspec = inspect.getargspec(f) bits = [] for a in argspec.args: if a in kwargs: bits.append(u'%s=%s' % (a, unicode_safe_repr(kwargs.pop(a)))) if kwargs: for a in sorted(kwargs): bits.append(u'%s=%s' % (a, unicode_safe_repr(kwargs[a]))) return u', '.join( [unicode_safe_repr(x) for x in args] + bits )
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),))
def __repr__(self): try: return super(reprmangledtuple, self).__repr__() except UnicodeEncodeError: # pragma: no cover if len(self) == 1: return u"(%s,)" % (unicode_safe_repr(self[0]),) else: return u"(%s)" % (u", ".join( map(unicode_safe_repr, self) ))
def debug_data(self, data): buffer_parts = [u"["] for i, (u, v) in enumerate(data.blocks): if i > 0: buffer_parts.append(u" || ") buffer_parts.append(u', '.join( int_to_text(int(i)) for i in data.buffer[u:v])) buffer_parts.append(u']') status = unicode_safe_repr(data.status) if data.status == Status.INTERESTING: status = u'%s (%s)' % ( status, unicode_safe_repr(data.interesting_origin, )) self.debug(u'%d bytes %s -> %s, %s' % ( data.index, u''.join(buffer_parts), status, data.output, ))
def debug_data(self, data): buffer_parts = [u"["] for i, (u, v) in enumerate(data.blocks): if i > 0: buffer_parts.append(u" || ") buffer_parts.append( u', '.join(int_to_text(int(i)) for i in data.buffer[u:v])) buffer_parts.append(u']') status = unicode_safe_repr(data.status) if data.status == Status.INTERESTING: status = u'%s (%s)' % ( status, unicode_safe_repr(data.interesting_origin,)) self.debug(u'%d bytes %s -> %s, %s' % ( data.index, u''.join(buffer_parts), status, data.output, ))
def debug_data(self, data): buffer_parts = [u"["] for i, (u, v) in enumerate(data.blocks): if i > 0: buffer_parts.append(u" || ") buffer_parts.append(u', '.join( int_to_text(int(i)) for i in data.buffer[u:v])) buffer_parts.append(u']') self.debug(u'%d bytes %s -> %s, %s' % ( data.index, u''.join(buffer_parts), unicode_safe_repr(data.status), data.output, ))
def test_sampling_snowmen(): assert unicode_safe_repr(st.sampled_from(( Frosty, u'hi'))) == u'sampled_from((☃, %s))' % (repr(u'hi'),)
def test_just_frosty(recwarn): assert unicode_safe_repr(st.just(Frosty)) == u'just(☃)' if PY2: recwarn.pop(HypothesisDeprecationWarning)
def test_sampling_snowmen(recwarn): assert unicode_safe_repr(st.sampled_from(( Frosty, u'hi'))) == u'sampled_from((☃, %s))' % (repr(u'hi'),) if PY2: recwarn.pop(HypothesisDeprecationWarning)
def calc_repr(): return u'just(%s)' % (unicode_safe_repr(value),)
def note(self, value): self.__assert_not_frozen('note') if not isinstance(value, text_type): value = unicode_safe_repr(value) self.output += value
def test_sampling_snowmen(): assert unicode_safe_repr(st.sampled_from((Frosty, u"hi"))) == u"sampled_from((☃, %s))" % (repr(u"hi"),)
def test_sampling_snowmen(): assert unicode_safe_repr(st.sampled_from( (Frosty, 'hi'))) == 'sampled_from((☃, %s))' % (repr('hi'), )
def test_just_frosty(): assert unicode_safe_repr(st.just(Frosty)) == 'just(☃)'
def simplify_template_such_that( search_strategy, random, t, f, tracker, settings, start_time ): """Perform a greedy search to produce a "simplest" version of a template that satisfies some predicate. Care is taken to avoid cycles in simplify. f should produce the same result deterministically. This function may raise an error given f such that f(t) returns False sometimes and True some other times. If f throws UnsatisfiedAssumption this will be treated the same as if it returned False. """ assert isinstance(random, Random) yield t successful_shrinks = 0 changed = True max_warmup = 5 warmup = 0 while ( (changed or warmup < max_warmup) and successful_shrinks < settings.max_shrinks ): changed = False warmup += 1 if warmup < max_warmup: debug_report('Running warmup simplification round %d' % ( warmup )) elif warmup == max_warmup: debug_report('Warmup is done. Moving on to fully simplifying') any_simplifiers = False for simplify in search_strategy.simplifiers(random, t): debug_report('Applying simplification pass %s' % ( simplify.__name__, )) any_simplifiers = True any_shrinks = False while True: simpler = simplify(random, t) if warmup < max_warmup: simpler = islice(simpler, warmup) for s in simpler: any_shrinks = True if time_to_call_it_a_day(settings, start_time): return if tracker.track(s) > 1: debug_report('Skipping simplifying to duplicate %s' % ( unicode_safe_repr(s), )) continue try: if f(s): successful_shrinks += 1 changed = True yield s t = s break except UnsatisfiedAssumption: pass else: break if not any_shrinks: debug_report('No shrinks possible') if successful_shrinks >= settings.max_shrinks: break if not any_simplifiers: debug_report('No simplifiers for template %s' % ( unicode_safe_repr(t), )) break
def nicerepr(v): if inspect.isfunction(v): return get_pretty_function_description(v) else: return unicode_safe_repr(v)
def test_just_frosty(): with pytest.warns(HypothesisDeprecationWarning): assert unicode_safe_repr(st.just(Frosty)) == u'just(☃)'
def simplify_template_such_that( search_strategy, random, t, f, tracker, settings, start_time ): """Perform a greedy search to produce a "simplest" version of a template that satisfies some predicate. Care is taken to avoid cycles in simplify. f should produce the same result deterministically. This function may raise an error given f such that f(t) returns False sometimes and True some other times. If f throws UnsatisfiedAssumption this will be treated the same as if it returned False. """ assert isinstance(random, Random) yield t successful_shrinks = 0 changed = True max_warmup = 5 warmup = 0 while ( (changed or warmup < max_warmup) and successful_shrinks < settings.max_shrinks ): changed = False warmup += 1 if warmup < max_warmup: debug_report(u'Running warmup simplification round %d' % ( warmup )) elif warmup == max_warmup: debug_report(u'Warmup is done. Moving on to fully simplifying') any_simplifiers = False for simplify in search_strategy.simplifiers(random, t): debug_report(u'Applying simplification pass %s' % ( simplify.__name__, )) any_simplifiers = True any_shrinks = False while True: simpler = simplify(random, t) if warmup < max_warmup: simpler = islice(simpler, warmup) for s in simpler: any_shrinks = True if time_to_call_it_a_day(settings, start_time): return if tracker.track(s) > 1: debug_report( u'Skipping simplifying to duplicate %s' % ( unicode_safe_repr(s), )) continue try: if f(s): successful_shrinks += 1 changed = True yield s t = s break else: yield t except UnsatisfiedAssumption: pass else: break if not any_shrinks: debug_report(u'No shrinks possible') if successful_shrinks >= settings.max_shrinks: break if not any_simplifiers: debug_report(u'No simplifiers for template %s' % ( unicode_safe_repr(t), )) break
def test_just_frosty(): assert unicode_safe_repr(st.just(Frosty)) == u'just(☃)'
def test_sampling_snowmen(): with pytest.warns(HypothesisDeprecationWarning): assert unicode_safe_repr(st.sampled_from(( Frosty, u'hi'))) == u'sampled_from((☃, %s))' % (repr(u'hi'),)
def calc_repr(): return u'just(%s)' % (unicode_safe_repr(value), )