同一份真实盘包在屏蔽与不屏蔽 PyJHora 下新旧渲染 sha 都一致,各 24 项且退出码 0。指定 pytest 233 通过、3 跳过。 Co-Authored-By: Grok (agent loop)
115 lines
4.1 KiB
Python
115 lines
4.1 KiB
Python
"""Phase-1 report_render package: import boundary and moved-helper parity."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
ORIGINAL_PLANET_LABEL_CN = {
|
|
"Sun": "太阳",
|
|
"Moon": "月亮",
|
|
"Mars": "火星",
|
|
"Mercury": "水星",
|
|
"Jupiter": "木星",
|
|
"Venus": "金星",
|
|
"Saturn": "土星",
|
|
"Rahu": "北交点",
|
|
"Ketu": "南交点",
|
|
}
|
|
|
|
|
|
def test_report_render_imports_without_engine() -> None:
|
|
code = "\n".join([
|
|
"import sys",
|
|
"import scripts.report_render.envelope",
|
|
"import scripts.report_render.text",
|
|
"import scripts.report_render.sections_misc",
|
|
"banned = [name for name in sys.modules if name == 'jyotish_engine' or name.startswith('jyotish_engine.') or name == 'scripts.jyotish_engine' or name.startswith('scripts.jyotish_engine.')]",
|
|
"assert banned == []",
|
|
])
|
|
env = dict(os.environ)
|
|
env["PYTHONPATH"] = str(ROOT)
|
|
env["PYTHONHASHSEED"] = "0"
|
|
completed = subprocess.run(
|
|
[sys.executable, "-c", code],
|
|
cwd=ROOT,
|
|
env=env,
|
|
text=True,
|
|
capture_output=True,
|
|
check=False,
|
|
)
|
|
assert completed.returncode == 0, completed.stderr
|
|
|
|
|
|
def test_planet_label_and_signs_match_engine_literals() -> None:
|
|
from scripts.jyotish_engine import SIGNS, SIGNS_CN
|
|
from scripts.report_render import text as moved
|
|
|
|
assert list(moved.PLANET_LABEL_CN) == list(ORIGINAL_PLANET_LABEL_CN)
|
|
for key, value in ORIGINAL_PLANET_LABEL_CN.items():
|
|
assert moved.PLANET_LABEL_CN[key] == value
|
|
assert moved.SIGNS == SIGNS
|
|
assert moved.SIGNS_CN == SIGNS_CN
|
|
|
|
|
|
def _first(packet, kind: str):
|
|
stack = [packet]
|
|
while stack:
|
|
current = stack.pop()
|
|
if kind == "bool" and isinstance(current, bool):
|
|
return current
|
|
if kind == "str" and isinstance(current, str) and current.strip():
|
|
return current
|
|
if kind == "list" and isinstance(current, list) and current:
|
|
return current
|
|
if isinstance(current, dict):
|
|
stack.extend(current.values())
|
|
elif isinstance(current, (list, tuple)):
|
|
stack.extend(list(current))
|
|
raise AssertionError(kind)
|
|
|
|
|
|
def test_five_moved_helpers_match_engine_on_real_packet() -> None:
|
|
from scripts.jyotish_engine import (
|
|
_bool_text,
|
|
_envelope_list,
|
|
_humanize_reader_token,
|
|
_md_cell,
|
|
_unwrap,
|
|
build_professional_report_reference_packet,
|
|
cmd_full_reading,
|
|
render_pl9_markdown,
|
|
)
|
|
from scripts.professional_report_reference import _export_args
|
|
from scripts.report_render.envelope import _bool_text as moved_bool
|
|
from scripts.report_render.envelope import _envelope_list as moved_list
|
|
from scripts.report_render.envelope import _unwrap as moved_unwrap
|
|
from scripts.report_render.text import _humanize_reader_token as moved_token
|
|
from scripts.report_render.text import _md_cell as moved_cell
|
|
from tests.test_report_reader_main import FICTIONAL
|
|
|
|
reading = cmd_full_reading(SimpleNamespace(**FICTIONAL))
|
|
packet = build_professional_report_reference_packet(reading, _export_args(dict(FICTIONAL)), [])
|
|
rendered = render_pl9_markdown(packet)
|
|
assert isinstance(rendered, str) and len(rendered) > 100
|
|
flag = _first(packet, "bool")
|
|
label = _first(packet, "str")
|
|
rows = _first(packet, "list")
|
|
birth = packet.get("birth_info")
|
|
assert _bool_text(flag) == moved_bool(flag)
|
|
assert _md_cell(label) == moved_cell(label)
|
|
assert _unwrap(birth) == moved_unwrap(birth)
|
|
assert _humanize_reader_token("Sun") == moved_token("Sun")
|
|
assert _humanize_reader_token("Aries") == moved_token("Aries")
|
|
assert _envelope_list(rows) == moved_list(rows)
|
|
assert _bool_text is moved_bool
|
|
assert _md_cell is moved_cell
|
|
assert _unwrap is moved_unwrap
|
|
assert _humanize_reader_token is moved_token
|
|
assert _envelope_list is moved_list
|