Files
shd.build/tools/game-data-capture/tests/integration/test_clipboard_watch.py
T

43 lines
1.2 KiB
Python

from __future__ import annotations
import subprocess
import sys
import time
from pathlib import Path
import pytest
from game_data_capture.ingest.clipboard import ClipboardIntake, WatchConfig
def test_shutdown_reaps_real_child_process_group(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
child: subprocess.Popen[bytes] | None = None
real_popen = subprocess.Popen
def fake_popen(args: list[str], **kwargs: object) -> subprocess.Popen[bytes]:
nonlocal child
assert args[0] == "wl-paste" and kwargs["shell"] is False
child = real_popen(
[sys.executable, "-c", "import time; time.sleep(30)"],
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
start_new_session=True,
)
return child
monkeypatch.setattr(subprocess, "Popen", fake_popen)
intake = ClipboardIntake(
WatchConfig((tmp_path / "spool").resolve(), 100, 1, "v1", 1, 0.01, 0.2)
)
intake.arm()
assert child is not None and child.poll() is None
intake.shutdown()
for _ in range(20):
if child.poll() is not None:
break
time.sleep(0.01)
assert child.poll() is not None