MCPcopy Create free account
hub / github.com/hynek/structlog / test_add_extra_e2e

Method test_add_extra_e2e

tests/test_stdlib.py:689–724  ·  view source on GitHub ↗

Values passed in the `extra` parameter of the `logging` module's log methods pass through to log output.

(
        self,
        extra_dict: dict[str, Any],
        allow: Collection[str] | None,
        misses: set[str] | None,
    )

Source from the content-addressed store, hash-verified

687 ],
688 )
689 def test_add_extra_e2e(
690 self,
691 extra_dict: dict[str, Any],
692 allow: Collection[str] | None,
693 misses: set[str] | None,
694 ):
695 """
696 Values passed in the `extra` parameter of the `logging` module's log
697 methods pass through to log output.
698 """
699 logger = logging.Logger(sys._getframe().f_code.co_name)
700 string_io = StringIO()
701 handler = logging.StreamHandler(string_io)
702 formatter = ProcessorFormatter(
703 foreign_pre_chain=[ExtraAdder(allow)],
704 processors=[JSONRenderer()],
705 )
706 handler.setFormatter(formatter)
707 handler.setLevel(0)
708 logger.addHandler(handler)
709 logger.setLevel(0)
710 logging.warning("allow = %s", allow) # noqa: LOG015
711
712 event_dict = {"event": "Some text"}
713 expected = self._copy_allowed(event_dict, extra_dict, allow)
714
715 logger.info("Some %s", "text", extra=extra_dict)
716 actual = {
717 key: value
718 for key, value in json.loads(string_io.getvalue()).items()
719 if not key.startswith("_")
720 }
721
722 assert expected == actual
723 if misses:
724 assert misses.isdisjoint(expected.keys())
725
726 @classmethod
727 def _copy_allowed(

Callers

nothing calls this directly

Calls 8

_copy_allowedMethod · 0.95
ProcessorFormatterClass · 0.90
ExtraAdderClass · 0.90
JSONRendererClass · 0.90
setLevelMethod · 0.80
addHandlerMethod · 0.80
warningMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected