- 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
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
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()
|