Fix test functions for setup_for_testing's new call syntax

This commit is contained in:
Benoit de Chezelles 2019-10-18 04:47:04 +02:00
parent 26b7b1ec63
commit be505ce6e0

View File

@ -554,57 +554,57 @@ def test_char(ch, sz=48):
# kitty +runpy "from kitty.fonts.box_drawing import test_char; import sys; test_char('XXX')" # kitty +runpy "from kitty.fonts.box_drawing import test_char; import sys; test_char('XXX')"
from .render import display_bitmap, setup_for_testing from .render import display_bitmap, setup_for_testing
from kitty.fast_data_types import concat_cells, set_send_sprite_to_gpu from kitty.fast_data_types import concat_cells, set_send_sprite_to_gpu
width, height = setup_for_testing('monospace', sz)[1:] with setup_for_testing('monospace', sz) as (_, width, height):
buf = bytearray(width * height) buf = bytearray(width * height)
try: try:
render_box_char(ch, buf, width, height) render_box_char(ch, buf, width, height)
def join_cells(*cells): def join_cells(*cells):
cells = tuple(bytes(x) for x in cells) cells = tuple(bytes(x) for x in cells)
return concat_cells(width, height, False, cells) return concat_cells(width, height, False, cells)
rgb_data = join_cells(buf) rgb_data = join_cells(buf)
display_bitmap(rgb_data, width, height) display_bitmap(rgb_data, width, height)
print() print()
finally: finally:
set_send_sprite_to_gpu(None) set_send_sprite_to_gpu(None)
def test_drawing(sz=48, family='monospace'): def test_drawing(sz=48, family='monospace'):
from .render import display_bitmap, setup_for_testing from .render import display_bitmap, setup_for_testing
from kitty.fast_data_types import concat_cells, set_send_sprite_to_gpu from kitty.fast_data_types import concat_cells, set_send_sprite_to_gpu
width, height = setup_for_testing(family, sz)[1:] with setup_for_testing(family, sz) as (_, width, height):
space = bytearray(width * height) space = bytearray(width * height)
def join_cells(cells): def join_cells(cells):
cells = tuple(bytes(x) for x in cells) cells = tuple(bytes(x) for x in cells)
return concat_cells(width, height, False, cells) return concat_cells(width, height, False, cells)
def render_chr(ch): def render_chr(ch):
if ch in box_chars: if ch in box_chars:
cell = bytearray(len(space)) cell = bytearray(len(space))
render_box_char(ch, cell, width, height) render_box_char(ch, cell, width, height)
return cell return cell
return space return space
pos = 0x2500 pos = 0x2500
rows = [] rows = []
space_row = join_cells(repeat(space, 32)) space_row = join_cells(repeat(space, 32))
try: try:
for r in range(10): for r in range(10):
row = [] row = []
for i in range(16): for i in range(16):
row.append(render_chr(chr(pos))) row.append(render_chr(chr(pos)))
row.append(space) row.append(space)
pos += 1 pos += 1
rows.append(join_cells(row)) rows.append(join_cells(row))
rows.append(space_row) rows.append(space_row)
rgb_data = b''.join(rows) rgb_data = b''.join(rows)
width *= 32 width *= 32
height *= len(rows) height *= len(rows)
assert len(rgb_data) == width * height * 4, '{} != {}'.format(len(rgb_data), width * height * 4) assert len(rgb_data) == width * height * 4, '{} != {}'.format(len(rgb_data), width * height * 4)
display_bitmap(rgb_data, width, height) display_bitmap(rgb_data, width, height)
finally: finally:
set_send_sprite_to_gpu(None) set_send_sprite_to_gpu(None)