106 lines
2.7 KiB
Python
106 lines
2.7 KiB
Python
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def _environment() -> dict[str, str]:
|
|
environment = os.environ.copy()
|
|
environment["QT_QPA_PLATFORM"] = "offscreen"
|
|
return environment
|
|
|
|
|
|
def test_module_launcher_dispatches_probe_without_starting_qt(tmp_path: Path) -> None:
|
|
output = tmp_path / "兼容性 结果.json"
|
|
|
|
result = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-m",
|
|
"dx_productivity",
|
|
"probe",
|
|
"--output",
|
|
str(output),
|
|
"--route",
|
|
"named",
|
|
"--payload-json",
|
|
'{"portable":true}',
|
|
],
|
|
capture_output=True,
|
|
text=True,
|
|
encoding="utf-8",
|
|
env=_environment(),
|
|
timeout=15,
|
|
check=False,
|
|
)
|
|
|
|
assert result.returncode == 0, result.stderr
|
|
assert json.loads(output.read_text(encoding="utf-8")) == {
|
|
"format_version": 1,
|
|
"route": "named",
|
|
"portable": True,
|
|
}
|
|
|
|
|
|
def test_module_launcher_runs_ui_smoke_test_and_exits(
|
|
fixture_path: Path,
|
|
) -> None:
|
|
result = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
"-m",
|
|
"dx_productivity",
|
|
"ui",
|
|
"--request",
|
|
str(fixture_path / "request-basic.json"),
|
|
"--smoke-test-ms",
|
|
"50",
|
|
],
|
|
capture_output=True,
|
|
text=True,
|
|
encoding="utf-8",
|
|
env=_environment(),
|
|
timeout=15,
|
|
check=False,
|
|
)
|
|
|
|
assert result.returncode == 0, result.stderr
|
|
|
|
|
|
def test_module_launcher_dispatches_update_without_starting_qt(tmp_path: Path) -> None:
|
|
import sys
|
|
import zipfile
|
|
|
|
current = tmp_path / "portable"
|
|
current.mkdir()
|
|
(current / "DxDesignerTools.exe").write_bytes(b"old")
|
|
staged = tmp_path / "update.zip"
|
|
with zipfile.ZipFile(staged, "w") as archive:
|
|
archive.writestr("DxDesignerTools.exe", b"new")
|
|
plan = tmp_path / "install-plan.json"
|
|
plan.write_text(
|
|
json.dumps(
|
|
{
|
|
"current_root": str(current),
|
|
"staged_zip": str(staged),
|
|
"backup_root": str(tmp_path / "backups"),
|
|
"restart_command": [sys.executable, "-c", "raise SystemExit(0)"],
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "dx_productivity", "update", "--plan", str(plan)],
|
|
capture_output=True,
|
|
text=True,
|
|
encoding="utf-8",
|
|
env=_environment(),
|
|
timeout=15,
|
|
check=False,
|
|
)
|
|
|
|
assert result.returncode == 0, result.stderr
|
|
assert (current / "DxDesignerTools.exe").read_bytes() == b"new"
|