1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#!/usr/bin/env python3
"""Check startup/runtime SDL Font name:size requests through an isolated 9P session."""
import argparse
from pathlib import Path
from fs import execute, new_pane, session
from ui_review import capture, panes, require, wait_for
def run(args):
root = args.output.resolve()
root.mkdir(parents=True, mode=0o700, exist_ok=True)
root.chmod(0o700)
config = root / 'config/pardes'
config.mkdir(parents=True, exist_ok=True)
(config / 'init').write_text(f'Shell /bin/sh\nTheme orchard\nFont {args.font}:18\nTaglineSize 80\n')
name = 'font-size'
launch = ['-c', 'stty cols 150 rows 48; exec "$@"', name,
str(args.binary.resolve()), '--9p=' + name]
inherited = {'PARDES_TEST': '1', 'PARDES_TEST_CAPTURE_DIR': str(root),
'PARDES_TEST_COLS': '150', 'PARDES_TEST_ROWS': '48',
'SDL_VIDEODRIVER': 'x11'}
with session('/bin/sh', root, name, socket_name=name, tty=True,
launch=launch, inherited=inherited) as (client, _):
control = new_pane(client, b'')
def report(size):
execute(client, control, 'Config')
def ready():
for serial, tag in panes(client).items():
if '/+Config ' in tag:
body = client.read(f'/pane/{serial}/body').decode()
if f'Font effective size {size:.2f} pixels' in body:
return body
return None
return require(wait_for(ready), f'Font did not become {size} pixels')
initial = report(18)
require('Font requested size 18.00' in initial, 'startup size suffix ignored')
require(args.font in initial, 'requested font missing')
execute(client, control, f'Font {args.font}:20.5')
require('Font requested size 20.50' in report(20.5), 'fractional size ignored')
execute(client, control, f'Font {args.font}')
report(20.5) # no suffix preserves current size
execute(client, control, f'Font {args.font}:900')
report(20.5) # invalid request cannot partially change the font
execute(client, control, 'Font DefinitelyMissingPardesFont:12')
report(20.5)
execute(client, control, f'Font {args.font}:18')
final = report(18)
(root / 'font-report.txt').write_text(final)
capture(client, root, 'font-size-18', True)
print('Font startup, fractional size, omitted size and invalid requests passed')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('binary', type=Path)
parser.add_argument('output', type=Path)
parser.add_argument('--font', default='MartianMono-NrRg')
run(parser.parse_args())
|