Skip to content

Commit

Permalink
test: log_level= option test for load_config
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Oct 5, 2024
1 parent cd8fced commit 6fd22ef
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ These features will be included in the next release:

Added
-----
- Unit test for ``log_level`` option for `darkgraylib.config.load_config`.

Fixed
-----
Expand Down
38 changes: 37 additions & 1 deletion src/darkgraylib/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from textwrap import dedent

import pytest
from toml import TomlDecodeError

from darkgraylib.config import (
ConfigurationError,
Expand Down Expand Up @@ -351,7 +352,7 @@ class OriginTrackingConfig(BaseConfig):
confpath=None,
expect={"config": "no_pyp"},
)
def test_load_config( # pylint: disable=too-many-arguments
def test_load_config_path( # pylint: disable=too-many-arguments
tmp_path, monkeypatch, srcs, cwd, confpath, expect
):
"""``load_config()`` finds and loads configuration based on source file paths"""
Expand Down Expand Up @@ -513,3 +514,38 @@ def test_dump_config(config, expect):
result = dump_config(config, "darkgraylib")

assert result == expect


@pytest.mark.parametrize(
["config", "expect"],
[
("", {}),
("log_level = 0", {"log_level": "NOTSET"}),
("log_level = 'NOTSET'", {"log_level": "NOTSET"}),
("log_level = 1", {"log_level": "Level 1"}),
("log_level = 2", {"log_level": "Level 2"}),
("log_level = 10", {"log_level": "DEBUG"}),
("log_level = 'DEBUG'", {"log_level": "DEBUG"}),
("log_level = DEBUG", TomlDecodeError),
("log_level = 20", {"log_level": "INFO"}),
("log_level = 'INFO'", {"log_level": "INFO"}),
("log_level = 30", {"log_level": "WARNING"}),
("log_level = 'WARNING'", {"log_level": "WARNING"}),
("log_level = 40", {"log_level": "ERROR"}),
("log_level = 'ERROR'", {"log_level": "ERROR"}),
("log_level = 50", {"log_level": "CRITICAL"}),
("log_level = 'CRITICAL'", {"log_level": "CRITICAL"}),
],
)
def test_load_config(tmp_path, monkeypatch, config, expect):
"""`load_config()` can load all supported options"""
(tmp_path / "pyproject.toml").write_text(f"[tool.darkgraylib]\n{config}\n")
monkeypatch.chdir(tmp_path)
with raises_if_exception(expect):

result = load_config(None, ["."], "darkgraylib", BaseConfig)

assert result == expect
assert {k: type(v) for k, v in result.items()} == {
k: type(v) for k, v in expect.items()
}

0 comments on commit 6fd22ef

Please sign in to comment.