59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
"""run_external_groups 编排测试(mock 编译/执行,不依赖 cobol/java 工具链)"""
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
|
|
|
|
from cobol_testgen import runner
|
|
from cobol_testgen.blackbox import BlackBoxGroup
|
|
|
|
|
|
def test_run_external_groups_orchestration(tmp_path, monkeypatch):
|
|
fields_dict = [
|
|
{"name": "R01APPL-ID", "level": 3, "pic": "X(8)",
|
|
"pic_info": {"type": "alphanumeric", "digits": 0, "decimal": 0,
|
|
"length": 8, "signed": False}},
|
|
]
|
|
fd_fields = {"R01INNFIL": ["R01APPL-ID"], "W01OUTFIL": ["R01APPL-ID"]}
|
|
select_info = {"R01INNFIL": {"assign": "ZAN04R01"},
|
|
"W01OUTFIL": {"assign": "ZAN04W01",
|
|
"organization": "SEQUENTIAL"}}
|
|
open_dir = {"R01INNFIL": "INPUT", "W01OUTFIL": "OUTPUT"}
|
|
roles = {"R01APPL-ID": "input"}
|
|
field_to_fd = {"R01APPL-ID": "R01INNFIL"}
|
|
|
|
monkeypatch.setattr(runner, "compile_sub_modules", lambda *a, **k: [])
|
|
monkeypatch.setattr(runner, "compile_program",
|
|
lambda *a, **k: str(tmp_path / "P.exe"))
|
|
monkeypatch.setattr(runner, "_discover_java", lambda *a, **k: None)
|
|
|
|
calls = []
|
|
|
|
def fake_run_group(group, exe_path, temp_dir, log_dir=None):
|
|
calls.append((group.name, temp_dir))
|
|
Path(temp_dir, "ZAN04W01").write_bytes(b"A0000001")
|
|
return runner.GroupResult(name=group.name, returncode=0, passed=True)
|
|
|
|
monkeypatch.setattr(runner, "run_group", fake_run_group)
|
|
|
|
groups = [
|
|
BlackBoxGroup(label="g1",
|
|
records=[{"R01APPL-ID": "A0000001"}],
|
|
term_types=["normal"]),
|
|
BlackBoxGroup(label="g2", records=[], term_types=[]),
|
|
]
|
|
outdir = tmp_path / "out"
|
|
results, jreports = runner.run_external_groups(
|
|
"P", str(outdir), str(tmp_path / "work"),
|
|
fields_dict, fd_fields, select_info, open_dir,
|
|
roles, field_to_fd, groups, source_dir=str(tmp_path / "src"),
|
|
)
|
|
|
|
assert [r.name for r in results] == ["P_black_box_g1"]
|
|
assert jreports == []
|
|
out_file = outdir / "black_box" / "g1" / "cobol" / "output" / "ZAN04W01"
|
|
assert out_file.read_bytes() == b"A0000001"
|
|
assert "bb_g1" in calls[0][1]
|