63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
from tomlkit import dumps, document
|
|
|
|
|
|
def _write_legacy_settings(path: Path) -> None:
|
|
data = document()
|
|
data["general"] = {
|
|
"keyboardLayout": 1,
|
|
"cthulhuModifierKeys": ["Insert", "KP_Insert"],
|
|
"progressBarVerbosity": 1,
|
|
"progressBarUpdateInterval": 10,
|
|
"ocrLanguageCode": "eng",
|
|
"ocrScaleFactor": 3,
|
|
"ocrCopyToClipboard": True,
|
|
}
|
|
data["profiles"] = {
|
|
"default": {
|
|
"profile": ["Default", "default"],
|
|
"keybindings": {},
|
|
"pronunciations": {},
|
|
}
|
|
}
|
|
path.write_text(dumps(data), encoding="utf-8")
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_migrates_legacy_keys_to_schema_tables(tmp_path):
|
|
settings_path = Path(tmp_path, "user-settings.toml")
|
|
_write_legacy_settings(settings_path)
|
|
|
|
from cthulhu import gsettings_registry
|
|
|
|
registry = gsettings_registry.get_registry()
|
|
registry.migrate_all(str(tmp_path))
|
|
|
|
migrated = settings_path.read_text(encoding="utf-8")
|
|
assert "format-version = 2" in migrated
|
|
assert "[profiles.default.keybindings]" in migrated
|
|
assert 'keyboard-layout = "desktop"' in migrated
|
|
assert 'desktop-modifier-keys = ["Insert", "KP_Insert"]' in migrated
|
|
assert "[profiles.default.ocr]" in migrated
|
|
assert 'language-code = "eng"' in migrated
|
|
assert "cthulhuModifierKeys" not in migrated
|
|
assert "progressBarUpdateInterval" not in migrated
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_migration_is_idempotent(tmp_path):
|
|
settings_path = Path(tmp_path, "user-settings.toml")
|
|
_write_legacy_settings(settings_path)
|
|
|
|
from cthulhu import gsettings_registry
|
|
|
|
registry = gsettings_registry.get_registry()
|
|
registry.migrate_all(str(tmp_path))
|
|
first = settings_path.read_text(encoding="utf-8")
|
|
registry.migrate_all(str(tmp_path))
|
|
second = settings_path.read_text(encoding="utf-8")
|
|
|
|
assert second == first
|