Files
tai/taicpp/tests/mplex_tmux_oracle.py
T

43 lines
1.5 KiB
Python

"""Oracle for `mplex_flow_test --tmux`: the same steps through tai.py's TmuxPlexerController
against a real tmux (isolated TMUX_TMPDIR), printing the same lines.
usage: python3 -I mplex_tmux_oracle.py <repo root>
"""
import importlib.util
import json
import os
import subprocess
import sys
import tempfile
import time
root = sys.argv[1]
spec = importlib.util.spec_from_file_location("tai_mod", root + "/tai.py")
tai = importlib.util.module_from_spec(spec)
sys.modules["tai_mod"] = tai
spec.loader.exec_module(tai)
os.environ["TMUX_TMPDIR"] = tempfile.mkdtemp(prefix="mplex-tmux-")
os.environ.pop("TMUX", None)
subprocess.run("tmux new-session -d -s t -x 80 -y 24 'cat' >/dev/null 2>&1", shell=True)
pane = subprocess.run("tmux list-panes -t t -F '#{pane_id}'", shell=True, capture_output=True, text=True).stdout.strip()
c = tai.TmuxPlexerController(pane)
print("send", json.dumps(c.send_keys("hello world", True)))
time.sleep(0.3)
print("read", json.dumps(c.read_pane(5)))
print("status", json.dumps(c.status()))
try:
tai.TmuxPlexerController("%99").read_pane(3)
except tai.PlexerError as exc:
print("error", exc)
try:
c.ask({"kind": "weird"}, 5)
except tai.PlexerError as exc:
print("ask", exc)
for kind in ("choice", "text"):
screen = {"kind": kind, "title": "T", "options": ["a", "b"], "text": "question"}
try:
print(kind, json.dumps(c.ask(screen, 5)))
except tai.PlexerError as exc:
print(kind, "error", exc)
subprocess.run("tmux kill-server >/dev/null 2>&1", shell=True)