Port mouse selection tests to new framework

This commit is contained in:
Kovid Goyal
2021-05-11 11:49:44 +05:30
parent 0260c9d3fb
commit 6dcc09a96f
4 changed files with 69 additions and 24 deletions

View File

@@ -5,15 +5,20 @@
import os
from unittest import TestCase
from kitty.config import Options, defaults, merge_configs
from kitty.fast_data_types import set_options
from kitty.fast_data_types import LineBuf, Cursor, Screen, HistoryBuf
from kitty.config import (
Options, defaults, finalize_keys, finalize_mouse_mappings, merge_configs
)
from kitty.fast_data_types import (
Cursor, HistoryBuf, LineBuf, Screen, set_options
)
from kitty.types import MouseEvent
class Callbacks:
def __init__(self) -> None:
def __init__(self, opts) -> None:
self.clear()
self.opts = opts
def write(self, data) -> None:
self.wtcbuf += data
@@ -54,6 +59,16 @@ class Callbacks:
def on_activity_since_last_focus(self) -> None:
pass
def on_mouse_event(self, event):
ev = MouseEvent(**event)
action = self.opts.mousemap.get(ev)
if action is None:
return False
self.current_mouse_button = ev.button
getattr(self, action.func)(*action.args)
self.current_mouse_button = 0
return True
def filled_line_buf(ynum=5, xnum=5, cursor=Cursor()):
ans = LineBuf(ynum, xnum)
@@ -92,11 +107,14 @@ class BaseTest(TestCase):
if options:
final_options.update(options)
options = Options(merge_configs(defaults._asdict(), final_options))
finalize_keys(options)
finalize_mouse_mappings(options)
set_options(options)
return options
def create_screen(self, cols=5, lines=5, scrollback=5, cell_width=10, cell_height=20, options=None):
self.set_options(options)
c = Callbacks()
opts = self.set_options(options)
c = Callbacks(opts)
s = Screen(c, lines, cols, scrollback, cell_width, cell_height, 0, c)
return s

View File

@@ -6,7 +6,7 @@ from functools import partial
from kitty.fast_data_types import (
GLFW_MOD_ALT, GLFW_MOD_CONTROL, GLFW_MOUSE_BUTTON_LEFT,
GLFW_MOUSE_BUTTON_RIGHT, create_mock_window,
GLFW_MOUSE_BUTTON_RIGHT, create_mock_window, mock_mouse_selection,
send_mock_mouse_event_to_window
)
@@ -40,6 +40,11 @@ class TestMouse(BaseTest):
w = create_mock_window(s)
ev = partial(send_mouse_event, w)
def mouse_selection(code: int) -> None:
mock_mouse_selection(w, s.callbacks.current_mouse_button, code)
s.callbacks.mouse_selection = mouse_selection
def sel():
return ''.join(s.text_for_selection())
@@ -210,7 +215,6 @@ class TestMouse(BaseTest):
self.ae(sel(), '1234')
press(x=1, y=1, button=GLFW_MOUSE_BUTTON_RIGHT)
self.ae(sel(), '123456')
move(x=2, y=1)
self.ae(sel(), '1234567')
move(x=2, y=1, q='1234567')
release(x=3, y=1, button=GLFW_MOUSE_BUTTON_RIGHT)
self.ae(sel(), '12345678')