#!/usr/bin/env python3 """Capture installed-application smoke evidence on a dedicated display.""" import argparse import hashlib import json import os from pathlib import Path import subprocess import tempfile root = Path(__file__).resolve().parents[1] parser = argparse.ArgumentParser() parser.add_argument('--binary', type=Path, default=root / 'build/install/bin/docview') parser.add_argument('--output', type=Path, default=root / 'tests/results/smoke') args = parser.parse_args() args.output.mkdir(parents=True, exist_ok=True) # A failed launch must not leave a previous run's successful aggregate behind. for name in ('results.json', 'package-smoke.json'): (args.output / name).unlink(missing_ok=True) with args.binary.open('rb') as binary: binary_hash = hashlib.file_digest(binary, 'sha256').hexdigest() cases = [ ('pdf-dark-100', 'pdf/extended/japanese-layout.pdf', 'pdf', 'dark', 1), ('pdf-fonts-dark-100', 'pdf/fonts/unembedded-japanese.pdf', 'pdf', 'dark', 1), ('pdf-light-200', 'pdf/extended/japanese-layout.pdf', 'pdf', 'light', 2), ('html-dark-100', 'web/html/index.html', 'html', 'dark', 1), ('zip-dark-100', 'web/html-book.zip', 'htmlzip', 'dark', 1), ('epub-dark-100', 'web/reflow-rtl.epub', 'epub', 'dark', 1), ] results = [] with tempfile.TemporaryDirectory(prefix='docview-smoke-') as temporary: for name, fixture, kind, theme, scale in cases: private = Path(temporary) / name private.mkdir() config = private / 'config.toml' config.write_text(f'schema_version=1\n[ui]\ntheme="{theme}"\npages_visible=true\n[privacy]\nremember_position=false\nrecent_documents=0\n', encoding='utf-8') destination = (args.output / name).resolve() env = os.environ.copy() env.update({key: str(private / leaf) for key, leaf in [('XDG_CONFIG_HOME','config'), ('XDG_STATE_HOME','state'), ('XDG_CACHE_HOME','cache')]}) env['QT_SCALE_FACTOR'] = str(scale) subprocess.run([str(args.binary.resolve()), '--config', str(config), '--smoke-output', str(destination), str(root / 'tests/fixtures' / fixture)], env=env, check=True, timeout=30) state = (destination / 'state.txt').read_text(encoding='utf-8').splitlines() runtime = json.loads((destination / 'runtime.json').read_text(encoding='utf-8')) if (runtime['windowWidth'] > runtime['screenWidth'] or runtime['windowHeight'] > runtime['screenHeight']): raise RuntimeError(f'{name}: initial window exceeds the selected logical screen: {runtime}') if state[:2] != ['Ready', kind] or not (destination / 'screen.png').is_file(): raise RuntimeError(f'{name}: unexpected state {state}') results.append({'case': name, 'state': state[0], 'format': kind, 'scale': scale, 'theme': theme, 'image': name + '/screen.png', 'binarySha256': binary_hash, 'runtime': runtime}) (args.output / 'results.json').write_text(json.dumps(results, ensure_ascii=False, indent=2) + '\n', encoding='utf-8') print(json.dumps(results, ensure_ascii=False))