feat: terminal backend abstraction — kitty, tmux, and plain backends
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import os
|
||||
from unittest.mock import patch, MagicMock
|
||||
from kitty_workbench.backends import detect_backend, Backend
|
||||
from kitty_workbench.backends.kitty import KittyBackend
|
||||
from kitty_workbench.backends.tmux import TmuxBackend
|
||||
from kitty_workbench.backends.plain import PlainBackend
|
||||
|
||||
|
||||
def test_detect_kitty():
|
||||
with patch.dict(os.environ, {"KITTY_PID": "12345"}, clear=False):
|
||||
backend = detect_backend()
|
||||
assert isinstance(backend, KittyBackend)
|
||||
|
||||
def test_detect_tmux():
|
||||
env = os.environ.copy()
|
||||
env.pop("KITTY_PID", None)
|
||||
env["TMUX"] = "/tmp/tmux-1000/default,12345,0"
|
||||
with patch.dict(os.environ, env, clear=True):
|
||||
backend = detect_backend()
|
||||
assert isinstance(backend, TmuxBackend)
|
||||
|
||||
def test_detect_plain():
|
||||
env = os.environ.copy()
|
||||
env.pop("KITTY_PID", None)
|
||||
env.pop("TMUX", None)
|
||||
with patch.dict(os.environ, env, clear=True):
|
||||
backend = detect_backend()
|
||||
assert isinstance(backend, PlainBackend)
|
||||
|
||||
def test_kitty_image_protocol():
|
||||
b = KittyBackend()
|
||||
assert b.image_protocol() == "kitty"
|
||||
|
||||
def test_tmux_image_protocol():
|
||||
b = TmuxBackend()
|
||||
with patch.dict(os.environ, {"TERM_PROGRAM": "unknown"}, clear=False):
|
||||
assert b.image_protocol() in ("sixel", "none")
|
||||
|
||||
def test_plain_image_protocol():
|
||||
b = PlainBackend()
|
||||
assert b.image_protocol() in ("sixel", "none")
|
||||
|
||||
def test_kitty_launch_pane():
|
||||
b = KittyBackend()
|
||||
with patch("kitty_workbench.backends.kitty.subprocess") as mock_sp:
|
||||
mock_sp.run.return_value = MagicMock(stdout="42", returncode=0)
|
||||
pane_id = b.launch_pane(["kitty-workbench", "tui", "test"], "Test")
|
||||
assert pane_id == 42
|
||||
call_args = mock_sp.run.call_args[0][0]
|
||||
assert "kitty" in call_args[0]
|
||||
assert "--location=vsplit" in call_args
|
||||
|
||||
def test_tmux_launch_pane():
|
||||
b = TmuxBackend()
|
||||
with patch("kitty_workbench.backends.tmux.subprocess") as mock_sp:
|
||||
mock_sp.run.return_value = MagicMock(stdout="%5", returncode=0)
|
||||
pane_id = b.launch_pane(["kitty-workbench", "tui", "test"], "Test")
|
||||
assert pane_id == "%5"
|
||||
call_args = mock_sp.run.call_args[0][0]
|
||||
assert "tmux" in call_args[0]
|
||||
assert "split-window" in call_args
|
||||
Reference in New Issue
Block a user