mirror of
https://github.com/19JVJeffery/tiddl-gui.git
synced 2026-10-22 02:42:16 -05:00
Agent-Logs-Url: https://github.com/19JVJeffery/tiddl-gui/sessions/ee218a96-15f4-4124-8eea-902561b3cc4e Co-authored-by: 19JVJeffery <94115228+19JVJeffery@users.noreply.github.com>
78 lines
1.6 KiB
Python
78 lines
1.6 KiB
Python
from pathlib import Path
|
|
from pytest import raises
|
|
|
|
from tiddl.cli.config import load_config_file, Config, CONFIG_FILENAME
|
|
|
|
|
|
def write_config(tmp_path: Path, content: str) -> Path:
|
|
cfg_path = tmp_path / CONFIG_FILENAME
|
|
cfg_path.write_text(content)
|
|
return cfg_path
|
|
|
|
|
|
def test_missing_file_default_config(tmp_path: Path):
|
|
cfg_file = tmp_path / "nonexistent.toml"
|
|
cfg = load_config_file(cfg_file)
|
|
|
|
assert isinstance(cfg, Config)
|
|
|
|
|
|
def test_valid_config_file(tmp_path: Path):
|
|
cfg_file = write_config(
|
|
tmp_path,
|
|
"""
|
|
enable_cache = false
|
|
debug = true
|
|
|
|
[download]
|
|
track_quality = "max"
|
|
threads_count = 8
|
|
""",
|
|
)
|
|
|
|
cfg = load_config_file(cfg_file)
|
|
|
|
assert cfg.enable_cache is False
|
|
assert cfg.debug is True
|
|
assert cfg.download.track_quality == "max"
|
|
assert cfg.download.threads_count == 8
|
|
|
|
|
|
def test_match_existing_path_case_config(tmp_path: Path):
|
|
cfg_file = write_config(
|
|
tmp_path,
|
|
"""
|
|
[download]
|
|
match_existing_path_case = true
|
|
""",
|
|
)
|
|
|
|
cfg = load_config_file(cfg_file)
|
|
|
|
assert cfg.download.match_existing_path_case is True
|
|
|
|
|
|
def test_invalid_type_raises(tmp_path: Path):
|
|
cfg_file = write_config(
|
|
tmp_path,
|
|
"""
|
|
enable_cache = "not_a_bool"
|
|
""",
|
|
)
|
|
|
|
with raises(Exception):
|
|
load_config_file(cfg_file)
|
|
|
|
|
|
def test_invalid_track_quality_raises(tmp_path: Path):
|
|
cfg_file = write_config(
|
|
tmp_path,
|
|
"""
|
|
[download]
|
|
track_quality = "ultra"
|
|
""",
|
|
)
|
|
|
|
with raises(Exception):
|
|
load_config_file(cfg_file)
|