Files
Jyotisha/tests/test_report_dasha_level_terms.py
ClaudeandClaude Opus 5.5 7d1057ccc5
Independent Staging Quality Gate / validate (push) Successful in 21m50s
Independent Staging Quality Gate / publish (push) Successful in 4m21s
feat(report): Vimshottari levels 大运 / 小运 / 细运 across the report pipeline
The personal report now uses the astrologer-approved names, matching the
chart page and the consult prompts since 7a56840f (issue #163 Q5): MD 大运,
AD 小运, PD 细运. Old names replaced in code-rendered text only: 主运 / 主大运
-> 大运, 子运 / 分运 / 副运 (AD) -> 小运, 次子运 / 次小运 / 再小运 and the
fact table's PD 小运 -> 细运. PD strings were converted before AD, and AD
before MD.

Covered: the focus card and its export text, the raw fact tables, theme
claim cards, the timing interpretation pack, the PL9 full-data export
(tables, dasha prose templates, AD/PD density anchors), rashi / Narayana
second level, KP monthly focus, orchestrator texts and technique-audit
rows. English translation keys follow the new Chinese labels
(大运 = Mahadasha, 小运 = Antardasha, 细运 = Pratyantardasha), and a new test
pins that no English mapping reads 小运 as the third level.

The five-level monthly sample table used 细运 for Sookshma; it now shows
Sookshma until the astrologer names the fourth level.

Saved reports are not migrated. Focus fences render from md/ad/pd codes,
and stored fact tables validate by structure, so old and new labels both
open. Goldens were updated in place and two hash pins re-pinned; reverting
only the term swap reproduces the old hashes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyeZrYn6ryNcSe5Y2Y
2026-11-02 21:32:51 +08:00

68 lines
3.5 KiB
Python
Raw Permalink 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.
"""Vimshottari level names in the report pipeline (issue #163 Q5).
MD 大运, AD 小运, PD 细运. The Chinese report renders these names, and the
English edition maps them back to Mahadasha / Antardasha / Pratyantardasha.
Before the rename 小运 meant PD in some tables, so a stale English mapping
could turn the new AD 小运 into "Pratyantardasha". These checks pin both
directions.
"""
from __future__ import annotations
import re
from scripts.narayana_rath import AD_DIRECTION_RULE
from scripts.pl9_full_data_export import _sanitize_pl9_ai_density_markdown
from scripts.pl9_language_terms import _EN_RESIDUAL_HAN, apply_en_residual_han
from scripts.pl9_reader_english import _translate, han_leaks
from scripts.pl9_reader_english_terms import PHRASES_EN, REGEX_EN
OLD_TERMS = re.compile(r"主运|子运|分运|次小运|再小运|主大运|副运")
PD_EN = re.compile(r"Pratyantar|\bPD\b|sub-sub", re.IGNORECASE)
def test_zh_dasha_prose_uses_the_three_level_names() -> None:
markdown = "\n\n".join([
"# PL9 对标主册",
"## 大运长页解释(PL9 p190-p204 对标)",
"### Interpretation of the Maha Dasha of Jupiter",
"#### Effects of Antar Dasha of Saturn in the Maha Dasha of Jupiter",
"The Antar Dasha of Saturn activates Saturn's natural themes inside the broader Maha Dasha of Jupiter.",
"##### Pratyantar Dasha of Mercury in the Antar Dasha of Saturn",
"",
])
text = _sanitize_pl9_ai_density_markdown(markdown, opening_summary=False)
assert "### 木星大运解释" in text
assert "#### 木星大运中土星小运的作用" in text
assert "木星大运中的土星小运,会把土星的自然主题带入当前阶段。" in text
# The AD reading note is still added under the AD sentence.
assert "这一小运不是单独结论,而是把土星的自然象征放进木星大运的背景里筛选。" in text
assert "##### 土星小运中的水星细运" in text
assert OLD_TERMS.search(text) is None
def test_english_tables_map_the_new_names_to_the_sanskrit_levels() -> None:
phrases = dict(PHRASES_EN)
assert phrases["| 序号 | 大运 | 起始 | 结束 | 年数 |"] == "| No. | Mahadasha | Start | End | Years |"
assert phrases["| Vimshottari AD | 大运 | 小运 | 起始 | 结束 |"] == "| Vimshottari AD | Mahadasha | Antardasha | Start | End |"
assert phrases["| Vimshottari PD | 大运 | 小运 | 细运 | 起始 | 结束 |"] == (
"| Vimshottari PD | Mahadasha | Antardasha | Pratyantardasha | Start | End |"
)
for zh in ("| Vimshottari AD | 大运 | 小运 | 起始 | 结束 |", "| Vimshottari PD | 大运 | 小运 | 细运 | 起始 | 结束 |"):
english = _translate(zh)
assert han_leaks(english) == []
def test_no_english_mapping_reads_小运_as_the_third_level() -> None:
entries = list(PHRASES_EN) + list(_EN_RESIDUAL_HAN) + [(pattern.pattern, replacement) for pattern, replacement in REGEX_EN]
for zh, english in entries:
assert OLD_TERMS.search(zh) is None, zh
if "小运" in zh and "细运" not in zh:
assert PD_EN.search(english) is None, (zh, english)
# The Narayana AD rule text and its residual English pieces.
zh_rule, en_rule = AD_DIRECTION_RULE["rath_table13_v1"]
assert zh_rule == "按小运起点星座奇偶(Table 13)"
assert dict(PHRASES_EN)[zh_rule] == en_rule
assert apply_en_residual_han("按小运起点星座奇偶") == "by the odd or even sign where the sub-period starts"
assert "sub-period" in apply_en_residual_han("Leo 的小运")