mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 17:17:38 +00:00
set_value looked up node.is_editable_text before attempt() ran. GI bindings from at-spi2-core < 2.53 (e.g. Ubuntu 24.04) do not expose that function, so the AttributeError escaped and every set-value failed. Probe with get_editable_text_iface, which has been bound since 2.9.2 and checks the same interface. Closes #10569 Co-authored-by: bbingz <zzb@gxsmjx.com>
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
import importlib.util
|
|
import sys
|
|
import types
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
|
|
def load_runtime():
|
|
editable_text = types.SimpleNamespace(set_text_contents=lambda editable, value: editable.update(text=value) or True)
|
|
repository = types.ModuleType("gi.repository")
|
|
repository.Atspi = types.SimpleNamespace(EditableText=editable_text)
|
|
gi = types.ModuleType("gi")
|
|
gi.repository = repository
|
|
gi.require_version = lambda *_: None
|
|
path = Path(__file__).with_name("runtime.py")
|
|
with mock.patch.dict(sys.modules, {"gi": gi, "gi.repository": repository}):
|
|
spec = importlib.util.spec_from_file_location("orca_linux_runtime_set_value_test", path)
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
class SetValueTest(unittest.TestCase):
|
|
def test_sets_text_on_bindings_without_is_editable_text(self):
|
|
# Why: at-spi2-core < 2.53 (e.g. Ubuntu 24.04) does not expose Accessible.is_editable_text to GI.
|
|
editable = {"text": ""}
|
|
node = types.SimpleNamespace(get_editable_text_iface=lambda: editable, get_value_iface=lambda: None)
|
|
|
|
self.assertTrue(load_runtime().set_value(node, "hello"))
|
|
self.assertEqual(editable["text"], "hello")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|