Fix zsh integration test on CI

Also, add various other robustness improvements to the test
This commit is contained in:
Kovid Goyal
2022-02-21 19:29:35 +05:30
parent a43f610555
commit 261057396c
3 changed files with 14 additions and 6 deletions

View File

@@ -8,7 +8,7 @@ import tempfile
import unittest
from contextlib import contextmanager
from kitty.constants import terminfo_dir
from kitty.constants import kitty_base_dir, terminfo_dir
from kitty.fast_data_types import CURSOR_BEAM
from kitty.shell_integration import setup_zsh_env
@@ -22,13 +22,17 @@ def safe_env_for_running_shell(home_dir, rc='', shell='zsh'):
'TERM': 'xterm-kitty',
'TERMINFO': terminfo_dir,
'KITTY_SHELL_INTEGRATION': 'enabled',
'KITTY_INSTALLATION_DIR': kitty_base_dir,
}
for x in ('USER', 'LANG'):
if os.environ.get(x):
ans[x] = os.environ[x]
if shell == 'zsh':
ans['ZLE_RPROMPT_INDENT'] = '0'
with open(os.path.join(home_dir, '.zshenv'), 'w') as f:
print('unset GLOBAL_RCS', file=f)
with open(os.path.join(home_dir, '.zshrc'), 'w') as f:
print(rc, file=f)
print(rc + '\n', file=f)
setup_zsh_env(ans)
return ans
@@ -36,10 +40,10 @@ def safe_env_for_running_shell(home_dir, rc='', shell='zsh'):
class ShellIntegration(BaseTest):
@contextmanager
def run_shell(self, shell='zsh', rc=''):
def run_shell(self, shell='zsh', rc='', cmd='{shell} -il'):
home_dir = os.path.realpath(tempfile.mkdtemp())
try:
pty = self.create_pty(f'{shell} -il', cwd=home_dir, env=safe_env_for_running_shell(home_dir, rc))
pty = self.create_pty(cmd.format(**locals()), cwd=home_dir, env=safe_env_for_running_shell(home_dir, rc))
i = 10
while i > 0 and not pty.screen_contents().strip():
pty.process_input_from_child()
@@ -66,4 +70,5 @@ RPS1="{rps1}"
self.ae(pty.callbacks.titlebuf, '~')
pty.send_cmd_to_child('mkdir test && ls -a')
pty.wait_till(lambda: pty.screen_contents().count(ps1) == 2)
self.ae(pty.last_cmd_output(), str(pty.screen.line(1)))
q = '\n'.join(str(pty.screen.line(i)) for i in range(1, pty.screen.cursor.y))
self.ae(pty.last_cmd_output(), q)