Avoid shadowing Python typing and retain pending mixed input selections

This commit is contained in:
David Heinemeier Hansson committed 2026-10-09 17:00:14 +02:00
1 parent 639cf3ee5e
commit f28a652347
8 files changed
+41 -14

No files matched your search

+27 -1
View File
@@ -10,6 +10,9 @@ from unittest.mock import patch
import json
import subprocess
# Script-directory imports must not shadow Python's standard typing module.
subprocess.run(["/usr/bin/python", "-c", "import sys; sys.path.insert(0, sys.argv[1]); import typing; from gi.repository import Gio; assert hasattr(typing, 'TYPE_CHECKING')", os.environ["OMARCHY_PATH"] + "/default/input-methods"], check=True)
spec = importlib.util.spec_from_file_location("indicator", os.environ["OMARCHY_PATH"] + "/default/input-methods/indicator.py")
indicator = importlib.util.module_from_spec(spec)
spec.loader.exec_module(indicator)
@@ -55,7 +58,7 @@ def fake_call(bus, method, args=None):
return ()
raise AssertionError(method)
with patch.object(indicator, "snapshot", side_effect=lambda bus: dict(live)), patch.object(indicator, "call", side_effect=fake_call):
with patch.object(indicator, "snapshot", side_effect=lambda bus: dict(live)), patch.object(indicator, "call", side_effect=fake_call), patch.object(indicator.subprocess, "run", return_value=subprocess.CompletedProcess([], 0, stdout='{"keyboards": []}')):
reader = indicator.Indicator(None)
assert reader.refresh()["current"] == "keyboard-us"
reader.select_next()
@@ -127,4 +130,27 @@ with patch.object(indicator.Gio, "bus_get_sync", return_value=None), patch.objec
assert all(command.args[0][-1] == "0" for command in process.call_args_list[1:])
print("ok - layouts and composition engines share one cycle and returning to direct input resets the layout")
keyboards = [{"name": "physical", "layout": "us,dk", "active_layout_index": 0}]
live = {"methods": ["keyboard-us", "pinyin"], "current": "", "name": "", "label": "", "language": ""}
selected.clear()
def fake_process(command, **kwargs):
if command[:3] == ["hyprctl", "-j", "devices"]:
return subprocess.CompletedProcess(command, 0, stdout=json.dumps({"keyboards": keyboards}))
keyboards[0]["active_layout_index"] = int(command[-1])
return subprocess.CompletedProcess(command, 0, stdout="")
with patch.object(indicator, "snapshot", side_effect=lambda bus: dict(live)), patch.object(indicator, "call", side_effect=fake_call), patch.object(indicator.subprocess, "run", side_effect=fake_process):
reader = indicator.Indicator(None)
reader.select_next()
assert keyboards[0]["active_layout_index"] == 1
reader.select_next()
assert reader.pending == "pinyin" and selected == []
assert reader.refresh()["current"] == "pinyin"
live["current"] = "keyboard-us"
reader.refresh()
assert selected == ["pinyin"] and reader.pending == ""
reader.select_next()
assert keyboards[0]["active_layout_index"] == 0
assert selected[-1] == "keyboard-us"
print("ok - mixed-layout bar clicks queue an engine without focus and apply it when a text field gains focus")
PY