#!/usr/bin/env python3 """Drive one memoria binary against the fake provider with a long response and dump the emulated final screen to stdout. Usage: run_long.py """ import os import pty import select import sys import time binary = sys.argv[1] pid, fd = pty.fork() if pid == 0: os.environ["MEMORIA_PROVIDER"] = "fake" os.execv(binary, [binary]) out = b"" def pump(t): global out end = time.time() + t while time.time() < end: r, _, _ = select.select([fd], [], [], 0.1) if r: try: out += os.read(fd, 65536) except OSError: return time.sleep(0.05) pump(1.0) os.write(fd, b"foobar\r") pump(4.0) # let the long response stream in and several repaint frames pass os.write(fd, b"\x03") pump(0.5) try: os.close(fd) except OSError: pass sys.stdout.write(out.decode("utf-8", "replace"))