Hopefully fix some wayland keyboard stuff.

This commit is contained in:
Storm Dragon
2026-04-08 03:37:50 -04:00
parent 2d9790de88
commit eeb7bd046f
6 changed files with 124 additions and 12 deletions

View File

@@ -0,0 +1,30 @@
import sys
import unittest
from pathlib import Path
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from cthulhu.plugins.ByeCthulhu.plugin import ByeCthulhu
class ByeCthulhuRegressionTests(unittest.TestCase):
def test_activate_only_connects_stop_signal_once(self):
plugin = ByeCthulhu()
signalManager = mock.Mock()
signalManager.connectSignal.return_value = 42
plugin.app = mock.Mock()
plugin.app.getSignalManager.return_value = signalManager
plugin.activate(plugin)
plugin.activate(plugin)
signalManager.connectSignal.assert_called_once_with(
"stop-application-completed",
plugin.process,
"default",
)
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,32 @@
import sys
import unittest
from pathlib import Path
from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from cthulhu import cthulhu_state
from cthulhu.scripts import default
class DefaultScriptShutdownRegressionTests(unittest.TestCase):
def test_remove_key_grabs_clears_tracking_without_touching_dead_device(self):
script = object.__new__(default.Script)
script.grab_ids = [474, 475]
script._modifierGrabIds = [("Insert", 99)]
with (
mock.patch.object(cthulhu_state, "device", None),
mock.patch("cthulhu.scripts.default.cthulhu.removeKeyGrab") as removeKeyGrab,
mock.patch("cthulhu.scripts.default.input_event_manager.get_manager") as getManager,
):
script.removeKeyGrabs()
removeKeyGrab.assert_not_called()
getManager.assert_not_called()
self.assertEqual(script.grab_ids, [])
self.assertEqual(script._modifierGrabIds, [])
if __name__ == "__main__":
unittest.main()

View File

@@ -0,0 +1,44 @@
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()