85 lines
1.9 KiB
Python
85 lines
1.9 KiB
Python
"""PtyManager 테스트."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Sequence
|
|
|
|
import pytest
|
|
|
|
from lazy_enter.pty_manager import PtyManager
|
|
|
|
|
|
class FakeSpawn:
|
|
def __init__(self, *_args: object, **_kwargs: object) -> None:
|
|
self.before = ""
|
|
self._alive = True
|
|
|
|
def isalive(self) -> bool:
|
|
return self._alive
|
|
|
|
def sendline(self, _text: str) -> None:
|
|
return None
|
|
|
|
def expect(self, *_args: object, **_kwargs: object) -> None:
|
|
return None
|
|
|
|
def close(self, force: bool = False) -> None:
|
|
assert force is True
|
|
self._alive = False
|
|
|
|
|
|
def test_initial_state():
|
|
pty = PtyManager("claude")
|
|
assert not pty.is_alive
|
|
|
|
|
|
def test_start_raises_when_tmux_session_missing(monkeypatch: pytest.MonkeyPatch):
|
|
def fake_run(
|
|
cmd: Sequence[str],
|
|
check: bool,
|
|
capture_output: bool,
|
|
text: bool,
|
|
):
|
|
assert list(cmd) == ["tmux", "has-session", "-t", "claude"]
|
|
assert check is False
|
|
assert capture_output is True
|
|
assert text is True
|
|
|
|
class Result:
|
|
returncode = 1
|
|
|
|
return Result()
|
|
|
|
monkeypatch.setattr("lazy_enter.pty_manager.subprocess.run", fake_run)
|
|
|
|
pty = PtyManager("claude")
|
|
with pytest.raises(RuntimeError):
|
|
pty.start()
|
|
|
|
|
|
def test_start_and_stop_attach(monkeypatch: pytest.MonkeyPatch):
|
|
def fake_run(
|
|
_cmd: Sequence[str],
|
|
check: bool,
|
|
capture_output: bool,
|
|
text: bool,
|
|
):
|
|
assert check is False
|
|
assert capture_output is True
|
|
assert text is True
|
|
|
|
class Result:
|
|
returncode = 0
|
|
|
|
return Result()
|
|
|
|
monkeypatch.setattr("lazy_enter.pty_manager.subprocess.run", fake_run)
|
|
monkeypatch.setattr("lazy_enter.pty_manager.pexpect.spawn", FakeSpawn)
|
|
|
|
pty = PtyManager("claude")
|
|
pty.start()
|
|
assert pty.is_alive
|
|
|
|
pty.stop()
|
|
assert not pty.is_alive
|