Scope Esc cancel listener to active recording
This commit is contained in:
parent
e5d709a393
commit
64c8c26bce
6 changed files with 105 additions and 7 deletions
|
|
@ -18,6 +18,17 @@ class FakeDesktop:
|
|||
def __init__(self):
|
||||
self.inject_calls = []
|
||||
self.quit_calls = 0
|
||||
self.cancel_listener_start_calls = 0
|
||||
self.cancel_listener_stop_calls = 0
|
||||
self.cancel_listener_callback = None
|
||||
|
||||
def start_cancel_listener(self, callback) -> None:
|
||||
self.cancel_listener_start_calls += 1
|
||||
self.cancel_listener_callback = callback
|
||||
|
||||
def stop_cancel_listener(self) -> None:
|
||||
self.cancel_listener_stop_calls += 1
|
||||
self.cancel_listener_callback = None
|
||||
|
||||
def inject_text(
|
||||
self,
|
||||
|
|
@ -239,6 +250,28 @@ class DaemonTests(unittest.TestCase):
|
|||
any("DEBUG:root:state: idle -> recording" in line for line in logs.output)
|
||||
)
|
||||
|
||||
@patch("aman.stop_audio_recording", return_value=FakeAudio(8))
|
||||
@patch("aman.start_audio_recording", return_value=(object(), object()))
|
||||
def test_cancel_listener_armed_only_while_recording(self, _start_mock, _stop_mock):
|
||||
desktop = FakeDesktop()
|
||||
daemon = self._build_daemon(desktop, FakeModel(), verbose=False)
|
||||
daemon._start_stop_worker = (
|
||||
lambda stream, record, trigger, process_audio: daemon._stop_and_process(
|
||||
stream, record, trigger, process_audio
|
||||
)
|
||||
)
|
||||
|
||||
self.assertIsNone(desktop.cancel_listener_callback)
|
||||
daemon.toggle()
|
||||
self.assertEqual(desktop.cancel_listener_start_calls, 1)
|
||||
self.assertEqual(desktop.cancel_listener_stop_calls, 0)
|
||||
self.assertIsNotNone(desktop.cancel_listener_callback)
|
||||
|
||||
daemon.toggle()
|
||||
self.assertEqual(desktop.cancel_listener_start_calls, 1)
|
||||
self.assertEqual(desktop.cancel_listener_stop_calls, 1)
|
||||
self.assertIsNone(desktop.cancel_listener_callback)
|
||||
|
||||
|
||||
class LockTests(unittest.TestCase):
|
||||
def test_lock_rejects_second_instance(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue