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:
2025-11-01 22:17:50 +01:00
parent 674e9f9fd5
commit bb3b922325
9 changed files with 255 additions and 39 deletions

40
tests/test___init__.py Normal file
View 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()