-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a helper to log the inputs given to a CLI tool when the verbosity is set to debug. Mostly for user/dev debugging. Also added corresponding docs and unit tests.
- Loading branch information
1 parent
39be84e
commit cd2bfd0
Showing
2 changed files
with
83 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
34 changes: 34 additions & 0 deletions
34
flepimop/gempyor_pkg/tests/shared_cli/test_log_cli_inputs.py
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,34 @@ | ||
import logging | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
import pytest | ||
|
||
from gempyor.logging import _get_logging_level | ||
from gempyor.shared_cli import log_cli_inputs | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"kwargs", | ||
( | ||
{"abc": 123}, | ||
{"abc": 123, "verbosity": 3}, | ||
{"str": "foobar", "int": 123, "float": 3.14, "bool": True}, | ||
{"str": "foobar", "int": 123, "float": 3.14, "bool": True, "verbosity": 3}, | ||
{"file_path": Path("fizzbuzz.log")}, | ||
{"file_path": Path("fizzbuzz.log"), "verbosity": 3}, | ||
), | ||
) | ||
@pytest.mark.parametrize("verbosity", (None, 0, 1, 2, 3, logging.DEBUG, logging.INFO)) | ||
def test_number_of_messages( | ||
caplog: pytest.LogCaptureFixture, kwargs: dict[str, Any], verbosity: int | None | ||
) -> None: | ||
log_cli_inputs(kwargs, verbosity=verbosity) | ||
assert len(caplog.records) == ( | ||
len(kwargs) + 1 | ||
if _get_logging_level( | ||
kwargs.get("verbosity", 0) if verbosity is None else verbosity | ||
) | ||
<= logging.DEBUG | ||
else 0 | ||
) |