Files
ai-chess/legacy/tests/test_tmux.py
T

55 lines
1.5 KiB
Python

import asyncio
import os
import tempfile
import pytest
from ai_chess.tmux import TmuxSession
@pytest.mark.asyncio
async def test_create_kill_session():
s = TmuxSession("aichess-test-create")
try:
await s.kill() # idempotent
await s.create_window_with_cmd("cat > /tmp/aichess-test.out")
assert await s.exists()
finally:
await s.kill()
assert not await s.exists()
@pytest.mark.asyncio
async def test_paste_multiline():
out = tempfile.NamedTemporaryFile(mode="w", suffix=".out", delete=False)
out.close()
s = TmuxSession("aichess-test-paste")
try:
await s.kill()
await s.create_window_with_cmd(f"cat > {out.name}")
await asyncio.sleep(0.2)
await s.paste_text(pane=0, text='многострочный\nтест с "кавычками" и $vars\nthird')
await s.send_keys(pane=0, keys=["C-d"])
await asyncio.sleep(0.2)
with open(out.name) as f:
data = f.read()
assert "многострочный" in data
assert 'тест с "кавычками" и $vars' in data
assert "third" in data
finally:
await s.kill()
os.unlink(out.name)
@pytest.mark.asyncio
async def test_capture_pane():
s = TmuxSession("aichess-test-capture")
try:
await s.kill()
await s.create_window_with_cmd("printf 'hello world\\n'; sleep 5")
await asyncio.sleep(0.4)
text = await s.capture_pane(pane=0)
assert "hello world" in text
finally:
await s.kill()