kitty/kitty_tests/remote_control.py

54 lines
1.9 KiB
Python

#!/usr/bin/env python
# License: GPLv3 Copyright: 2026 Kovid Goyal <kovid at kovidgoyal.net>
from unittest.mock import patch
from kitty.rc.base import PayloadGetter, all_command_names, command_for_name
from .base import BaseTest
class Window:
def __init__(self, id: int, os_window_id: int):
self.id = id
self.os_window_id = os_window_id
class Boss:
def __init__(self, windows: list[Window]):
self.active_window = windows[0]
self.all_windows = windows
def match_windows(self, expr: str, self_window: Window | None = None):
if expr == 'all':
yield from self.all_windows
return
for window in self.all_windows:
if str(window.id) == expr:
yield window
class TestRemoteControl(BaseTest):
def test_set_os_window_title_command_is_registered(self):
self.assertIn('set_os_window_title', all_command_names())
self.ae(command_for_name('set-os-window-title').name, 'set-os-window-title')
def test_set_os_window_title_dedupes_os_windows(self):
windows = [Window(1, 11), Window(2, 11), Window(3, 22)]
boss = Boss(windows)
cmd = command_for_name('set-os-window-title')
with patch('kitty.rc.set_os_window_title.set_os_window_title_impl') as setter:
cmd.response_from_kitty(boss, windows[0], PayloadGetter(cmd, {'match': 'all', 'self': True, 'title': 'repo'}))
self.ae({call.args for call in setter.call_args_list}, {(11, 'repo'), (22, 'repo')})
def test_set_os_window_title_without_title_resets_override(self):
windows = [Window(1, 11)]
boss = Boss(windows)
cmd = command_for_name('set-os-window-title')
with patch('kitty.rc.set_os_window_title.set_os_window_title_impl') as setter:
cmd.response_from_kitty(boss, windows[0], PayloadGetter(cmd, {'self': True}))
setter.assert_called_once_with(11, '')