45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
import gi
|
|
|
|
gi.require_version("Gdk", "3.0")
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
|
|
from gi.repository import Gdk
|
|
|
|
from cthulhu import cthulhu_state
|
|
from cthulhu import input_event
|
|
from cthulhu import learn_mode_presenter
|
|
|
|
|
|
class LearnModePresenterRegressionTests(unittest.TestCase):
|
|
def test_escape_keyval_exits_learn_mode_when_event_string_is_control_character(self):
|
|
presenter = learn_mode_presenter.LearnModePresenter(mock.Mock())
|
|
presenter._is_active = True
|
|
|
|
keyboardEvent = input_event.KeyboardEvent(
|
|
True,
|
|
9,
|
|
Gdk.KEY_Escape,
|
|
0,
|
|
"\x1b",
|
|
)
|
|
|
|
activeScript = mock.Mock()
|
|
|
|
with mock.patch.object(cthulhu_state, "activeScript", activeScript):
|
|
result = presenter.handle_event(keyboardEvent)
|
|
|
|
self.assertTrue(result)
|
|
self.assertFalse(presenter.is_active())
|
|
activeScript.speakKeyEvent.assert_called_once_with(keyboardEvent)
|
|
activeScript.presentMessage.assert_called_once()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|