Enforce strict config schema and clean examples
This commit is contained in:
parent
0df8c356af
commit
67fc8d1701
4 changed files with 61 additions and 46 deletions
|
|
@ -113,7 +113,7 @@ class ConfigTests(unittest.TestCase):
|
|||
with self.assertRaisesRegex(ValueError, "injection.remove_transcription_from_clipboard"):
|
||||
load(str(path))
|
||||
|
||||
def test_unknown_top_level_fields_are_ignored(self):
|
||||
def test_unknown_top_level_fields_raise(self):
|
||||
payload = {
|
||||
"custom_a": {"enabled": True},
|
||||
"custom_b": {"nested": "value"},
|
||||
|
|
@ -123,10 +123,8 @@ class ConfigTests(unittest.TestCase):
|
|||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
cfg = load(str(path))
|
||||
|
||||
self.assertEqual(cfg.daemon.hotkey, "Cmd+m")
|
||||
self.assertEqual(cfg.injection.backend, "clipboard")
|
||||
with self.assertRaisesRegex(ValueError, "unknown config field: custom_a"):
|
||||
load(str(path))
|
||||
|
||||
def test_conflicting_replacements_raise(self):
|
||||
payload = {
|
||||
|
|
@ -178,15 +176,23 @@ class ConfigTests(unittest.TestCase):
|
|||
with self.assertRaisesRegex(ValueError, "wildcard"):
|
||||
load(str(path))
|
||||
|
||||
def test_unknown_vocabulary_fields_are_ignored(self):
|
||||
def test_unknown_vocabulary_fields_raise(self):
|
||||
payload = {"vocabulary": {"custom_limit": 100, "custom_extra": 200, "terms": ["Docker"]}}
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
cfg = load(str(path))
|
||||
with self.assertRaisesRegex(ValueError, "unknown config field: vocabulary.custom_limit"):
|
||||
load(str(path))
|
||||
|
||||
self.assertEqual(cfg.vocabulary.terms, ["Docker"])
|
||||
def test_unknown_nested_stt_field_raises(self):
|
||||
payload = {"stt": {"model": "base", "device": "cpu", "language": "en"}}
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "unknown config field: stt.language"):
|
||||
load(str(path))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue