Exemple #1
0
    def test_configure_all(self, proxy):
        x = stub()
        configure(processors=[x], context_class=dict)
        b = proxy.bind()

        assert [x] == b._processors
        assert dict is b._context.__class__
Exemple #2
0
    def test_configures_logger_factory(self):
        def f():
            pass

        configure(logger_factory=f)

        assert f is _CONFIG.logger_factory
Exemple #3
0
    def test_configure_all(self, proxy):
        x = stub()
        configure(processors=[x], context_class=dict)
        b = proxy.bind()

        assert [x] == b._processors
        assert dict is b._context.__class__
Exemple #4
0
 def test_just_processors(self, proxy):
     x = stub()
     configure(processors=[x])
     b = proxy.bind()
     assert [x] == b._processors
     assert _BUILTIN_DEFAULT_PROCESSORS != b._processors
     assert _BUILTIN_DEFAULT_CONTEXT_CLASS == b._context.__class__
Exemple #5
0
 def test_just_processors(self, proxy):
     x = stub()
     configure(processors=[x])
     b = proxy.bind()
     assert [x] == b._processors
     assert _BUILTIN_DEFAULT_PROCESSORS != b._processors
     assert _BUILTIN_DEFAULT_CONTEXT_CLASS == b._context.__class__
Exemple #6
0
    def test_honors_wrapper_from_config(self, proxy):
        """
        Configured wrapper_class is used if not overridden.
        """
        configure(wrapper_class=Wrapper)

        b = proxy.bind()

        assert isinstance(b, Wrapper)
Exemple #7
0
 def test_rebinds_bind_method(self, proxy):
     """
     To save time, be rebind the bind method once the logger has been
     cached.
     """
     configure(cache_logger_on_first_use=True)
     bind = proxy.bind
     proxy.bind()
     assert bind != proxy.bind
Exemple #8
0
 def test_rebinds_bind_method(self, proxy):
     """
     To save time, be rebind the bind method once the logger has been
     cached.
     """
     configure(cache_logger_on_first_use=True)
     bind = proxy.bind
     proxy.bind()
     assert bind != proxy.bind
Exemple #9
0
 def test_get_logger_passes_positional_arguments_to_logger_factory(self):
     """
     Ensure `get_logger` passes optional positional arguments through to
     the logger factory.
     """
     factory = call_recorder(lambda *args: object())
     configure(logger_factory=factory)
     get_logger("test").bind(x=42)
     assert [call("test")] == factory.calls
Exemple #10
0
 def test_get_logger_passes_positional_arguments_to_logger_factory(self):
     """
     Ensure `get_logger` passes optional positional arguments through to
     the logger factory.
     """
     factory = call_recorder(lambda *args: object())
     configure(logger_factory=factory)
     get_logger("test").bind(x=42)
     assert [call("test")] == factory.calls
Exemple #11
0
 def test_reset(self, proxy):
     x = stub()
     configure(processors=[x], context_class=dict, wrapper_class=Wrapper)
     reset_defaults()
     b = proxy.bind()
     assert [x] != b._processors
     assert _BUILTIN_DEFAULT_PROCESSORS == b._processors
     assert isinstance(b, _BUILTIN_DEFAULT_WRAPPER_CLASS)
     assert _BUILTIN_DEFAULT_CONTEXT_CLASS == b._context.__class__
     assert _BUILTIN_DEFAULT_LOGGER_FACTORY is _CONFIG.logger_factory
Exemple #12
0
 def test_reset(self, proxy):
     x = stub()
     configure(processors=[x], context_class=dict, wrapper_class=Wrapper)
     reset_defaults()
     b = proxy.bind()
     assert [x] != b._processors
     assert _BUILTIN_DEFAULT_PROCESSORS == b._processors
     assert isinstance(b, _BUILTIN_DEFAULT_WRAPPER_CLASS)
     assert _BUILTIN_DEFAULT_CONTEXT_CLASS == b._context.__class__
     assert _BUILTIN_DEFAULT_LOGGER_FACTORY is _CONFIG.logger_factory
Exemple #13
0
    def test_argument_takes_precedence_over_configuration(self, cache):
        """
        Passing cache_logger_on_first_use as an argument overrides config.
        """
        configure(cache_logger_on_first_use=cache)

        proxy = BoundLoggerLazyProxy(None, cache_logger_on_first_use=not cache)
        bind = proxy.bind
        proxy.bind()

        if cache:
            assert bind == proxy.bind
        else:
            assert bind != proxy.bind
Exemple #14
0
    def test_bind_doesnt_cache_logger(self):
        """
        Calling configure() changes BoundLoggerLazyProxys immediately.
        Previous uses of the BoundLoggerLazyProxy don't interfere.
        """
        class F(object):
            "New logger factory with a new attribute"
            def a(self, *args):
                return 5

        proxy = BoundLoggerLazyProxy(None)
        proxy.bind()
        configure(logger_factory=F)
        new_b = proxy.bind()
        assert new_b.a() == 5
Exemple #15
0
    def test_prefers_args_over_config(self):
        p = BoundLoggerLazyProxy(None, processors=[1, 2, 3],
                                 context_class=dict)
        b = p.bind()
        assert isinstance(b._context, dict)
        assert [1, 2, 3] == b._processors

        class Class(object):
            def __init__(self, *args, **kw):
                pass

            def update(self, *args, **kw):
                pass
        configure(processors=[4, 5, 6], context_class=Class)
        b = p.bind()
        assert not isinstance(b._context, Class)
        assert [1, 2, 3] == b._processors
Exemple #16
0
    def test_prefers_args_over_config(self):
        p = BoundLoggerLazyProxy(None, processors=[1, 2, 3], context_class=dict)
        b = p.bind()
        assert isinstance(b._context, dict)
        assert [1, 2, 3] == b._processors

        class Class(object):
            def __init__(self, *args, **kw):
                pass

            def update(self, *args, **kw):
                pass

        configure(processors=[4, 5, 6], context_class=Class)
        b = p.bind()
        assert not isinstance(b._context, Class)
        assert [1, 2, 3] == b._processors
Exemple #17
0
    def test_prefers_args_over_config(self):
        """
        Configuration can be overridden by passing arguments.
        """
        p = BoundLoggerLazyProxy(None,
                                 processors=[1, 2, 3],
                                 context_class=dict)
        b = p.bind()
        assert isinstance(b._context, dict)
        assert [1, 2, 3] == b._processors

        class Class:
            def __init__(self, *args, **kw):
                pass

            def update(self, *args, **kw):
                pass

        configure(processors=[4, 5, 6], context_class=Class)
        b = p.bind()

        assert not isinstance(b._context, Class)
        assert [1, 2, 3] == b._processors
Exemple #18
0
 def test_configure_sets_is_configured(self):
     assert False is _CONFIG.is_configured
     configure()
     assert True is _CONFIG.is_configured
Exemple #19
0
 def test_rest_resets_is_configured(self):
     configure()
     reset_defaults()
     assert False is _CONFIG.is_configured
Exemple #20
0
 def test_argument_takes_precedence_over_configuration2(self):
     configure(cache_logger_on_first_use=False)
     proxy = BoundLoggerLazyProxy(None, cache_logger_on_first_use=True)
     bind = proxy.bind
     proxy.bind()
     assert bind != proxy.bind
Exemple #21
0
 def test_honors_wrapper_from_config(self, proxy):
     configure(wrapper_class=Wrapper)
     b = proxy.bind()
     assert isinstance(b, Wrapper)
Exemple #22
0
 def test_configure_sets_is_configured(self):
     assert False is _CONFIG.is_configured
     configure()
     assert True is _CONFIG.is_configured
Exemple #23
0
 def test_just_context_class(self, proxy):
     configure(context_class=dict)
     b = proxy.bind()
     assert dict is b._context.__class__
     assert _BUILTIN_DEFAULT_PROCESSORS == b._processors
Exemple #24
0
    def test_configures_logger_factory(self):
        def f():
            pass

        configure(logger_factory=f)
        assert f is _CONFIG.logger_factory
Exemple #25
0
 def test_rest_resets_is_configured(self):
     configure()
     reset_defaults()
     assert False is _CONFIG.is_configured
Exemple #26
0
 def test_honors_wrapper_from_config(self, proxy):
     configure(wrapper_class=Wrapper)
     b = proxy.bind()
     assert isinstance(b, Wrapper)
Exemple #27
0
 def test_just_context_class(self, proxy):
     configure(context_class=dict)
     b = proxy.bind()
     assert dict is b._context.__class__
     assert _BUILTIN_DEFAULT_PROCESSORS == b._processors
Exemple #28
0
 def test_argument_takes_precedence_over_configuration2(self):
     configure(cache_logger_on_first_use=False)
     proxy = BoundLoggerLazyProxy(None, cache_logger_on_first_use=True)
     bind = proxy.bind
     proxy.bind()
     assert bind != proxy.bind