46 lines
2.2 KiB
Python
46 lines
2.2 KiB
Python
"""Verify the frozen supervisor, not a source-Python substitute for it."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
|
|
from PyInstaller.archive.readers import CArchiveReader
|
|
|
|
|
|
def verify(executable: Path, data_root: Path) -> dict:
|
|
executable = executable.resolve(strict=True)
|
|
if data_root.exists():
|
|
raise ValueError('Use a fresh verification data directory')
|
|
archive = CArchiveReader(str(executable))
|
|
assert 'win32timezone' in archive.open_embedded_archive('PYZ.pyz').toc, 'Missing win32timezone in frozen archive'
|
|
environment = dict(os.environ, QT_QPA_PLATFORM='offscreen')
|
|
for key in ('PYTHONPATH', 'PYTHONHOME', 'DX_TASK_CENTER_HOME'):
|
|
environment.pop(key, None)
|
|
result = subprocess.run([str(executable), '--smoke-test', '--data-root', str(data_root.resolve())],
|
|
env=environment, cwd=executable.parent, timeout=90,
|
|
creationflags=subprocess.CREATE_NO_WINDOW, capture_output=True)
|
|
assert result.returncode == 0, (result.returncode, result.stderr)
|
|
log = (data_root / 'logs/application.log').read_text(encoding='utf-8')
|
|
assert 'packaged_runtime_smoke_passed' in log
|
|
assert 'application_clean_shutdown exit_code=0' in log
|
|
records = [json.loads(p.read_text(encoding='utf-8'))
|
|
for p in (data_root / 'batch-resources').glob('*/session.json')]
|
|
assert len(records) == 1 and records[0]['state'] == 'released'
|
|
cleanup = records[0]['cleanup']
|
|
assert cleanup['desktop_handle_closed'] and cleanup['desktop_confirmation']['released']
|
|
assert not cleanup['errors']
|
|
return {'passed': True, 'frozen_supervisor': True, 'win32timezone_archived': True,
|
|
'process_creation_time_read': True, 'resources_released': True,
|
|
'executable': str(executable), 'data_root': str(data_root.resolve())}
|
|
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('executable', type=Path)
|
|
parser.add_argument('data_root', type=Path)
|
|
args = parser.parse_args()
|
|
print(json.dumps(verify(args.executable, args.data_root), ensure_ascii=False, indent=2))
|