Improve strict validation errors with actionable fix hints
This commit is contained in:
parent
ad1af63fac
commit
c8739b6804
3 changed files with 162 additions and 39 deletions
|
|
@ -24,6 +24,9 @@ class ConfigTests(unittest.TestCase):
|
|||
self.assertEqual(cfg.stt.device, "cpu")
|
||||
self.assertEqual(cfg.injection.backend, "clipboard")
|
||||
self.assertFalse(cfg.injection.remove_transcription_from_clipboard)
|
||||
self.assertEqual(cfg.ux.profile, "default")
|
||||
self.assertTrue(cfg.ux.show_notifications)
|
||||
self.assertTrue(cfg.advanced.strict_startup)
|
||||
self.assertEqual(cfg.vocabulary.replacements, [])
|
||||
self.assertEqual(cfg.vocabulary.terms, [])
|
||||
|
||||
|
|
@ -81,7 +84,7 @@ class ConfigTests(unittest.TestCase):
|
|||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "daemon.hotkey is invalid: missing key"):
|
||||
with self.assertRaisesRegex(ValueError, "daemon.hotkey: is invalid: missing key"):
|
||||
load(str(path))
|
||||
|
||||
def test_invalid_hotkey_multiple_keys_raises(self):
|
||||
|
|
@ -91,7 +94,7 @@ class ConfigTests(unittest.TestCase):
|
|||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, "daemon.hotkey is invalid: must include exactly one non-modifier key"
|
||||
ValueError, "daemon.hotkey: is invalid: must include exactly one non-modifier key"
|
||||
):
|
||||
load(str(path))
|
||||
|
||||
|
|
@ -123,7 +126,7 @@ class ConfigTests(unittest.TestCase):
|
|||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "unknown config field: custom_a"):
|
||||
with self.assertRaisesRegex(ValueError, "custom_a: unknown config field"):
|
||||
load(str(path))
|
||||
|
||||
def test_conflicting_replacements_raise(self):
|
||||
|
|
@ -182,7 +185,7 @@ class ConfigTests(unittest.TestCase):
|
|||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "unknown config field: vocabulary.custom_limit"):
|
||||
with self.assertRaisesRegex(ValueError, "vocabulary.custom_limit: unknown config field"):
|
||||
load(str(path))
|
||||
|
||||
def test_unknown_nested_stt_field_raises(self):
|
||||
|
|
@ -191,7 +194,16 @@ class ConfigTests(unittest.TestCase):
|
|||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "unknown config field: stt.language"):
|
||||
with self.assertRaisesRegex(ValueError, "stt.language: unknown config field"):
|
||||
load(str(path))
|
||||
|
||||
def test_invalid_ux_profile_raises(self):
|
||||
payload = {"ux": {"profile": "unknown"}}
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "ux.profile: must be one of"):
|
||||
load(str(path))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue