Example #1
0
 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,
     ))
Example #2
0
 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,
     ))
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
 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)))
Example #7
0
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
    )
Example #8
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),))
Example #9
0
 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)
             ))
Example #10
0
    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,
        ))
Example #11
0
    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,
        ))
Example #12
0
    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,
        ))
Example #13
0
def test_sampling_snowmen():
    assert unicode_safe_repr(st.sampled_from((
        Frosty, u'hi'))) == u'sampled_from((☃, %s))' % (repr(u'hi'),)
Example #14
0
def test_just_frosty(recwarn):
    assert unicode_safe_repr(st.just(Frosty)) == u'just(☃)'
    if PY2:
        recwarn.pop(HypothesisDeprecationWarning)
Example #15
0
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)
Example #16
0
 def calc_repr():
     return u'just(%s)' % (unicode_safe_repr(value),)
Example #17
0
 def note(self, value):
     self.__assert_not_frozen('note')
     if not isinstance(value, text_type):
         value = unicode_safe_repr(value)
     self.output += value
Example #18
0
def test_sampling_snowmen():
    assert unicode_safe_repr(st.sampled_from((Frosty, u"hi"))) == u"sampled_from((☃, %s))" % (repr(u"hi"),)
Example #19
0
def test_sampling_snowmen():
    assert unicode_safe_repr(st.sampled_from(
        (Frosty, 'hi'))) == 'sampled_from((☃, %s))' % (repr('hi'), )
Example #20
0
def test_just_frosty():
    assert unicode_safe_repr(st.just(Frosty)) == 'just(☃)'
Example #21
0
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
Example #22
0
def nicerepr(v):
    if inspect.isfunction(v):
        return get_pretty_function_description(v)
    else:
        return unicode_safe_repr(v)
Example #23
0
def test_just_frosty():
    with pytest.warns(HypothesisDeprecationWarning):
        assert unicode_safe_repr(st.just(Frosty)) == u'just(☃)'
Example #24
0
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
Example #25
0
def test_just_frosty():
    assert unicode_safe_repr(st.just(Frosty)) == u'just(☃)'
Example #26
0
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'),)
Example #27
0
 def note(self, value):
     self.__assert_not_frozen('note')
     if not isinstance(value, text_type):
         value = unicode_safe_repr(value)
     self.output += value
Example #28
0
 def calc_repr():
     return u'just(%s)' % (unicode_safe_repr(value), )