Files
Jyotisha/tests/test_report_reader_wording_2095.py
T

137 lines
7.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""BUG-2095: no internal codes, version codes, grade letters or 「只作参考」 in the personal report.
The astrologer's layering rule (2026-11-19): readers never see grade letters (A–D), internal
codes, rule ids or status codes, and the report does not use responsibility-shedding phrases.
Owner 2026-11-20: technique names (Bhrigu Bindu, Sarpa Drekkana, Saham names ...) stay; only
the stored keys become those names.
Charts are synthetic, or the repository's two public fixture charts.
"""
from __future__ import annotations
import re
import pytest
from scripts.pl9_language_terms import soften_lifespan_wording
from scripts.rashi_dasha_report import _method_line
from scripts.report_render.opening_guide import NARAYANA_OPEN_READER_ZH
from scripts.report_render.reader_keys import reader_key
from scripts.report_render.technique_status_axes import functional_profile_text, technique_audit_text
from tests.public_chart_reports import PUBLIC_REPORT_CASES, public_chart_reports
SNAKE = re.compile(r"\b[a-z]+(?:_[a-z0-9]+)+\b")
GRADE_LETTER = re.compile(r"[((][A-D][))]")
# "cross-reference only" (a method statement in the backstage gate line) is not the phrase.
REFERENCE_ONLY = re.compile(r"只作参考|仅作参考|(?<!cross-)\b[Rr]eference only\b")
# The one allowed occurrence: the English effect text of Matrunasa Yoga comes verbatim from the
# rule data (references/yoga_rules.json, `effects_en`), which this change does not own; its
# Chinese twin is not printed. Listed so that any other occurrence still fails.
RULE_DATA_ALLOWED = ("reference only, not a statement about the mother's health or life",)
def _reader_text(markdown: str) -> str:
"""Reader text: code fences, code spans, link targets and bare URLs are skipped."""
text = re.sub(r"```.*?```", "", markdown, flags=re.S)
text = re.sub(r"`[^`\n]*`", "", text)
text = re.sub(r"\]\([^)]*\)", "]", text)
text = re.sub(r"https?://\S+", "", text)
for allowed in RULE_DATA_ALLOWED:
text = text.replace(allowed, "")
return text
def _editions():
for case in PUBLIC_REPORT_CASES:
_packet, chinese, english = public_chart_reports(case)
yield case, "zh", chinese
yield case, "en", english
@pytest.mark.parametrize("case", PUBLIC_REPORT_CASES)
def test_both_editions_show_no_codes_version_codes_grade_letters_or_reference_only(case):
_packet, chinese, english = public_chart_reports(case)
for language, markdown in (("zh", chinese), ("en", english)):
text = _reader_text(markdown)
assert SNAKE.findall(text) == [], (case, language, sorted(set(SNAKE.findall(text)))[:20])
assert "pvr_table30_v1" not in text, (case, language)
assert GRADE_LETTER.findall(text) == [], (case, language)
assert REFERENCE_ONLY.findall(text) == [], (case, language)
def test_internal_keys_become_technique_names_in_both_languages():
assert reader_key("bhrigu_bindu", "zh") == reader_key("bhrigu_bindu", "en") == "Bhrigu Bindu"
assert reader_key("sarpa_drekkana", "en") == "Sarpa Drekkana"
assert reader_key("new_year_lord", "zh") == "年首星座主"
assert reader_key("new_year_lord", "en") == "Lord of the year's opening sign"
assert reader_key("day_lord", "zh") == "日主" and reader_key("day_lord", "en") == "Day lord"
# A key with no known reader name: Title Case, no underscores, no version code.
assert reader_key("punya_saham", "zh") == "Punya Saham"
assert reader_key("some_new_method_v2", "en") == "Some New Method"
# Generic tables keep unknown keys for the edition's later word pass.
assert reader_key("dt_local", "zh", title_case=False) == "dt_local"
# Values that are not keys are untouched.
assert reader_key("Jupiter", "en") == "Jupiter" and reader_key(12.5, "zh") == 12.5
def test_sensitive_point_tables_print_the_point_names():
for case, language, markdown in _editions():
assert "| Bhrigu Bindu |" in markdown, (case, language)
assert "| bhrigu_bindu |" not in markdown, (case, language)
def test_functional_profile_is_named_without_its_version_code():
assert functional_profile_text("pvr_table30_v1", "zh") == "PVR 表 30"
assert functional_profile_text("pvr_table30_v1", "en") == "PVR Table 30"
for case, language, markdown in _editions():
prose = markdown.replace("PVR 表 30(第 1 版)", "").replace("PVR Table 30 (version 1)", "")
assert "pvr_table30_v1" not in prose, (case, language)
def test_technique_audit_condition_is_written_in_words():
axes = {"calculation_status": "executed", "interpretation_status": "conditional",
"interpretation_evidence": "parameter_sensitive"}
assert technique_audit_text({}, axes, "zh") == "计算已执行,解读有条件(结果会随算法设置变化)"
assert technique_audit_text({}, axes, "en") == (
"Calculation completed, conditional interpretation (results change with the calculation settings)")
def test_rashi_dasha_method_is_named_not_coded():
section = {"status": "listed", "profile_id": "goel_method_1_v1", "source_zh": "某书,印页 1", "source_en": "A book, page 1"}
# 原值: 「本站选用的方法:Goel 第一法,出处:某书,印页 1;…」/ "…Goel method 1, source: A book, page 1;"
# 新值: 只写方法名
# 原因: BUG-2129 负责人 2026-11-21:报告里不给读者出现书名、作者出处、页码和章节号
assert _method_line(section, "zh") == "本站选用的方法:Goel 第一法;未与外部软件逐一核对。"
assert _method_line(section, "en") == "Method used on this site: Goel method 1; not checked one-by-one against external software."
def test_kp_significator_levels_are_words_not_letters():
for case, language, markdown in _editions():
assert "(A)" not in markdown and "(A)" not in markdown, (case, language)
assert "| A | B | C | D |" not in markdown, (case, language)
_packet, chinese, english = public_chart_reports(PUBLIC_REPORT_CASES[0])
assert "| 很强 | 强 | 一般 | 较弱 |" in chinese
assert "| Very strong | Strong | Normal | Weak |" in english
def test_limits_are_stated_instead_of_reference_only():
assert "只作参考" not in NARAYANA_OPEN_READER_ZH and "没定的几处和各种排法" in NARAYANA_OPEN_READER_ZH
assert soften_lifespan_wording("长寿", "zh") == "传统上与体质和恢复力有关,不用来推断寿命"
assert soften_lifespan_wording("longevity", "en") == (
"Traditionally associated with constitution and recovery; not used to judge length of life.")
_packet, chinese, english = public_chart_reports(PUBLIC_REPORT_CASES[0])
# 原值: "所列的传统做法:不保证任何效果"
# 新值: "不列做法):不保证任何效果"(介绍句注明近似筛查的候选结构不列做法)
# 原因: BUG-2110 占星师 2026-11-21:时蛇煞宫位筛查只是候选结构,不列传统做法
# BUG-2221 原值: 断言介绍句「不列做法):不保证任何效果」;新值: 不再按大运主星列做法,这张盘没有检出 Dosha 时整张表不出现;
# 出现时写明不需要照做、不保证改变结果。原因: 占星师 2026-11-22 回复第六节
assert "### 传统辅助建议" not in chinese
if "### 传统文化资料(可选阅读)" in chinese:
assert "不需要照做,也不保证改变事情的结果" in chinese
if "### Traditional cultural notes (optional reading)" in english:
assert "Nothing here needs to be done" in english
assert "这张盘不按这套大运看时间" in chinese
assert "so this chart's timing is not read from it" in english