Пример #1
0
    def template_condition(data):
        with BuildContext(data):
            try:
                data.is_find = True
                with deterministic_PRNG():
                    result = data.draw(search)
                    data.note(result)
                    success = condition(result)
            except UnsatisfiedAssumption:
                data.mark_invalid()

        if success:
            successful_examples[0] += 1

        if settings.verbosity >= Verbosity.verbose:
            if not successful_examples[0]:
                report(
                    u'Tried non-satisfying example %s' % (nicerepr(result),))
            elif success:
                if successful_examples[0] == 1:
                    last_repr[0] = nicerepr(result)
                    report(u'Found satisfying example %s' % (last_repr[0],))
                    last_data[0] = data
                elif (
                    sort_key(hbytes(data.buffer)) <
                    sort_key(last_data[0].buffer)
                ) and nicerepr(result) != last_repr[0]:
                    last_repr[0] = nicerepr(result)
                    report(u'Shrunk example to %s' % (last_repr[0],))
                    last_data[0] = data
        if success and not data.frozen:
            data.mark_interesting()
Пример #2
0
    def template_condition(data):
        with BuildContext(data):
            try:
                data.is_find = True
                result = data.draw(search)
                data.note(result)
                success = condition(result)
            except UnsatisfiedAssumption:
                data.mark_invalid()

        if success:
            successful_examples[0] += 1

        if settings.verbosity == Verbosity.verbose:
            if not successful_examples[0]:
                report(lambda: u'Trying example %s' % (
                    nicerepr(result),
                ))
            elif success:
                if successful_examples[0] == 1:
                    report(lambda: u'Found satisfying example %s' % (
                        nicerepr(result),
                    ))
                else:
                    report(lambda: u'Shrunk example to %s' % (
                        nicerepr(result),
                    ))
                last_data[0] = data
        if success and not data.frozen:
            data.mark_interesting()
Пример #3
0
    def template_condition(data):
        with BuildContext(data):
            try:
                data.is_find = True
                with deterministic_PRNG():
                    result = data.draw(search)
                    data.note(result)
                    success = condition(result)
            except UnsatisfiedAssumption:
                data.mark_invalid()

        if success:
            successful_examples[0] += 1

        if settings.verbosity >= Verbosity.verbose:
            if not successful_examples[0]:
                report(u"Tried non-satisfying example %s" %
                       (nicerepr(result), ))
            elif success:
                if successful_examples[0] == 1:
                    last_repr[0] = nicerepr(result)
                    report(u"Found satisfying example %s" % (last_repr[0], ))
                    last_data[0] = data
                elif (sort_key(hbytes(data.buffer)) < sort_key(
                        last_data[0].buffer)
                      ) and nicerepr(result) != last_repr[0]:
                    last_repr[0] = nicerepr(result)
                    report(u"Shrunk example to %s" % (last_repr[0], ))
                    last_data[0] = data
        if success and not data.frozen:
            data.mark_interesting()
Пример #4
0
    def template_condition(data):
        with BuildContext(data):
            try:
                data.is_find = True
                result = data.draw(search)
                data.note(result)
                success = condition(result)
            except UnsatisfiedAssumption:
                data.mark_invalid()

        if success:
            successful_examples[0] += 1

        if settings.verbosity == Verbosity.verbose:
            if not successful_examples[0]:
                report(lambda: u'Trying example %s' % (
                    nicerepr(result),
                ))
            elif success:
                if successful_examples[0] == 1:
                    report(lambda: u'Found satisfying example %s' % (
                        nicerepr(result),
                    ))
                    last_data[0] = data
                elif (
                    sort_key(hbytes(data.buffer)) <
                    sort_key(last_data[0].buffer)
                ):
                    report(lambda: u'Shrunk example to %s' % (
                        nicerepr(result),
                    ))
                    last_data[0] = data
        if success and not data.frozen:
            data.mark_interesting()
Пример #5
0
 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
Пример #7
0
    def print_step(self, step):
        """Print a step to the current reporter.

        This is called right before a step is executed.
        """
        self.step_count = getattr(self, u'step_count', 0) + 1
        report(u'Step #%d: %s' % (self.step_count, nicerepr(step)))
Пример #8
0
    def print_step(self, step, result):
        """Print a step to the current reporter.

        This is called right after a step is executed.
        """
        self.step_count = getattr(self, "step_count", 0) + 1
        report("Step #%d: %s" % (self.step_count, nicerepr(step)))
Пример #9
0
    def print_step(self, step):
        """Print a step to the current reporter.

        This is called right before a step is executed.
        """
        self.step_count = getattr(self, u'step_count', 0) + 1
        report(u'Step #%d: %s' % (self.step_count, nicerepr(step)))
Пример #10
0
 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
Пример #11
0
def builds(target, *args, **kwargs):
    """Generates values by drawing from args and kwargs and passing them to
    target in the appropriate argument position.

    e.g. builds(target,
    integers(), flag=booleans()) would draw an integer i and a boolean b and
    call target(i, flag=b).

    """
    from hypothesis.internal.reflection import nicerepr

    def splat(value):
        return target(*value[0], **value[1])
    target_name = getattr(target, u'__name__', type(target).__name__)
    splat.__name__ = str(
        u'splat(%s)' % (target_name,)
    )
    return ReprWrapperStrategy(
        tuples(tuples(*args), fixed_dictionaries(kwargs)).map(splat),
        u'builds(%s)' % (
            u', '.join(
                [nicerepr(target)] +
                list(map(nicerepr, args)) +
                sorted([u'%s=%r' % (k, v) for k, v in kwargs.items()]))))
Пример #12
0
 def __repr__(self):
     return "%s(%s)" % (type(self).__name__, nicerepr(self.bundles))
Пример #13
0
 def __repr__(self):
     return u'%s(%s)' % (
         type(self).__name__,
         nicerepr(self.bundles),
     )
Пример #14
0
 def calc_repr():
     return u'builds(%s)' % (
         u', '.join(
             [nicerepr(target)] +
             list(map(nicerepr, args)) +
             sorted([u'%s=%r' % (k, v) for k, v in kwargs.items()])))
Пример #15
0
 def __repr__(self):
     return u'%s(%s)' % (
         type(self).__name__,
         nicerepr(self.bundles),
     )
Пример #16
0
 def __repr__(self):
     return "{}({})".format(type(self).__name__, nicerepr(self.bundles))
Пример #17
0
 def calc_repr():
     return u'builds(%s)' % (
         u', '.join([nicerepr(target)] + list(map(nicerepr, args)) +
                    sorted([u'%s=%r' % (k, v) for k, v in kwargs.items()])))