Files
yiyezhqiu-refactored/tests/integration/test_compatibility_probe.py
T

81 lines
2.8 KiB
Python

import json
import subprocess
from pathlib import Path
import pytest
from dx_productivity.bridge.probe_host import main, write_probe_marker
def test_probe_marker_is_versioned_json(tmp_path: Path) -> None:
output = tmp_path / "compatibility.json"
write_probe_marker(output, "named", {"selected_query": True})
assert output.read_text(encoding="utf-8") == (
'{"format_version":1,"route":"named","selected_query":true}\n'
)
def test_probe_cli_merges_capability_payload(tmp_path: Path) -> None:
output = tmp_path / "compatibility.json"
exit_code = main(
[
"--output",
str(output),
"--route",
"named",
"--payload-json",
'{"yield_method":"Scripting.DoEvents","retained_reference":true}',
]
)
assert exit_code == 0
assert json.loads(output.read_text(encoding="utf-8"))["yield_method"] == (
"Scripting.DoEvents"
)
def test_probe_cli_rejects_non_object_payload(tmp_path: Path) -> None:
with pytest.raises(ValueError, match="JSON object"):
main(
[
"--output",
str(tmp_path / "compatibility.json"),
"--route",
"named",
"--payload-json",
"[]",
]
)
def test_startup_probe_uses_packaged_executable_and_records_portable_path() -> None:
text = Path("integration/dxdesigner795/CompatibilityProbe.vbs").read_text(
encoding="ascii"
)
assert "DxDesignerTools.exe" in text
assert '"script_path_source"' in text
assert '"portable_root_valid"' in text
assert "DXTOOLS_HOME" not in text
assert "py -3.12" not in text
assert "D:\\NET_CHECK" not in text
assert text.isascii()
def test_probe_reads_native_location_and_parent_methods(tmp_path: Path) -> None:
fake = Path("tests/vbs/test_refdes_export.vbs").read_text(encoding="ascii").split('Set Fso = CreateObject')[0]
probe = Path("integration/dxdesigner795/CompatibilityProbe.vbs").read_text(encoding="ascii")
harness = tmp_path / "probe.vbs"
harness.write_text(fake + "\n" + probe + '\nSet Component = New FakeComponent\n'
'Set Component.Location = New FakeLocation\nComponent.Location.X = 10\nComponent.Location.Y = 20\n'
'Set Component.Parent = New FakeParentBlock\nComponent.ComponentName = "R1"\n'
'If DxToolsProbePositionMethod(Component) <> "GetLocation().X/Y" Then WScript.Quit 7\n'
'If DxToolsProbePathMethod(Component) = "" Then WScript.Quit 8\n'
'WScript.Echo "native getters verified"\n', encoding="ascii")
result = subprocess.run(["cscript", "//nologo", str(harness)], capture_output=True)
assert result.returncode == 0, result.stderr.decode("mbcs", errors="replace")
assert b"native getters verified" in result.stdout