refactor: rework configuration models, add CLI, tests and VSCode settings
- Replace hardcoded CONFIG_PATH with appdirs AppDirs (use app.user_config_dir) and update SETTINGS_PATH - Rework dataclasses: add Library, QbitTorrent; convert Komga.libraries to List[Library]; use Path for media_path; add getLibraryByName and proper __post_init__ conversions - Extend KomGrabber to support downloader/downloader_settings (aria2/qbit), normalize Path handling and expanduser usage - Add type fixes, utility methods (getattr/_setattr) and API __post_init__ to convert nested dicts to dataclass instances - Add package CLI entrypoints (__main__.py, src package main) and simple runner (main.py) - Add tests for package __init__ CLI and config behavior (tests/*) and a small test script (test.py) - Add .vscode/settings.json for pytest integration - Tidy pyproject.toml: format dependencies, add dev/test dependency groups and fix trailing newline in bumpversion section
This commit is contained in:
40
tests/test___init__.py
Normal file
40
tests/test___init__.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
from src.komconfig.__init__ import main
|
||||
import sys
|
||||
|
||||
|
||||
def test_valid_key():
|
||||
mock_config = MagicMock()
|
||||
mock_config.dict.return_value = {"valid_key": "value"}
|
||||
|
||||
with patch("src.komconfig.__init__.KomConfig", return_value=mock_config):
|
||||
with patch("sys.argv", ["__init__.py", "valid_key"]):
|
||||
main()
|
||||
|
||||
|
||||
def test_key_not_found():
|
||||
mock_config = MagicMock()
|
||||
mock_config.dict.return_value = {"another_key": "value"}
|
||||
|
||||
with patch("src.komconfig.__init__.KomConfig", return_value=mock_config):
|
||||
with patch("sys.argv", ["__init__.py", "missing_key"]):
|
||||
main()
|
||||
|
||||
|
||||
def test_non_dict_config():
|
||||
mock_config = MagicMock()
|
||||
mock_config.dict.return_value = None
|
||||
|
||||
with patch("src.komconfig.__init__.KomConfig", return_value=mock_config):
|
||||
with patch("sys.argv", ["__init__.py", "any_key"]):
|
||||
main()
|
||||
|
||||
|
||||
def test_exception_handling():
|
||||
mock_config = MagicMock()
|
||||
mock_config.dict.side_effect = Exception("Test Exception")
|
||||
|
||||
with patch("src.komconfig.__init__.KomConfig", return_value=mock_config):
|
||||
with patch("sys.argv", ["__init__.py", "any_key"]):
|
||||
main()
|
||||
18
tests/test_config.py
Normal file
18
tests/test_config.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from komconfig import KomConfig
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def komconfig():
|
||||
return KomConfig()
|
||||
|
||||
|
||||
def test_komconfig(komconfig):
|
||||
assert komconfig is not None
|
||||
|
||||
|
||||
def test_general(komconfig):
|
||||
assert KomConfig().general.log_file == "/var/log/komgrabber.log"
|
||||
assert KomConfig().general.log_level == "INFO"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user