Settings tests
This commit is contained in:
parent
028949f216
commit
0302511f5f
@ -248,13 +248,9 @@ If no options are given, %(prog)s will run in windowed mode.""",
|
||||
file_options = self.parse_file(config_paths.user_config_dir / "settings.json")
|
||||
cli_options = self.parse_args(args, namespace=self.get_namespace_for_args(file_options))
|
||||
|
||||
# for group, group_options in cli_options.items():
|
||||
# if group in cli_options:
|
||||
# file_options[group].update(group_options)
|
||||
# else:
|
||||
# file_options[group] = group_options
|
||||
# Just in case something weird happens with the commandline options
|
||||
file_options["runtime"]["config"] = config_paths
|
||||
if "runtime" in cli_options:
|
||||
# Just in case something weird happens with the commandline options
|
||||
cli_options["runtime"]["config"] = config_paths
|
||||
|
||||
# Normalize a final time for fun
|
||||
return self.normalize_options(cli_options, file=True, cmdline=True)
|
||||
|
@ -163,12 +163,11 @@ def seed_all_publishers(monkeypatch):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def settings(tmp_path):
|
||||
def settings(settings_manager, tmp_path):
|
||||
|
||||
manager = ctsettings.Manager()
|
||||
ctsettings.register_commandline(manager)
|
||||
ctsettings.register_settings(manager)
|
||||
defaults = manager.defaults()
|
||||
ctsettings.register_commandline(settings_manager)
|
||||
ctsettings.register_settings(settings_manager)
|
||||
defaults = settings_manager.defaults()
|
||||
defaults["runtime"]["config"] = ctsettings.ComicTaggerPaths(tmp_path / "config")
|
||||
defaults["runtime"]["config"].user_data_dir.mkdir(parents=True, exist_ok=True)
|
||||
defaults["runtime"]["config"].user_config_dir.mkdir(parents=True, exist_ok=True)
|
||||
@ -178,6 +177,12 @@ def settings(tmp_path):
|
||||
yield defaults
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def settings_manager():
|
||||
manager = ctsettings.Manager()
|
||||
yield manager
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def comic_cache(settings, mock_version) -> Generator[comictalker.comiccacher.ComicCacher, Any, None]:
|
||||
yield comictalker.comiccacher.ComicCacher(settings["runtime"]["config"].user_cache_dir, mock_version[0])
|
||||
|
59
tests/settings_test.py
Normal file
59
tests/settings_test.py
Normal file
@ -0,0 +1,59 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from comictaggerlib import settings as ctsettings
|
||||
|
||||
|
||||
def test_settings_manager():
|
||||
manager = ctsettings.Manager()
|
||||
defaults = manager.defaults()
|
||||
assert manager is not None and defaults is not None
|
||||
|
||||
|
||||
settings_cases = [
|
||||
(
|
||||
{
|
||||
"test": (
|
||||
{
|
||||
"args": ["--test"],
|
||||
"kwargs": dict(
|
||||
action=None,
|
||||
nargs=None,
|
||||
const=None,
|
||||
default=None,
|
||||
type=None,
|
||||
choices=None,
|
||||
required=None,
|
||||
help=None,
|
||||
metavar=None,
|
||||
dest=None,
|
||||
cmdline=True,
|
||||
file=True,
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
dict({"test": {"test": {"names": ["--test"], "dest": "test", "default": None}}}),
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("settings, expected", settings_cases)
|
||||
def test_add_setting(settings, expected, settings_manager, tmp_path):
|
||||
for group, settings in settings.items():
|
||||
|
||||
def add_settings(parser):
|
||||
for setting in settings:
|
||||
settings_manager.add_setting(*setting["args"], **setting["kwargs"])
|
||||
|
||||
settings_manager.add_group(group, add_settings)
|
||||
|
||||
parsed_settings = settings_manager.parse_options(ctsettings.ComicTaggerPaths(tmp_path), args=[])
|
||||
|
||||
# print(parsed_settings)
|
||||
# print(expected)
|
||||
for group, settings in expected.items():
|
||||
for setting_name, setting in settings.items():
|
||||
assert parsed_settings[group][setting_name] == setting["default"]
|
||||
assert False
|
Loading…
Reference in New Issue
Block a user