From a6aff817cf5d053e4dbcc7c8f3ddea78c018055a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 6 Jun 2022 15:59:34 +0530 Subject: [PATCH] Prepare for prewarm testing --- kitty_tests/__init__.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/kitty_tests/__init__.py b/kitty_tests/__init__.py index f9308d3cb..25728b31b 100644 --- a/kitty_tests/__init__.py +++ b/kitty_tests/__init__.py @@ -192,12 +192,17 @@ class BaseTest(TestCase): class PTY: - def __init__(self, argv, rows=25, columns=80, scrollback=100, cell_width=10, cell_height=20, cwd=None, env=None): + def __init__(self, argv=None, rows=25, columns=80, scrollback=100, cell_width=10, cell_height=20, cwd=None, env=None): if isinstance(argv, str): argv = shlex.split(argv) - pid, self.master_fd = fork() - self.is_child = pid == CHILD self.write_buf = b'' + if argv is None: + from kitty.child import openpty + self.master_fd, self.slave_fd = openpty() + self.is_child = False + else: + pid, self.master_fd = fork() + self.is_child = pid == CHILD if self.is_child: while read_screen_size().width != columns * cell_width: time.sleep(0.01) @@ -268,13 +273,14 @@ class PTY: if not q(): raise TimeoutError(f'The condition was not met. Screen contents: \n {repr(self.screen_contents())}') - def set_window_size(self, rows=25, columns=80): + def set_window_size(self, rows=25, columns=80, send_signal=True): if hasattr(self, 'screen'): self.screen.resize(rows, columns) - x_pixels = columns * self.cell_width - y_pixels = rows * self.cell_height - s = struct.pack('HHHH', rows, columns, x_pixels, y_pixels) - fcntl.ioctl(self.master_fd, termios.TIOCSWINSZ, s) + if send_signal: + x_pixels = columns * self.cell_width + y_pixels = rows * self.cell_height + s = struct.pack('HHHH', rows, columns, x_pixels, y_pixels) + fcntl.ioctl(self.master_fd, termios.TIOCSWINSZ, s) def screen_contents(self): lines = []