File: test_cookiecutter_logging.py

package info (click to toggle)
python-briefcase 0.3.22-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,300 kB
  • sloc: python: 59,405; makefile: 57
file content (44 lines) | stat: -rw-r--r-- 1,207 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
44
import logging

import pytest

from briefcase.console import LogLevel, RichLoggingHandler

cookiecutter_logger = logging.getLogger("cookiecutter")


@pytest.fixture
def base_command(base_command):
    # Mock actual templating commands as no-ops
    base_command.update_cookiecutter_cache = lambda *a, **kw: None
    base_command.tools.cookiecutter = lambda *a, **kw: None
    return base_command


@pytest.mark.parametrize(
    "logging_level, handler_expected",
    [
        (LogLevel.DEEP_DEBUG, True),
        (LogLevel.DEBUG, False),
        (LogLevel.VERBOSE, False),
        (LogLevel.INFO, False),
    ],
)
def test_git_stdlib_logging(base_command, logging_level, handler_expected):
    """A logging handler is configured for GitPython when DEEP_DEBUG is enabled."""
    base_command.console.verbosity = logging_level

    base_command.generate_template(
        template="",
        branch="",
        output_path="",
        extra_context={},
    )

    assert handler_expected is any(
        isinstance(h, RichLoggingHandler)
        for h in logging.getLogger("cookiecutter").handlers
    )

    # reset handlers since they are persistent
    logging.getLogger("cookiecutter").handlers.clear()