-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgtk_fixture.py
More file actions
65 lines (49 loc) · 1.7 KB
/
Copy pathgtk_fixture.py
File metadata and controls
65 lines (49 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Select a deterministic GTK fixture for one Midscene Test case."""
import base64
import os
from pathlib import Path
import signal
import sys
import gi
# Ubuntu 22.04 supplies PyGObject for its system Python 3.10. The application
# requires Python 3.11+, but this isolated fixture must use the system Python to
# share GTK bindings, so provide the standard-library module through tomli.
if sys.version_info < (3, 11):
import tomli
sys.modules["tomllib"] = tomli
gi.require_version("Gtk", "4.0")
from gi.repository import GLib, Gtk
from doubao_input.i18n import set_language
from gtk_onboarding_fixture import build_onboarding_fixture
from gtk_runtime_fixture import build_runtime_fixture
RUNTIME_MODES = {"runtime-delivery", "runtime-cancel"}
def fixture_mode():
encoded = os.environ.get("DOUBAO_E2E_MODE_B64", "")
return base64.b64decode(encoded).decode() if encoded else ""
def main():
Gtk.init()
set_language("en")
mode = fixture_mode()
if mode in {"voxtype-live", "voxtype-settings"}:
fake_cli = Path(__file__).parent / "fakes"
os.environ["PATH"] = str(fake_cli) + os.pathsep + os.environ["PATH"]
cleanup = (
build_runtime_fixture() if mode in RUNTIME_MODES
else build_onboarding_fixture(mode)
)
loop = GLib.MainLoop()
def stop(*_args):
loop.quit()
return GLib.SOURCE_REMOVE
signal.signal(signal.SIGTERM, lambda *_args: GLib.idle_add(stop))
signal.signal(signal.SIGINT, lambda *_args: GLib.idle_add(stop))
print(
f"READY: synthetic Doubao Say GTK fixture · {mode or 'default'}",
flush=True,
)
try:
loop.run()
finally:
cleanup()
if __name__ == "__main__":
main()