179 lines
5.6 KiB
Python
179 lines
5.6 KiB
Python
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
|
|
import pytest
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
|
RELEASE_ROOT = Path(os.environ.get("DXTOOLS_RELEASE_ROOT", str(REPO_ROOT / "release" / "DxDesigner效率工具")))
|
|
|
|
|
|
def _sanitized_environment() -> dict[str, str]:
|
|
environment = os.environ.copy()
|
|
windows = Path(os.environ.get("WINDIR", "C:/Windows"))
|
|
environment["PATH"] = os.pathsep.join(
|
|
(str(windows / "System32"), str(windows))
|
|
)
|
|
environment["QT_QPA_PLATFORM"] = "offscreen"
|
|
environment.pop("PYTHONHOME", None)
|
|
environment.pop("PYTHONPATH", None)
|
|
return environment
|
|
|
|
|
|
def test_release_contains_portable_runtime_and_root_scripts() -> None:
|
|
expected = (
|
|
"DxDesignerTools.exe",
|
|
"_runtime/python312.dll",
|
|
"_runtime/PySide6/plugins/platforms/qwindows.dll",
|
|
"_runtime/vbs/BridgeCommon.vbs",
|
|
"_runtime/vbs/Snapshot.vbs",
|
|
"_runtime/vbs/Transaction.vbs",
|
|
"_runtime/vbs/Mailbox.vbs",
|
|
"_runtime/vbs/BomExport.vbs",
|
|
"MenuAdd.vbs",
|
|
"DesignBridge.vbs",
|
|
"CompatibilityProbe.vbs",
|
|
"PdfSaveListener.vbs",
|
|
"LoadMenu.vbs",
|
|
"templates/BOM模板.xls",
|
|
"expedition/ExpeditionBridge.vbs",
|
|
"docs/DxDesigner_7.9.5_自动位号工具使用说明.docx",
|
|
)
|
|
|
|
for relative_path in expected:
|
|
assert (RELEASE_ROOT / relative_path).is_file(), relative_path
|
|
assert any(
|
|
path.suffix in {".ttf", ".otf"}
|
|
for path in (RELEASE_ROOT / "_runtime").rglob("*")
|
|
)
|
|
|
|
|
|
def test_release_does_not_bundle_foreign_icu_from_build_path() -> None:
|
|
runtime = RELEASE_ROOT / "_runtime"
|
|
|
|
assert not (runtime / "icuuc.dll").exists()
|
|
assert not list(runtime.glob("icudt*.dll"))
|
|
|
|
|
|
def test_packaged_probe_runs_without_python_on_path(tmp_path: Path) -> None:
|
|
output = tmp_path / "兼容性 结果.json"
|
|
result = subprocess.run(
|
|
[
|
|
str(RELEASE_ROOT / "DxDesignerTools.exe"),
|
|
"probe",
|
|
"--output",
|
|
str(output),
|
|
"--route",
|
|
"named",
|
|
"--payload-json",
|
|
'{"portable":true}',
|
|
],
|
|
env=_sanitized_environment(),
|
|
timeout=30,
|
|
check=False,
|
|
)
|
|
|
|
assert result.returncode == 0
|
|
assert json.loads(output.read_text(encoding="utf-8"))["portable"] is True
|
|
|
|
|
|
@pytest.mark.parametrize("feature", (
|
|
"refdes", "property-change", "property-visibility", "inspection", "network",
|
|
"bom", "history", "settings", "pdf-export",
|
|
))
|
|
def test_packaged_ui_loads_request_without_python_on_path(feature: str) -> None:
|
|
result = subprocess.run(
|
|
[
|
|
str(RELEASE_ROOT / "DxDesignerTools.exe"),
|
|
"ui",
|
|
"--request",
|
|
str(REPO_ROOT / "tests" / "fixtures" / "request-basic.json"),
|
|
"--feature",
|
|
feature,
|
|
"--smoke-test-ms",
|
|
"250",
|
|
],
|
|
env=_sanitized_environment(),
|
|
timeout=30,
|
|
check=False,
|
|
)
|
|
|
|
assert result.returncode == 0
|
|
|
|
|
|
def test_packaged_application_runs_from_chinese_path_with_spaces(
|
|
tmp_path: Path,
|
|
) -> None:
|
|
copied_root = tmp_path / "中文 工具"
|
|
shutil.copytree(RELEASE_ROOT, copied_root)
|
|
output = tmp_path / "兼容性 结果.json"
|
|
|
|
probe = subprocess.run(
|
|
[
|
|
str(copied_root / "DxDesignerTools.exe"),
|
|
"probe",
|
|
"--output",
|
|
str(output),
|
|
"--route",
|
|
"named",
|
|
"--payload-json",
|
|
'{"portable":true}',
|
|
],
|
|
env=_sanitized_environment(),
|
|
timeout=30,
|
|
check=False,
|
|
)
|
|
ui = subprocess.run(
|
|
[
|
|
str(copied_root / "DxDesignerTools.exe"),
|
|
"ui",
|
|
"--request",
|
|
str(REPO_ROOT / "tests" / "fixtures" / "request-basic.json"),
|
|
"--smoke-test-ms",
|
|
"250",
|
|
],
|
|
env=_sanitized_environment(),
|
|
timeout=30,
|
|
check=False,
|
|
)
|
|
|
|
assert probe.returncode == 0
|
|
assert json.loads(output.read_text(encoding="utf-8"))["portable"] is True
|
|
assert ui.returncode == 0
|
|
|
|
|
|
def test_release_archive_matches_sha256_manifest() -> None:
|
|
archive = Path(os.environ.get("DXTOOLS_RELEASE_ARCHIVE", str(REPO_ROOT / "release" / "DxDesigner效率工具_Win11_x64.zip")))
|
|
manifest = Path(os.environ.get("DXTOOLS_RELEASE_MANIFEST", str(REPO_ROOT / "release" / "SHA256SUMS.txt")))
|
|
|
|
digest = hashlib.sha256(archive.read_bytes()).hexdigest()
|
|
|
|
assert manifest.read_text(encoding="utf-8").split()[0] == digest
|
|
|
|
|
|
def test_packaged_listener_disabled_exits_without_python_on_path(tmp_path: Path) -> None:
|
|
config = tmp_path / "pdf-export-settings.json"
|
|
config.write_text('{"auto_export":false}', encoding="utf-8")
|
|
result = subprocess.run(
|
|
[str(RELEASE_ROOT / "DxDesignerTools.exe"), "pdf-export-listen", "--settings", str(config)],
|
|
env=_sanitized_environment(), timeout=30, check=False,
|
|
)
|
|
assert result.returncode == 0
|
|
|
|
|
|
def test_packaged_pcb_compute_without_python_on_path(tmp_path: Path) -> None:
|
|
request = tmp_path / "request.txt"
|
|
output = tmp_path / "plan.txt"
|
|
request.write_text("T|0|1|1|1|C1|0|C1\nT|1|2|1|1|NOTE|0|C1\nC|C1|10|20|0.5|0.3\n", encoding="ascii")
|
|
result = subprocess.run(
|
|
[str(RELEASE_ROOT / "DxDesignerTools.exe"), "compute", "assembly-refdes", "--request", str(request), "--output", str(output)],
|
|
env=_sanitized_environment(), timeout=30, check=False,
|
|
)
|
|
assert result.returncode == 0
|
|
assert "MOVE|0|10.0000|20.0000|0.00|0.3000|Arial\n" in output.read_text(encoding="ascii")
|
|
assert "DELETE|1\n" in output.read_text(encoding="ascii")
|