Add clipboard cleanup option for clipboard backend
This commit is contained in:
parent
1423e44008
commit
ccf968a410
9 changed files with 114 additions and 11 deletions
|
|
@ -25,6 +25,7 @@ class ConfigTests(unittest.TestCase):
|
|||
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.assertTrue(cfg.ai.enabled)
|
||||
self.assertEqual(cfg.vocabulary.replacements, [])
|
||||
self.assertEqual(cfg.vocabulary.terms, [])
|
||||
|
|
@ -38,7 +39,10 @@ class ConfigTests(unittest.TestCase):
|
|||
"daemon": {"hotkey": "Ctrl+space"},
|
||||
"recording": {"input": 3},
|
||||
"stt": {"model": "small", "device": "cuda"},
|
||||
"injection": {"backend": "injection"},
|
||||
"injection": {
|
||||
"backend": "injection",
|
||||
"remove_transcription_from_clipboard": True,
|
||||
},
|
||||
"ai": {"enabled": False},
|
||||
"vocabulary": {
|
||||
"replacements": [
|
||||
|
|
@ -62,6 +66,7 @@ class ConfigTests(unittest.TestCase):
|
|||
self.assertEqual(cfg.stt.model, "small")
|
||||
self.assertEqual(cfg.stt.device, "cuda")
|
||||
self.assertEqual(cfg.injection.backend, "injection")
|
||||
self.assertTrue(cfg.injection.remove_transcription_from_clipboard)
|
||||
self.assertFalse(cfg.ai.enabled)
|
||||
self.assertEqual(cfg.vocabulary.max_rules, 100)
|
||||
self.assertEqual(cfg.vocabulary.max_terms, 200)
|
||||
|
|
@ -92,6 +97,7 @@ class ConfigTests(unittest.TestCase):
|
|||
self.assertEqual(cfg.stt.model, "tiny")
|
||||
self.assertEqual(cfg.stt.device, "cpu")
|
||||
self.assertEqual(cfg.injection.backend, "clipboard")
|
||||
self.assertFalse(cfg.injection.remove_transcription_from_clipboard)
|
||||
self.assertFalse(cfg.ai.enabled)
|
||||
self.assertEqual(cfg.vocabulary.replacements, [])
|
||||
|
||||
|
|
@ -104,6 +110,15 @@ class ConfigTests(unittest.TestCase):
|
|||
with self.assertRaisesRegex(ValueError, "injection.backend"):
|
||||
load(str(path))
|
||||
|
||||
def test_invalid_clipboard_remove_option_raises(self):
|
||||
payload = {"injection": {"remove_transcription_from_clipboard": "yes"}}
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
path = Path(td) / "config.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "injection.remove_transcription_from_clipboard"):
|
||||
load(str(path))
|
||||
|
||||
def test_removed_logging_section_raises(self):
|
||||
payload = {"logging": {"log_transcript": True}}
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
|
|
|
|||
|
|
@ -19,8 +19,14 @@ class FakeDesktop:
|
|||
self.inject_calls = []
|
||||
self.quit_calls = 0
|
||||
|
||||
def inject_text(self, text: str, backend: str) -> None:
|
||||
self.inject_calls.append((text, backend))
|
||||
def inject_text(
|
||||
self,
|
||||
text: str,
|
||||
backend: str,
|
||||
*,
|
||||
remove_transcription_from_clipboard: bool = False,
|
||||
) -> None:
|
||||
self.inject_calls.append((text, backend, remove_transcription_from_clipboard))
|
||||
|
||||
def request_quit(self) -> None:
|
||||
self.quit_calls += 1
|
||||
|
|
@ -101,7 +107,7 @@ class DaemonTests(unittest.TestCase):
|
|||
daemon.toggle()
|
||||
|
||||
self.assertEqual(daemon.get_state(), leld.State.IDLE)
|
||||
self.assertEqual(desktop.inject_calls, [("hello world", "clipboard")])
|
||||
self.assertEqual(desktop.inject_calls, [("hello world", "clipboard", False)])
|
||||
|
||||
@patch("leld.stop_audio_recording", return_value=FakeAudio(8))
|
||||
@patch("leld.start_audio_recording", return_value=(object(), object()))
|
||||
|
|
@ -143,7 +149,7 @@ class DaemonTests(unittest.TestCase):
|
|||
daemon.toggle()
|
||||
daemon.toggle()
|
||||
|
||||
self.assertEqual(desktop.inject_calls, [("good morning Marta", "clipboard")])
|
||||
self.assertEqual(desktop.inject_calls, [("good morning Marta", "clipboard", False)])
|
||||
|
||||
def test_transcribe_skips_hints_when_model_does_not_support_them(self):
|
||||
desktop = FakeDesktop()
|
||||
|
|
@ -189,6 +195,28 @@ class DaemonTests(unittest.TestCase):
|
|||
daemon_verbose = leld.Daemon(cfg, desktop, verbose=True)
|
||||
self.assertTrue(daemon_verbose.log_transcript)
|
||||
|
||||
@patch("leld.stop_audio_recording", return_value=FakeAudio(8))
|
||||
@patch("leld.start_audio_recording", return_value=(object(), object()))
|
||||
def test_passes_clipboard_remove_option_to_desktop(self, _start_mock, _stop_mock):
|
||||
desktop = FakeDesktop()
|
||||
model = FakeModel(text="hello world")
|
||||
cfg = self._config()
|
||||
cfg.injection.remove_transcription_from_clipboard = True
|
||||
|
||||
with patch("leld._build_whisper_model", return_value=model):
|
||||
daemon = leld.Daemon(cfg, desktop, verbose=False)
|
||||
daemon.ai_processor = FakeAIProcessor()
|
||||
daemon._start_stop_worker = (
|
||||
lambda stream, record, trigger, process_audio: daemon._stop_and_process(
|
||||
stream, record, trigger, process_audio
|
||||
)
|
||||
)
|
||||
|
||||
daemon.toggle()
|
||||
daemon.toggle()
|
||||
|
||||
self.assertEqual(desktop.inject_calls, [("hello world", "clipboard", True)])
|
||||
|
||||
def test_state_changes_are_debug_level(self):
|
||||
desktop = FakeDesktop()
|
||||
with patch("leld._build_whisper_model", return_value=FakeModel()):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue