Ejemplo n.º 1
0
def override_stdouts():
    """Override `sys.stdout` and `sys.stderr` with `WhateverIO`."""
    prev_out, prev_err = sys.stdout, sys.stderr
    mystdout, mystderr = WhateverIO(), WhateverIO()
    sys.stdout = sys.__stdout__ = mystdout
    sys.stderr = sys.__stderr__ = mystderr

    yield mystdout, mystderr

    sys.stdout = sys.__stdout__ = prev_out
    sys.stderr = sys.__stderr__ = prev_err
Ejemplo n.º 2
0
def wrap_logger(logger, loglevel=logging.ERROR):
    old_handlers = get_handlers(logger)
    sio = WhateverIO()
    siohandler = logging.StreamHandler(sio)
    logger.handlers = [siohandler]

    yield sio

    logger.handlers = old_handlers
Ejemplo n.º 3
0
    def request(self, **request):
        """Similar to parent class, but returns the request object as
        soon as it has created it."""
        environ = {
            'HTTP_COOKIE': unicode(self.cookies),
            'HTTP_USER_AGENT': 'Django UnitTest Client 1.0',
            'REMOTE_ADDR': '127.0.0.1',
            'PATH_INFO': '/',
            'QUERY_STRING': '',
            'REQUEST_METHOD': 'GET',
            'SCRIPT_NAME': '',
            'SERVER_NAME': 'testserver',
            'SERVER_PORT': 80,
            'SERVER_PROTOCOL': 'HTTP/1.1',
            'wsgi.input': WhateverIO(),
        }

        environ.update(self.defaults)
        environ.update(request)
        return WSGIRequest(environ)