File: test_config.py

package info (click to toggle)
python-colorlog 6.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 232 kB
  • sloc: python: 721; makefile: 5
file content (43 lines) | stat: -rw-r--r-- 1,259 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Test using colorlog with logging.config"""

import logging
import logging.config
import os.path


def path(filename):
    """Return an absolute path to a file in the current directory."""
    return os.path.join(os.path.dirname(os.path.realpath(__file__)), filename)


def test_build_from_file(test_logger):
    logging.config.fileConfig(path("test_config.ini"))
    test_logger(logging.getLogger(), lambda line: ":test_config.ini" in line)


def test_build_from_dictionary(test_logger):
    logging.config.dictConfig(
        {
            "version": 1,
            "formatters": {
                "colored": {
                    "()": "colorlog.ColoredFormatter",
                    "format": "%(log_color)s%(levelname)s:%(name)s:%(message)s:dict",
                }
            },
            "handlers": {
                "stream": {
                    "class": "logging.StreamHandler",
                    "formatter": "colored",
                    "level": "DEBUG",
                },
            },
            "loggers": {
                "": {
                    "handlers": ["stream"],
                    "level": "DEBUG",
                },
            },
        }
    )
    test_logger(logging.getLogger(), lambda line: ":dict" in line)