Exemplo n.º 1
0
 def wrapped_fun(*args, **kwargs):
     arg_seed = None
     if 'seed' in kwargs:
         arg_seed = kwargs['seed']
         del kwargs['seed']
     with seed(arg_seed):
         used_seed = initial_seed()
         if 'print_seed' in kwargs:
             if kwargs['print_seed']:
                 print "Random seed: %d" % used_seed
                 del kwargs['print_seed']
             # I don't know if this line is necessary, but it can't
             # hurt; and it would be a real pity to lose the
             # information you need to reproduce a segfault because
             # it was missing...
             stdout.flush()
         try:
             fn(*args, **kwargs)
         except StandardError, e:
             # We treat any sort of StandardError as a doctest
             # failure.  (We have to eat the exception, because if
             # doctesting sees an exception, it doesn't display
             # whatever was printed before the exception happened
             # -- so the text we print here would be lost.)  Note
             # that KeyboardInterrupt is not a StandardError, so
             # pressing Control-C doesn't print this message.
             print "Random testing has revealed a problem in " + fn.__name__
             print "Please report this bug!  You may be the first"
             print "person in the world to have seen this problem."
             print "Please include this random seed in your bug report:"
             print "Random seed: %d" % used_seed
             print repr(e)
Exemplo n.º 2
0
 def wrapped_fun(*args, **kwargs):
     arg_seed = None
     if 'seed' in kwargs:
         arg_seed = kwargs['seed']
         del kwargs['seed']
     with seed(arg_seed):
         used_seed = initial_seed()
         if 'print_seed' in kwargs:
             if kwargs['print_seed']:
                 print "Random seed: %d" % used_seed
                 del kwargs['print_seed']
             # I don't know if this line is necessary, but it can't
             # hurt; and it would be a real pity to lose the
             # information you need to reproduce a segfault because
             # it was missing...
             stdout.flush()
         try:
             fn(*args, **kwargs)
         except StandardError, e:
             # We treat any sort of StandardError as a doctest
             # failure.  (We have to eat the exception, because if
             # doctesting sees an exception, it doesn't display
             # whatever was printed before the exception happened
             # -- so the text we print here would be lost.)  Note
             # that KeyboardInterrupt is not a StandardError, so
             # pressing Control-C doesn't print this message.
             print "Random testing has revealed a problem in " + fn.__name__
             print "Please report this bug!  You may be the first"
             print "person in the world to have seen this problem."
             print "Please include this random seed in your bug report:"
             print "Random seed: %d" % used_seed
             print repr(e)