Ejemplo n.º 1
0
 def test_stdlib_methods_support(self, method):
     """
     PrintLogger implements methods of stdlib loggers.
     """
     sio = StringIO()
     getattr(PrintLogger(sio), method)('hello')
     assert 'hello' in sio.getvalue()
Ejemplo n.º 2
0
 def test_stdlib_methods_support(self, method):
     """
     PrintLogger implements methods of stdlib loggers.
     """
     sio = StringIO()
     getattr(PrintLogger(sio), method)('hello')
     assert 'hello' in sio.getvalue()
Ejemplo n.º 3
0
 def test_writesOnlyMessageWithLF(self):
     sio = StringIO()
     PlainFileLogObserver(sio)({
         'system': 'some system',
         'message': ('hello', )
     })
     assert 'hello\n' == sio.getvalue()
Ejemplo n.º 4
0
def _format_exception(exc_info):
    """
    Prettyprint an `exc_info` tuple.

    Shamelessly stolen from stdlib's logging module.
    """
    sio = StringIO()
    traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], None, sio)
    s = sio.getvalue()
    sio.close()
    if s[-1:] == "\n":
        s = s[:-1]
    return s
Ejemplo n.º 5
0
 def test_lock(self):
     """
     Creating a logger adds a lock to WRITE_LOCKS.
     """
     sio = StringIO()
     assert sio not in WRITE_LOCKS
     PrintLogger(sio)
     assert sio in WRITE_LOCKS
Ejemplo n.º 6
0
def _format_stack(frame):
    """
    Pretty-print the stack of `frame` like logging would.
    """
    sio = StringIO()
    sio.write('Stack (most recent call last):\n')
    traceback.print_stack(frame, file=sio)
    sinfo = sio.getvalue()
    if sinfo[-1] == '\n':
        sinfo = sinfo[:-1]
    sio.close()
    return sinfo
Ejemplo n.º 7
0
 def test_writesOnlyMessageWithLF(self):
     sio = StringIO()
     PlainFileLogObserver(sio)({"system": "some system", "message": ("hello",)})
     assert "hello\n" == sio.getvalue()
Ejemplo n.º 8
0
 def test_writesOnlyMessageWithLF(self):
     sio = StringIO()
     PlainFileLogObserver(sio)({'system': 'some system',
                                'message': ('hello',)})
     assert 'hello\n' == sio.getvalue()
Ejemplo n.º 9
0
 def test_isLogObserver(self):
     assert ILogObserver.providedBy(PlainFileLogObserver(StringIO()))
Ejemplo n.º 10
0
def sio():
    return StringIO()