feat: platform-dependent config path (APPDATA on Windows)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from unittest.mock import patch
|
||||||
|
import os
|
||||||
import tomllib
|
import tomllib
|
||||||
|
|
||||||
from whisper_local.config import Config, load_config
|
from whisper_local.config import Config, load_config
|
||||||
@@ -57,3 +59,20 @@ class TestLoadConfig:
|
|||||||
config_file.write_text("")
|
config_file.write_text("")
|
||||||
config = load_config(config_file)
|
config = load_config(config_file)
|
||||||
assert config.hotkey == "KEY_F12"
|
assert config.hotkey == "KEY_F12"
|
||||||
|
|
||||||
|
|
||||||
|
class TestConfigPath:
|
||||||
|
@patch.dict(os.environ, {"APPDATA": "C:\\Users\\test\\AppData\\Roaming"})
|
||||||
|
@patch("whisper_local.config.sys")
|
||||||
|
def test_windows_config_path(self, mock_sys):
|
||||||
|
mock_sys.platform = "win32"
|
||||||
|
from whisper_local.config import _default_config_path
|
||||||
|
result = _default_config_path()
|
||||||
|
assert result == Path("C:\\Users\\test\\AppData\\Roaming") / "whisper-local" / "config.toml"
|
||||||
|
|
||||||
|
@patch("whisper_local.config.sys")
|
||||||
|
def test_linux_config_path(self, mock_sys):
|
||||||
|
mock_sys.platform = "linux"
|
||||||
|
from whisper_local.config import _default_config_path
|
||||||
|
result = _default_config_path()
|
||||||
|
assert result == Path.home() / ".config" / "whisper-local" / "config.toml"
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
"""Konfiguration aus TOML-Datei mit sinnvollen Defaults."""
|
"""Konfiguration aus TOML-Datei mit sinnvollen Defaults."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import tomllib
|
import tomllib
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_CONFIG_PATH = Path.home() / ".config" / "whisper-local" / "config.toml"
|
def _default_config_path() -> Path:
|
||||||
|
if sys.platform == "win32":
|
||||||
|
return Path(os.environ.get("APPDATA", "")) / "whisper-local" / "config.toml"
|
||||||
|
return Path.home() / ".config" / "whisper-local" / "config.toml"
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_CONFIG_PATH = _default_config_path()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
Reference in New Issue
Block a user