77 lines
4.0 KiB
Python
77 lines
4.0 KiB
Python
"""Create task data with the real 1.1.1 EXE, then open its copy in the candidate."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import sqlite3
|
|
import subprocess
|
|
import time
|
|
|
|
import win32con
|
|
import win32gui
|
|
|
|
from accept_packaged_ui import wait
|
|
from packaged_window_driver import WindowDriver
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--root', type=Path, required=True)
|
|
args = parser.parse_args()
|
|
root = args.root.resolve(strict=True)
|
|
repository = Path(__file__).resolve().parents[1]
|
|
legacy = repository / 'dist/DxPartReplace-1.1.1/DxPartReplace/DxPartReplace.exe'
|
|
release = json.loads((repository / 'docs/releases/v1.1.1-build.json').read_text(encoding='utf-8'))
|
|
assert hashlib.sha256(legacy.read_bytes()).hexdigest() == release['artifacts']['exe_sha256']
|
|
old_data, new_data = root / 'v111-created-data', root / 'v111-upgraded-copy'
|
|
old_data.mkdir(exist_ok=False)
|
|
projects = root / 'upgrade-fixture-projects'
|
|
for name in ('Legacy-A', 'Legacy-B'):
|
|
path = projects / name / 'board.prj'
|
|
path.parent.mkdir(parents=True)
|
|
path.write_text('KEY FrontEndSnapshot "DxD"\nKEY iCDBDir "database"\n', encoding='utf-8')
|
|
env = dict(os.environ, TEMP=str(repository / 'build/test-temp-remediation'),
|
|
TMP=str(repository / 'build/test-temp-remediation'), LOCALAPPDATA=str(root / 'profile'))
|
|
for key in ('PYTHONPATH', 'PYTHONHOME', 'DX_TASK_CENTER_HOME', 'QT_QPA_PLATFORM'):
|
|
env.pop(key, None)
|
|
process = subprocess.Popen([str(legacy), '--data-root', str(old_data)], env=env,
|
|
creationflags=subprocess.CREATE_NO_WINDOW)
|
|
driver = WindowDriver(process.pid, root / 'upgrade-recording')
|
|
window = driver.main()
|
|
try:
|
|
driver.click(driver.find(automation_id='newTaskButton'))
|
|
dialog = wait(lambda: next((w for w in driver.windows() if w.window_text() == '从目录创建工程任务'), None), timeout=15)
|
|
driver.type_text(driver.find(automation_id='taskDirectory', window=dialog), str(projects))
|
|
driver.click(driver.find(automation_id='readTaskProjects', window=dialog))
|
|
create = driver.find('创建任务', kind='Button', window=dialog)
|
|
wait(create.is_enabled, timeout=20)
|
|
driver.click(create)
|
|
def read_tasks(path):
|
|
with sqlite3.connect(path) as db:
|
|
return db.execute('select task_id,name from tasks order by task_id').fetchall()
|
|
original = wait(lambda: (rows if len(rows := read_tasks(old_data / 'task-center.db')) == 2 else None), timeout=20)
|
|
time.sleep(.5)
|
|
finally:
|
|
win32gui.PostMessage(window.handle, win32con.WM_CLOSE, 0, 0)
|
|
process.wait(timeout=30)
|
|
before = hashlib.sha256((old_data / 'task-center.db').read_bytes()).hexdigest()
|
|
new_data.mkdir()
|
|
with sqlite3.connect((old_data / 'task-center.db').as_uri() + '?mode=ro', uri=True) as src, sqlite3.connect(new_data / 'task-center.db') as dst:
|
|
src.backup(dst)
|
|
env['QT_QPA_PLATFORM'] = 'offscreen'
|
|
candidate = root / 'extracted/DxPartReplace/DxPartReplace.exe'
|
|
result = subprocess.run([str(candidate), '--smoke-test', '--data-root', str(new_data)],
|
|
env=env, capture_output=True, timeout=90)
|
|
report = dict(legacy_version='1.1.1', task_count=len(original), candidate_exit_code=result.returncode,
|
|
task_identities_preserved=read_tasks(new_data / 'task-center.db') == original,
|
|
legacy_source_unchanged=hashlib.sha256((old_data / 'task-center.db').read_bytes()).hexdigest() == before,
|
|
fixture_is_metadata_only=True, cad_launched=False)
|
|
assert result.returncode == 0 and report['task_identities_preserved'] and report['legacy_source_unchanged'], report
|
|
(root / 'v111-upgrade-report.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8')
|
|
print(json.dumps(report, ensure_ascii=False, indent=2))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|