Files
Jyotisha/tests/test_dasha_master_children.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

232 lines
9.7 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.
"""T5: sourced dasha children are copied into the master pack and rendered."""
from __future__ import annotations
from copy import deepcopy
from datetime import datetime
from scripts.annual_native.dasha_children import (
attach_kalachakra_simplified_children,
enrich_master_family,
)
from scripts.ashtottari_dasha import calculate_ashtottari_dasha
from scripts.jyotish_engine import _native_dasha_master_families
from scripts.kalachakra_dasha import calculate_kalachakra_dasha
from scripts.pl9_reader_export import render_pl9_parity_markdown
from scripts.yogini_dasha import calculate_yogini_dasha
def _major_view(row: dict) -> tuple:
return (
row.get("lord") or row.get("planet") or row.get("rashi") or row.get("sign"),
row.get("rashi") or row.get("sign"),
row.get("years"),
row.get("start_date") or row.get("start"),
row.get("end_date") or row.get("end"),
)
def _applicable_ashtottari() -> dict:
for index in range(27):
result = calculate_ashtottari_dasha({
"moon_nakshatra_index": index,
"is_shukla_paksha": True,
"moon_longitude": index * (360.0 / 27.0) + 1.0,
"birth_datetime": datetime(1990, 1, 1, 12, 0),
})
if result.get("major"):
return result
raise AssertionError("no applicable Ashtottari fixture")
def test_kalachakra_children_hang_on_existing_majors() -> None:
source = calculate_kalachakra_dasha({
"moon_nakshatra_index": 0,
"moon_pada": 1,
"birth_datetime": datetime(1990, 6, 15, 10, 30),
})
before = [_major_view(row) for row in source["major"]]
enriched, antardasha, pratyantar = attach_kalachakra_simplified_children(
source["major"], source["total_cycle"],
)
assert [_major_view(row) for row in source["major"]] == before
# 原值: major 行没有 antardasha
# 新值: 计算函数自己挂上子运
# 原因: 上游 f353a096 在返回前附上按比例的子运;简化附件仍只改副本
assert source["major"][0]["antardasha"]
assert [_major_view(row) for row in enriched] == before
assert antardasha and pratyantar
assert enriched[0]["antardasha"][-1]["end_date"] == enriched[0]["end_date"]
assert enriched[0]["antardasha"][0]["model"] == "simplified"
assert enriched[0]["antardasha"][0]["pratyantardasha"]
def test_master_pack_keeps_sourced_children_and_leaves_modules_alone() -> None:
ashtottari = _applicable_ashtottari()
yogini = calculate_yogini_dasha({
"birth_datetime": datetime(1990, 6, 15, 10, 30),
"moon_longitude": 10.0,
"as_of": datetime(2020, 1, 1),
})
kalachakra = calculate_kalachakra_dasha({
"moon_nakshatra_index": 0,
"moon_pada": 1,
"birth_datetime": datetime(1990, 6, 15, 10, 30),
})
narayana = {
"mahadasha_sequence": [{
"sign": "Aries", "lord": "Mars", "years": 7,
"start_age": 0, "end_age": 7, "period_key": "md-0",
}],
"dense_boundaries": [{
"level": "AD", "sign": "Taurus", "lord": "Venus",
"duration_years": 1, "start_age": 0, "end_age": 1,
"parent_md": "Aries", "parent_period_key": "md-0",
}],
}
tribhagi = {"major": [{
"lord": "Sun", "years": 1,
"start_date": "2000-01-01T00:00:00", "end_date": "2001-01-01T00:00:00",
}]}
families = _native_dasha_master_families({
"ashtottari_dasha": ashtottari,
"yogini_dasha": yogini,
"kalachakra_dasha": kalachakra,
"narayana_dasha": narayana,
"tribhagi_dasha": tribhagi,
"dasha": {"timeline": [{"lord": "Sun", "start": "2000-01-01", "end": "2006-01-01"}]},
})
assert families["ashtottari"]["periods"][0]["antardasha"]
assert families["yogini"]["periods"][0]["antardasha"]
assert families["kala_chakra"]["periods"][0]["antardasha"][0]["pratyantardasha"]
assert families["narayana"]["periods"][0]["antardasha"][0]["sign"] == "Taurus"
assert "antardasha" not in tribhagi["major"][0]
assert "antardasha" not in yogini["major"][0]
# 原值: kalachakra major 行没有 antardasha
# 新值: 无月亮经度时也带按比例子运
# 原因: 上游 f353a096 的简化路径同样在返回前附上子运
assert kalachakra["major"][0]["antardasha"]
assert "antardasha" not in narayana["mahadasha_sequence"][0]
assert [_major_view(row) for row in families["kala_chakra"]["periods"]] == [
_major_view(row) for row in kalachakra["major"]
]
assert families["vimshottari"]["periods"][0]["lord"] == "Sun"
assert "antardasha" not in families["vimshottari"]["periods"][0]
def test_missing_child_rule_and_kalachakra_model_are_labeled() -> None:
packet = {
"report_language": "zh",
"worksheets": {"timing_and_predictive_systems": {"dasha_master_pack": {"families": {
"tribhagi": {"periods": [{
"lord": "Sun", "years": 1,
"start_date": "2000-01-01T00:00:00", "end_date": "2001-01-01T00:00:00",
}]},
"kala_chakra": {"periods": [{
"lord": "Sun", "rashi": "Aries", "years": 7,
"start_date": "2000-01-01T00:00:00", "end_date": "2007-01-01T00:00:00",
"antardasha": [{
"lord": "Moon", "rashi": "Cancer", "parent_rashi": "Aries",
"start_date": "2000-01-01T00:00:00", "end_date": "2001-01-01T00:00:00",
"pratyantardasha": [{
"lord": "Mars", "rashi": "Aries",
"start_date": "2000-01-01T00:00:00", "end_date": "2000-02-01T00:00:00",
}],
}],
}]},
}}}},
}
chinese = render_pl9_parity_markdown(packet)
# 原值:"本体系未提供子运"、"次小运"
# 新值:"本体系未提供小运"、"细运"(Kala Chakra 说明与 PD 表头),且不再出现子运、次小运
# 原因:报告运期名称按占星师口径(issue #163 Q5):MD 大运、AD 小运、PD 细运
assert "本体系未提供小运" in chinese
assert "简化模型" in chinese
assert "细运" in chinese
assert "子运" not in chinese and "次小运" not in chinese
english = render_pl9_parity_markdown({**packet, "report_language": "en"})
assert "This system does not provide sub-periods." in english
assert "Simplified model" in english
def test_enrich_does_not_invent_children_for_vimshottari() -> None:
rows = enrich_master_family("vimshottari", {"timeline": []}, [{"lord": "Sun", "years": 6}])
assert rows == [{"lord": "Sun", "years": 6}]
assert "antardasha" not in rows[0]
def test_enrich_keeps_existing_keys_and_values_on_every_system() -> None:
"""Child fields may be added. Keys and values that were already there stay."""
yogini_row = {
"yogini": "Mangala",
"planet": "Moon",
"lord": "Moon",
"full_years": 1,
"years": 1.0,
"start_date": "1990-01-01T00:00:00",
"end_date": "1991-01-01T00:00:00",
"unclipped_start_date": "1990-01-01T00:00:00",
"marker": "keep-yogini",
}
narayana_module = {
"mahadasha_sequence": [{
"sign": "Aries", "lord": "Mars", "years": 7,
"start_age": 0, "end_age": 7, "period_key": "md-0",
}],
"dense_boundaries": [{
"level": "AD", "sign": "Taurus", "lord": "Venus",
"duration_years": 1, "start_age": 0, "end_age": 1,
"parent_md": "Aries", "parent_period_key": "md-0",
}],
}
narayana_row = {
"sign": "Aries", "lord": "Mars", "years": 7,
"start_age": 0, "end_age": 7, "period_key": "md-0",
"marker": "keep-narayana",
}
kala_row = {
"lord": "Sun", "rashi": "Aries", "years": 7, "full_years": 7,
"start_date": "1990-01-01T00:00:00", "end_date": "1997-01-01T00:00:00",
"marker": "keep-kala",
}
plain = {"lord": "Sun", "years": 6, "full_years": 6, "marker": "keep-plain"}
samples = {
"vimshottari": ({}, [{**plain, "marker": "keep-vim"}]),
"yogini": ({"dasha_year_days": 365.25}, [yogini_row]),
"narayana": (narayana_module, [narayana_row]),
"kala_chakra": ({"total_cycle": 7}, [kala_row]),
"ashtottari": ({}, [{**plain, "marker": "keep-ashtottari"}]),
"tribhagi": ({}, [{**plain, "marker": "keep-tribhagi"}]),
"tribhagi_40": ({}, [{**plain, "marker": "keep-tribhagi-40"}]),
"shodashottari": ({}, [{**plain, "marker": "keep-shodashottari"}]),
"dwadashottari": ({}, [{**plain, "marker": "keep-dwadashottari"}]),
"dwisaptatisama": ({}, [{**plain, "marker": "keep-dwisaptatisama"}]),
"shattrimshatsama": ({}, [{**plain, "marker": "keep-shattrimshatsama"}]),
"panchottari": ({}, [{**plain, "marker": "keep-panchottari"}]),
"satabdika": ({}, [{**plain, "marker": "keep-satabdika"}]),
"chaturshitisama": ({}, [{**plain, "marker": "keep-chaturshitisama"}]),
"shastihayani": ({}, [{**plain, "marker": "keep-shastihayani"}]),
}
for key, (module, rows) in samples.items():
before = deepcopy(rows)
enriched = enrich_master_family(key, module, rows)
assert rows == before
assert len(enriched) == len(before)
for old, new in zip(before, enriched):
for field, value in old.items():
assert field in new
assert new[field] == value
def test_yogini_enrich_keeps_the_row_when_full_years_is_missing() -> None:
row = {
"yogini": "Mangala",
"planet": "Moon",
"years": 1,
"start_date": "1990-01-01",
"end_date": "1991-01-01",
}
enriched = enrich_master_family("yogini", {}, [row])
assert enriched[0] == row
assert "antardasha" not in enriched[0]