mirror of
https://github.com/powerline/powerline.git
synced 2025-07-28 08:14:41 +02:00
Make tmux tests more sane
This commit is contained in:
parent
ca8245b9e8
commit
14982fc693
@ -4,6 +4,7 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from itertools import groupby
|
||||||
|
|
||||||
import pexpect
|
import pexpect
|
||||||
|
|
||||||
@ -65,3 +66,33 @@ class ExpectProcess(threading.Thread):
|
|||||||
def send(self, data):
|
def send(self, data):
|
||||||
with self.child_lock:
|
with self.child_lock:
|
||||||
self.child.send(data)
|
self.child.send(data)
|
||||||
|
|
||||||
|
def get_highlighted_text(self, text, attrs, default_props=()):
|
||||||
|
ret = []
|
||||||
|
new_attrs = attrs.copy()
|
||||||
|
for cell_properties, segment_text in text:
|
||||||
|
segment_text = segment_text.translate({'{': '{{', '}': '}}'})
|
||||||
|
if cell_properties not in new_attrs:
|
||||||
|
new_attrs[cell_properties] = len(new_attrs) + 1
|
||||||
|
props_name = new_attrs[cell_properties]
|
||||||
|
if props_name in default_props:
|
||||||
|
ret.append(segment_text)
|
||||||
|
else:
|
||||||
|
ret.append('{' + str(props_name) + ':' + segment_text + '}')
|
||||||
|
return ''.join(ret), new_attrs
|
||||||
|
|
||||||
|
def get_row(self, row, attrs, default_props=()):
|
||||||
|
with self.lock:
|
||||||
|
return self.get_highlighted_text((
|
||||||
|
(key, ''.join((cell.text for cell in subline)))
|
||||||
|
for key, subline in groupby((
|
||||||
|
self.vterm.vtscreen[row, col] for col in range(self.cols)
|
||||||
|
), lambda cell: cell.cell_properties_key)
|
||||||
|
), attrs, default_props)
|
||||||
|
|
||||||
|
def get_screen(self, attrs, default_props=()):
|
||||||
|
lines = []
|
||||||
|
for row in range(self.rows):
|
||||||
|
line, attrs = self.get_row(row, attrs, default_props)
|
||||||
|
lines.append(line)
|
||||||
|
return '\n'.join(lines), attrs
|
||||||
|
@ -7,7 +7,6 @@ import sys
|
|||||||
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from subprocess import check_call
|
from subprocess import check_call
|
||||||
from itertools import groupby
|
|
||||||
from difflib import ndiff
|
from difflib import ndiff
|
||||||
from glob import glob1
|
from glob import glob1
|
||||||
|
|
||||||
@ -21,6 +20,10 @@ from tests.lib.terminal import ExpectProcess
|
|||||||
VTERM_TEST_DIR = os.path.abspath('tests/vterm_tmux')
|
VTERM_TEST_DIR = os.path.abspath('tests/vterm_tmux')
|
||||||
|
|
||||||
|
|
||||||
|
def convert_expected_result(p, expected_result):
|
||||||
|
return p.get_highlighted_text(expected_result, {})
|
||||||
|
|
||||||
|
|
||||||
def cell_properties_key_to_shell_escape(cell_properties_key):
|
def cell_properties_key_to_shell_escape(cell_properties_key):
|
||||||
fg, bg, bold, underline, italic = cell_properties_key
|
fg, bg, bold, underline, italic = cell_properties_key
|
||||||
return('\x1b[38;2;{0};48;2;{1}{bold}{underline}{italic}m'.format(
|
return('\x1b[38;2;{0};48;2;{1}{bold}{underline}{italic}m'.format(
|
||||||
@ -33,57 +36,32 @@ def cell_properties_key_to_shell_escape(cell_properties_key):
|
|||||||
|
|
||||||
|
|
||||||
def test_expected_result(p, expected_result, cols, rows, print_logs):
|
def test_expected_result(p, expected_result, cols, rows, print_logs):
|
||||||
last_line = []
|
expected_text, attrs = convert_expected_result(p, expected_result)
|
||||||
for col in range(cols):
|
|
||||||
last_line.append(p[rows - 1, col])
|
|
||||||
attempts = 3
|
attempts = 3
|
||||||
result = None
|
result = None
|
||||||
while attempts:
|
while attempts:
|
||||||
result = tuple((
|
actual_text, all_attrs = p.get_row(rows - 1, attrs)
|
||||||
(key, ''.join((i.text for i in subline)))
|
if actual_text == expected_text:
|
||||||
for key, subline in groupby(last_line, lambda i: i.cell_properties_key)
|
|
||||||
))
|
|
||||||
if result == expected_result:
|
|
||||||
return True
|
return True
|
||||||
attempts -= 1
|
attempts -= 1
|
||||||
print('Actual result does not match expected. Attempts left: {0}.'.format(attempts))
|
print('Actual result does not match expected. Attempts left: {0}.'.format(attempts))
|
||||||
sleep(2)
|
sleep(2)
|
||||||
print('Result:')
|
print('Result:')
|
||||||
shesc_result = ''.join((
|
print(actual_text)
|
||||||
'{0}{1}\x1b[m'.format(cell_properties_key_to_shell_escape(key), text)
|
|
||||||
for key, text in result
|
|
||||||
))
|
|
||||||
print(shesc_result)
|
|
||||||
print(result)
|
|
||||||
print('Expected:')
|
print('Expected:')
|
||||||
shesc_expected_result = ''.join((
|
print(expected_text)
|
||||||
'{0}{1}\x1b[m'.format(cell_properties_key_to_shell_escape(key), text)
|
print('Attributes:')
|
||||||
for key, text in expected_result
|
print(all_attrs)
|
||||||
))
|
|
||||||
print(shesc_expected_result)
|
|
||||||
p.send(b'powerline-config tmux setup\n')
|
p.send(b'powerline-config tmux setup\n')
|
||||||
sleep(5)
|
sleep(5)
|
||||||
print('Screen:')
|
print('Screen:')
|
||||||
screen = []
|
screen, screen_attrs = p.get_screen(attrs)
|
||||||
for i in range(rows):
|
print(screen)
|
||||||
screen.append([])
|
print(screen_attrs)
|
||||||
for j in range(cols):
|
|
||||||
screen[-1].append(p[i, j])
|
|
||||||
print('\n'.join(
|
|
||||||
''.join((
|
|
||||||
'{0}{1}\x1b[m'.format(
|
|
||||||
cell_properties_key_to_shell_escape(i.cell_properties_key),
|
|
||||||
i.text
|
|
||||||
) for i in line
|
|
||||||
))
|
|
||||||
for line in screen
|
|
||||||
))
|
|
||||||
a = shesc_result.replace('\x1b', '\\e') + '\n'
|
|
||||||
b = shesc_expected_result.replace('\x1b', '\\e') + '\n'
|
|
||||||
print('_' * 80)
|
print('_' * 80)
|
||||||
print('Diff:')
|
print('Diff:')
|
||||||
print('=' * 80)
|
print('=' * 80)
|
||||||
print(''.join((u(line) for line in ndiff([a], [b]))))
|
print(''.join((u(line) for line in ndiff([actual_text], [expected_text]))))
|
||||||
if print_logs:
|
if print_logs:
|
||||||
for f in glob1(VTERM_TEST_DIR, '*.log'):
|
for f in glob1(VTERM_TEST_DIR, '*.log'):
|
||||||
print('_' * 80)
|
print('_' * 80)
|
||||||
@ -310,10 +288,11 @@ def main(attempts=3):
|
|||||||
if ret is not None:
|
if ret is not None:
|
||||||
return ret
|
return ret
|
||||||
finally:
|
finally:
|
||||||
check_call([tmux_exe, '-S', socket_path, 'kill-server'], env={
|
pass
|
||||||
'PATH': vterm_path,
|
# check_call([tmux_exe, '-S', socket_path, 'kill-server'], env={
|
||||||
'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH', ''),
|
# 'PATH': vterm_path,
|
||||||
}, cwd=VTERM_TEST_DIR)
|
# 'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH', ''),
|
||||||
|
# }, cwd=VTERM_TEST_DIR)
|
||||||
return main(attempts=(attempts - 1))
|
return main(attempts=(attempts - 1))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user