Validate hotkeys and support Super alias
This commit is contained in:
parent
2cbc1a98b9
commit
3bc473262d
6 changed files with 138 additions and 34 deletions
|
|
@ -9,26 +9,28 @@ SRC = ROOT / "src"
|
|||
if str(SRC) not in sys.path:
|
||||
sys.path.insert(0, str(SRC))
|
||||
|
||||
from config import load
|
||||
from config import load, redacted_dict
|
||||
|
||||
|
||||
class ConfigTests(unittest.TestCase):
|
||||
def test_defaults_when_file_missing(self):
|
||||
missing = Path(tempfile.gettempdir()) / "lel_missing_config_test.json"
|
||||
if missing.exists():
|
||||
missing.unlink()
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
missing = Path(td) / "nested" / "config.json"
|
||||
cfg = load(str(missing))
|
||||
|
||||
cfg = load(str(missing))
|
||||
self.assertEqual(cfg.daemon.hotkey, "Cmd+m")
|
||||
self.assertEqual(cfg.recording.input, "")
|
||||
self.assertEqual(cfg.stt.model, "base")
|
||||
self.assertEqual(cfg.stt.device, "cpu")
|
||||
self.assertEqual(cfg.injection.backend, "clipboard")
|
||||
self.assertFalse(cfg.injection.remove_transcription_from_clipboard)
|
||||
self.assertEqual(cfg.vocabulary.replacements, [])
|
||||
self.assertEqual(cfg.vocabulary.terms, [])
|
||||
self.assertTrue(cfg.domain_inference.enabled)
|
||||
|
||||
self.assertEqual(cfg.daemon.hotkey, "Cmd+m")
|
||||
self.assertEqual(cfg.recording.input, "")
|
||||
self.assertEqual(cfg.stt.model, "base")
|
||||
self.assertEqual(cfg.stt.device, "cpu")
|
||||
self.assertEqual(cfg.injection.backend, "clipboard")
|
||||
self.assertFalse(cfg.injection.remove_transcription_from_clipboard)
|
||||
self.assertEqual(cfg.vocabulary.replacements, [])
|
||||
self.assertEqual(cfg.vocabulary.terms, [])
|
||||
self.assertTrue(cfg.domain_inference.enabled)
|
||||
self.assertTrue(missing.exists())
|
||||
written = json.loads(missing.read_text(encoding="utf-8"))
|
||||
self.assertEqual(written, redacted_dict(cfg))
|
||||
|
||||
def test_loads_nested_config(self):
|
||||
payload = {
|
||||
|
|
@ -66,6 +68,36 @@ class ConfigTests(unittest.TestCase):
|
|||
self.assertEqual(cfg.vocabulary.terms, ["Systemd", "Kubernetes"])
|
||||
self.assertTrue(cfg.domain_inference.enabled)
|
||||
|
||||
def test_super_modifier_hotkey_is_valid(self):
|
||||
payload = {"daemon": {"hotkey": "Super+m"}}
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
cfg = load(str(path))
|
||||
|
||||
self.assertEqual(cfg.daemon.hotkey, "Super+m")
|
||||
|
||||
def test_invalid_hotkey_missing_key_raises(self):
|
||||
payload = {"daemon": {"hotkey": "Ctrl+Alt"}}
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "daemon.hotkey is invalid: missing key"):
|
||||
load(str(path))
|
||||
|
||||
def test_invalid_hotkey_multiple_keys_raises(self):
|
||||
payload = {"daemon": {"hotkey": "Ctrl+a+b"}}
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, "daemon.hotkey is invalid: must include exactly one non-modifier key"
|
||||
):
|
||||
load(str(path))
|
||||
|
||||
def test_loads_legacy_keys(self):
|
||||
payload = {
|
||||
"hotkey": "Alt+m",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue