116 lines
4.4 KiB
Python
116 lines
4.4 KiB
Python
"""Chinese appendix facts for issue #91 section A.
|
||
|
||
Dosha, friendship, and yoga cells come from structured fields. The Chinese
|
||
appendix is not an English render with the short-word sanitizer applied.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from scripts.pl9_full_data_export import (
|
||
_render_pl9_ai_density_raw_data_markdown_zh,
|
||
render_full_data_markdown,
|
||
)
|
||
from scripts.report_render.appendix_language import (
|
||
chinese_prose_gates,
|
||
dosha_row,
|
||
friendship_table,
|
||
)
|
||
from tests.test_report_full_data_fix import _packet
|
||
|
||
|
||
def test_dosha_rows_use_structured_fields() -> None:
|
||
missing = dosha_row("mangal_dosha", {}, "zh")
|
||
assert missing is not None
|
||
assert missing[1] == "未判定"
|
||
assert dosha_row("mangal_dosha", {}, "en")[1] == "Not determined"
|
||
|
||
clear = dosha_row("mangal_dosha", {"has_dosha": False}, "zh")
|
||
assert clear is not None and clear[1] == "无"
|
||
assert "火星不在煞宫" in clear[2]
|
||
english = dosha_row("mangal_dosha", {"has_dosha": False}, "en")
|
||
assert english is not None and english[1] == "No"
|
||
assert "not in a dosha house" in english[2]
|
||
|
||
partial = dosha_row("kaal_sarp_dosha", {
|
||
"has_dosha": True,
|
||
"type": "partial",
|
||
"planets_in_axis": ["Sun", "Moon", "Mars", "Mercury", "Jupiter"],
|
||
"planets_outside": ["Venus", "Saturn"],
|
||
"rahu_house": 1,
|
||
"ketu_house": 7,
|
||
}, "zh")
|
||
assert partial is not None
|
||
assert partial[1] == "部分"
|
||
assert "7 颗中 5 颗" in partial[2]
|
||
assert "北交点/罗睺在第 1 宫" in partial[2]
|
||
partial_en = dosha_row("kaal_sarp_dosha", {
|
||
"has_dosha": True,
|
||
"type": "partial",
|
||
"planets_in_axis": ["Sun", "Moon", "Mars", "Mercury", "Jupiter"],
|
||
"planets_outside": ["Venus", "Saturn"],
|
||
"rahu_house": 1,
|
||
"ketu_house": 7,
|
||
}, "en")
|
||
assert partial_en is not None and "5 of 7" in partial_en[2]
|
||
|
||
|
||
def test_friendship_reads_rows_not_snapshot_keys() -> None:
|
||
snapshot = {
|
||
"status": "parameter_sensitive",
|
||
"rows": [
|
||
{
|
||
"planet": "Sun",
|
||
"natural": {"friends": ["Moon", "Mars"], "enemies": ["Venus"], "neutral": ["Mercury"]},
|
||
"temporary": {"friends": ["Jupiter"], "enemies": ["Saturn"]},
|
||
"compound": {"great_friends": ["Moon"], "friends": [], "neutral": [], "enemies": [], "great_enemies": ["Saturn"]},
|
||
}
|
||
],
|
||
}
|
||
headers, rows = friendship_table(snapshot, "zh")
|
||
assert headers[0] == "行星"
|
||
assert headers[-1] == "复合关系"
|
||
assert rows[0][0] == "太阳"
|
||
assert "月亮" in rows[0][1]
|
||
assert "极友:月亮" in rows[0][-1]
|
||
assert "GREAT_FRIEND" not in rows[0][-1]
|
||
_, english_rows = friendship_table(snapshot, "en")
|
||
assert english_rows[0][0] == "Sun"
|
||
assert "Great friend: Moon" in english_rows[0][-1]
|
||
|
||
|
||
def test_chinese_appendix_is_not_back_translated() -> None:
|
||
packet = _packet("zh")
|
||
packet["worksheets"]["strengths_and_scores"]["planetary_friendship"] = {
|
||
"rows": [{
|
||
"planet": "Sun",
|
||
"natural": {"friends": ["Moon"], "enemies": [], "neutral": ["Mars"]},
|
||
"temporary": {"friends": ["Jupiter"], "enemies": ["Venus"]},
|
||
"compound": {"great_friends": ["Moon"], "friends": [], "neutral": [], "enemies": [], "great_enemies": []},
|
||
}],
|
||
}
|
||
appendix = _render_pl9_ai_density_raw_data_markdown_zh(packet)
|
||
assert "## 行星友敌关系矩阵" in appendix
|
||
assert "## Planetary Friendship Matrix" not in appendix
|
||
assert "Natural friends" not in appendix
|
||
assert "极友:月亮" in appendix
|
||
assert "Aries" not in appendix
|
||
assert "白羊座" in appendix
|
||
assert "第 1 宫宫主" in appendix
|
||
assert "house " not in appendix
|
||
gates = chinese_prose_gates(appendix)
|
||
assert gates == {"english_signs": 0, "han_function_glue": 0}
|
||
|
||
rendered = render_full_data_markdown(packet)
|
||
rendered_gates = chinese_prose_gates(rendered)
|
||
assert rendered_gates["english_signs"] == 0
|
||
assert rendered_gates["han_function_glue"] == 0
|
||
assert "Raja Yoga" not in rendered
|
||
assert "blocked" not in rendered.lower()
|
||
|
||
|
||
def test_chinese_prose_gates_catch_sign_names_and_glue() -> None:
|
||
sample = "```jyotish-chart\nAries\n```\n正文 Aries。火星 in 12,in ),, :"
|
||
gates = chinese_prose_gates(sample)
|
||
assert gates["english_signs"] == 1
|
||
assert gates["han_function_glue"] == 3
|