Exemplo n.º 1
0
 def test_proxies_log(self):
     """
     BoundLogger.exception.log() is proxied to the apropriate method.
     """
     bl = BoundLogger(ReturnLogger(), [return_method_name], {})
     assert "critical" == bl.log(50, "event")
     assert "debug" == bl.log(10, "event")
Exemplo n.º 2
0
    def test_stdlib_methods_support(self, method):
        """
        ReturnLogger implements methods of stdlib loggers.
        """
        v = getattr(ReturnLogger(), method)("hello")

        assert "hello" == v
Exemplo n.º 3
0
 def test_positional_args_proxied(self):
     """
     Positional arguments supplied are proxied as kwarg.
     """
     bl = BoundLogger(ReturnLogger(), [], {})
     args, kwargs = bl.debug('event', 'foo', bar='baz')
     assert 'baz' == kwargs.get('bar')
     assert ('foo', ) == kwargs.get('positional_args')
Exemplo n.º 4
0
def build_bl(logger=None, processors=None, context=None):
    """
    Convenience function to build BoundLoggerBases with sane defaults.
    """
    return BoundLoggerBase(
        logger if logger is not None else ReturnLogger(),
        processors if processors is not None else _CONFIG.default_processors,
        context if context is not None else _CONFIG.default_context_class(),
    )
Exemplo n.º 5
0
 def test_exception_exc_info(self):
     """
     BoundLogger.exception sets exc_info=True.
     """
     bl = BoundLogger(ReturnLogger(), [], {})
     assert ((), {
         "exc_info": True,
         "event": "event"
     }) == bl.exception('event')
Exemplo n.º 6
0
 def test_proxies_anything(self):
     """
     Anything that isn't part of BoundLoggerBase gets proxied to the correct
     wrapped logger methods.
     """
     b = BoundLogger(
         ReturnLogger(),
         _CONFIG.default_processors,
         _CONFIG.default_context_class(),
     )
     assert 'log', 'foo' == b.log('foo')
     assert 'gol', 'bar' == b.gol('bar')
Exemplo n.º 7
0
 def test_caches(self):
     """
     __getattr__() gets called only once per logger method.
     """
     b = BoundLogger(
         ReturnLogger(),
         _CONFIG.default_processors,
         _CONFIG.default_context_class(),
     )
     assert 'msg' not in b.__dict__
     b.msg('foo')
     assert 'msg' in b.__dict__
Exemplo n.º 8
0
    def test_proxies_anything(self):
        """
        Anything that isn't part of BoundLoggerBase gets proxied to the correct
        wrapped logger methods.
        """
        b = BoundLogger(
            ReturnLogger(),
            _CONFIG.default_processors,
            _CONFIG.default_context_class(),
        )

        assert "log", "foo" == b.log("foo")
        assert "gol", "bar" == b.gol("bar")
Exemplo n.º 9
0
    def test_pickle(self):
        """
        Can be pickled and unpickled.

        Works only on Python 3: TypeError: can't pickle instancemethod objects
        """
        b = BoundLogger(
            ReturnLogger(),
            _CONFIG.default_processors,
            _CONFIG.default_context_class(),
        ).bind(x=1)

        assert b.info("hi") == pickle.loads(pickle.dumps(b)).info("hi")
Exemplo n.º 10
0
def logger():
    """
    Returns a simple logger stub with a *msg* method that takes one argument
    which gets returned.
    """
    return ReturnLogger()
Exemplo n.º 11
0
def test_return_logger():
    obj = ['hello']
    assert obj is ReturnLogger().msg(obj)
Exemplo n.º 12
0
def build_bl(logger=None, processors=None, context=None):
    """
    Convenience function to build BoundLogger with sane defaults.
    """
    return BoundLogger(logger or ReturnLogger(), processors, {})
Exemplo n.º 13
0
 def test_exception_maps_to_error(self):
     bl = BoundLogger(ReturnLogger(), [return_method_name], {})
     assert "error" == bl.exception("event")
Exemplo n.º 14
0
 def test_proxies_exception(self):
     """
     BoundLogger.exception is proxied to Logger.error.
     """
     bl = BoundLogger(ReturnLogger(), [return_method_name], {})
     assert "error" == bl.exception("event")
Exemplo n.º 15
0
 def test_proxies_to_correct_method(self, method_name):
     """
     The basic proxied methods are proxied to the correct counterparts.
     """
     bl = BoundLogger(ReturnLogger(), [return_method_name], {})
     assert method_name == getattr(bl, method_name)('event')