-
-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable debug cookiecutter logging for deep debug
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
import pytest | ||
|
||
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( | ||
"verbosity, log_level", | ||
[ | ||
(0, logging.INFO), | ||
(1, logging.INFO), | ||
(2, logging.DEBUG), | ||
], | ||
) | ||
def test_cookiecutter_logging_config(base_command, verbosity, log_level): | ||
"""The loggers for cookiecutter are configured as expected.""" | ||
base_command.logger.verbosity = verbosity | ||
|
||
base_command.generate_template( | ||
template="", branch="", output_path="", extra_context={} | ||
) | ||
# call multiple times to ensure only 1 handler ever exists | ||
base_command.generate_template( | ||
template="", branch="", output_path="", extra_context={} | ||
) | ||
|
||
assert len(cookiecutter_logger.handlers) == 1 | ||
assert cookiecutter_logger.handlers[0].level == log_level |