Files
Jyotisha/tests/test_report_appendix_detail.py
T
ClaudeandClaude Fable 5.2 b01f3ce870
Independent Staging Quality Gate / validate-frontend (push) Successful in 5m38s
Independent Staging Quality Gate / validate-python (push) Successful in 7m54s
Independent Staging Quality Gate / publish (push) Successful in 3m21s
fix(report): an unsupported reference drops its sentence, not the section; Ashtakavarga is auxiliary outside career and wealth (BUG-2019)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-19 13:12:06 +08:00

210 lines
12 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.
"""Appendix detail (upstream parity): Argala sources and the nakshatra reference."""
from __future__ import annotations
from scripts.report_render.parity_chapters import _argala, _nakshatra_reference
def _packet() -> dict:
house_1 = {
"ref_sign": "Cancer",
"argala_count": 2,
"virodhargala_count": 1,
"net_result": "supported",
"primary": {
"H2": {"house_from_reference": 2, "planets": ["Mercury", "Venus"], "blocked_by_house": 12, "blockers": [], "effective": True},
"H11": {"house_from_reference": 11, "planets": [], "blocked_by_house": 3, "blockers": ["Moon"], "effective": False},
"H4": {"house_from_reference": 4, "planets": [], "blocked_by_house": 10, "blockers": [], "effective": False},
},
"secondary": {
"H5": {"house_from_reference": 5, "planets": [], "role": "argala", "blocked_by_house": 9, "blockers": ["Saturn"], "effective": False},
"H9": {"house_from_reference": 9, "planets": ["Saturn"], "role": "virodhargala", "obstructs_house": 5},
},
"specific": {"house": 3, "planets": ["Moon"], "effective": False},
}
return {"worksheets": {"advanced_systems": {"argala": {"houses": {"house_1": house_1}}}}}
def test_detail_lists_each_source_once_with_its_obstruction() -> None:
text = _argala(_packet(), "zh")
assert "| 1 | 主 Argala | 2 | 水星、金星 | 12 | 无 | 是 |" in text
assert "| 1 | 主 Argala | 11 | 无 | 3 | 月亮 | 否 |" in text
assert "| 1 | 次 Argala | 5 | 无 | 9 | 土星 | 否 |" in text
# The 9th is only an obstruction; it is not a separate Argala row.
assert "| 1 | 次 Argala | 9 |" not in text
# A source with no planets on either side is omitted.
assert "| 1 | 主 Argala | 4 |" not in text
assert "| 1 | 第 3 宫特殊 Argala | 3 | 月亮 |" in text
def test_english_detail() -> None:
text = _argala(_packet(), "en")
assert "| 1 | Primary | 2 | Mercury, Venus | 12 | None | Yes |" in text
def test_nakshatra_reference_reads_the_lord_gana_degree_and_sub_lord() -> None:
packet = {"worksheets": {"advanced_systems": {"nakshatra_adv": {
"natal_nakshatras": {"Sun": {"nakshatra": "Ashlesha", "nakshatra_lord": "Mercury", "pada": 2, "gana": "Rakshasa", "degree_in_nakshatra": 6.3284}},
"sub_lords": {"Sun": {"sub_lord": "Moon"}},
}}}}
assert "| 太阳 | Ashlesha | 2 | 水星 | 罗刹 | 6.3284 | 月亮 |" in _nakshatra_reference(packet, "zh")
assert "| Sun | Ashlesha | 2 | Mercury | Rakshasa | 6.3284 | Moon |" in _nakshatra_reference(packet, "en")
def test_shadbala_components_are_named_and_add_up() -> None:
"""BUG-1660: the six components used generic labels (合计 / 内容 / 年数 / 落座度数 / 容许天数)."""
from scripts.report_render.parity_chapters import _shadbala_parts
sun = {
"sthana_bala": {"ucha_bala": 25.67, "sapta_score": 99.0, "ojayugma_bala": 0.0, "kendra_bala": 60.0, "drekkana_bala": 0.0, "total": 184.67},
"dig_bala": 23.64,
"kala_bala": {"nathonnata": 22.16, "paksha": 43.55, "tribhaga": 0.0, "abda": 0.0, "masa": 0.0, "vaara": 0.0, "hora": 60.0, "ayana": 50.74, "yuddha": 0.0, "total": 176.45},
"chesta_bala": 50.74, "naisargika_bala": 60.0, "drik_bala": 4.62,
"total_virupas": 500.12, "total_rupas": 8.3353, "min_required": 6.5, "ishta_bala_pct": 128.2,
}
packet = {"worksheets": {"strengths_and_scores": {"shadbala": {"planets": {"Sun": sun}}}}}
text = _shadbala_parts(packet, "zh", result_only=False)
assert "| 行星 | Sthana(位置) | Dig(方位) | Kala(时间) | Cheshta(运动) | Naisargika(自然) | Drik(相照) |" in text
assert "| 太阳 | 184.67 | 23.64 | 176.45 | 50.74 | 60.00 | 4.62 | 500.12 | 8.34 | 6.50 | 128.20 |" in text
assert "| 太阳 | 25.67 | 99.00 | 0.00 | 60.00 | 0.00 |" in text
for wrong in ("年数", "落座度数", "容许天数"):
assert wrong not in text
english = _shadbala_parts(packet, "en", result_only=False)
assert "| Planet | Sthana | Dig | Kala | Cheshta | Naisargika | Drik |" in english
def test_vimsopaka_and_varga_ruler_detail() -> None:
from scripts.report_render.parity_chapters import _mapping, _vimsopaka
vims = {"worksheets": {"strengths_and_scores": {"vimsopaka": {"Sun": {
"planet": "Sun", "total_score": 13.45, "category": "Moderate",
"varga_scores": {"Rashi": {"dignity": "Great Friend", "virupas": 18.0, "weight": 3.5, "weighted_score": 63.0}},
}}}}}
assert "| 太阳 | Rashi | 极友 | 18.00 | 3.50 | 63.00 |" in _vimsopaka(vims, "zh")
varga = {"worksheets": {"divisional_and_special_charts": {"varga_full": {
"D9_Navamsa": {"_meta": {"div": 9, "name": "Navamsa"}, "Ascendant": {"sign": "Scorpio"},
"Sun": {"sign": "Aries"}, "Saturn": {"sign": "Aries"}, "Moon": {"sign": "Cancer"}, "Rahu": {"sign": "Taurus"}},
}}}}
text = _mapping(varga, "zh")
assert "| 太阳 | 白羊座 | 火星 | 入旺 |" in text
assert "| 土星 | 白羊座 | 火星 | 落陷 |" in text
assert "| 月亮 | 巨蟹座 | 月亮 | 入庙 |" in text
# BUG-2019(占星师 2026-11-19 第 16 条): 原值 北交点 / 南交点(附录里是 北交点/罗睺、南交点/计都);新值 罗睺 / 计都。
assert "| 罗睺 | 金牛座 | 金星 | — |" in text
def test_prastara_detail_columns_add_up_to_the_bav() -> None:
from scripts.report_render.parity_chapters import _prastara
sun = {"Sun": [1] * 12, "Moon": [0] * 11 + [1], "Lagna": [1] + [0] * 11}
packet = {"worksheets": {"strengths_and_scores": {"ashtakavarga": {
"bav": {"Sun": {"total": 14}},
"pav": {"pav": {"Sun": sun}},
}}}}
text = _prastara(packet, "zh")
assert "**太阳的 Prastara**" in text
assert "| 上升 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |" in text
assert "| 合计(BAV) | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 14 |" in text
def test_avastha_detail_uses_the_module_meaning_and_basis() -> None:
from scripts.report_render.parity_chapters import _avastha
sun = {"planet": "Sun", "sign": "Cancer", "degree": 22.9951, "avasthas": {
"Bala": {"state": "Young", "degree_range": "18-24°", "sign_parity": "even", "method_status": "bphs_age_sign_parity", "meaning": "少年期:行星力量增长中"},
"Jagrat": {"state": "Dreaming", "house": 1, "method_status": "bphs_dignity_natural_relationships", "meaning": "梦境状态:行星半活跃"},
"Deeptadi": {"state": "Shanta", "meaning": "平静状态:…", "conditions": {"natural_friend_sign": True, "exalted": False}, "method_status": "simplified_heuristic"},
}}
rahu = {"planet": "Rahu", "sign": "Leo", "degree": 29.0, "avasthas": {"Jagrat": {"state": "Not classified"}}}
text = _avastha({"worksheets": {"advanced_systems": {"avasthas": {"Sun": sun, "Rahu": rahu}}}}, "zh")
assert "| 太阳 | 巨蟹座 | 梦境(Dreaming) | 22.9951 |" in text
assert "| 太阳 | 年龄(Baladi) | 少年期(Young) | 18-24°,偶数星座 | BPHS 规则 |" in text
assert "| 太阳 | 明暗(Deeptadi) | 平静(Shanta) | 在自然友星星座 | 简化规则 |" in text
assert "Not classified" not in text
def test_goel_component_tables() -> None:
from scripts.report_render.parity_chapters import _goel_components
strength = {
"planets": {"Sun": {"mooltrikona": 22.5, "karaka": 22.5, "kendriya": 30, "kartari": 0, "adhipati": 60, "malefic_contacts": ["Ketu"], "total": 135.0}},
"rashi_strengths": [{"sign": "Aries", "permanent": 15, "karaka": 0, "sthana": 0, "aspect": 60, "aspect_roles": ["Mercury"], "lord_strength": 108.75, "total": 183.75}],
}
text = _goel_components(strength, "zh")
assert "| 太阳 | 22.50 | 22.50 | 30.00 | 0.00 | 60.00 | 计都 | 135.00 |" in text
assert "| 白羊座 | 15.00 | 0.00 | 0.00 | 60.00 | 水星 | 108.75 | 183.75 |" in text
def test_avastha_names_follow_the_calculator_bug_1661() -> None:
"""BUG-1661: Young is 少年期 and Youth 青年期 (the glossary had them shifted); no English states left."""
from scripts.pl9_reader_export import render_pl9_parity_markdown
from scripts.report_render.avastha_terms import avastha_zh
from tests.test_report_longform_parity import _producer_packet
assert avastha_zh("Bala", "Young") == "少年期" and avastha_zh("Bala", "Youth") == "青年期"
states = {
"Bala": {"state": "Old"}, "Jagrat": {"state": "Deep Sleep"},
"Deeptadi": {"state": "Dina", "applicable_states": ["Khala", "Dina"]},
"Lajjitadi": {"state": "Kshudita"}, "Shayanadi": {"state": "Prakashana"},
}
packet = _producer_packet({
# The Avastha table sits in the strengths chapter, which needs strength data.
"strengths_and_scores": {"summary_card": {"has_shadbala": False}},
"advanced_systems": {"avasthas": {"Mercury": {"avasthas": states}}},
})
text = render_pl9_parity_markdown(packet)
row = next(line for line in text.splitlines() if line.startswith("| 水星 |") and "老年期" in line)
assert row == "| 水星 | 老年期 | 深睡 | 负担、低落 | 饥饿 | 显现 |"
def test_nakshatra_context_lists_the_two_strict_ashtottari_gates() -> None:
# 原值: 并列「罗睺不在角宫」与「月亮星宿与月相」两条规则,结论不同时写「两条规则结论不同」
# 新值: BPHS 罗睺条件决定是否适用;昼夜与月相只作记录;加结论
# 原因: BUG-1676,占星师 2026-11-07 两次裁定(第二次:昼夜月相属其他传承,不参与判定);月亮星宿白名单不作门槛
from scripts.report_render.parity_chapters import _nakshatra_context
gates = {
"rahu_from_lagna_lord": {"status": "pass", "position_from_lagna_lord": 5, "rahu_in_lagna": False},
"paksha_day_night": {"status": "fail", "is_shukla_paksha": True, "birth_is_daytime": True, "role": "recorded_only"},
}
packet = {"worksheets": {
"advanced_systems": {"nakshatra_dasha": {
"vimshottari_nak_breakdown": {
"moon_nakshatra": "Hasta", "moon_pada": 1,
"mahadasha": {"lord": "Rahu", "age_range": "15.23-33.23", "progress": 0.7648,
"nakshatra": {"nakshatra": "Uttara Phalguni", "pada": 1, "nakshatra_lord": "Sun"}},
"antardasha": {"lord": "Venus", "start_datetime": "2024-05-21T00:55:37", "end_datetime": "2027-05-21T18:55:37"},
"pada_windows": [{"period": "AD Rahu", "nakshatra": "Uttara Phalguni", "pada": 1, "years": 2.7,
"tara": {"tara_cn": "至友Tara", "tara_name": "ParamaMitra(至友)", "quality": "auspicious"}}],
},
}},
"timing_and_predictive_systems": {"ashtottari_dasha": {
"applicable": False,
"applicability": {"status": "applicable", "gates": gates},
}},
}}
text = _nakshatra_context(packet, "zh")
assert "| 当前大运 | 罗睺,15.23-33.23 岁,已走 76% |" in text
assert "| 小运 罗睺 | Uttara Phalguni | 1 | 2.70 | 至友Tara(吉) |" in text
assert "| 罗睺相对上升主星(BPHS,决定是否适用):不在上升,且在第 4、5、7、9、10 位 | 是 | 罗睺在上升主星起算第 5 位 |" in text
assert "| 昼夜与月相(其他传承,只作记录,不参与判定):白半月夜生或黑半月日生 | 否 | 白半月白天出生 |" in text
assert "罗睺条件满足,Ashtottari 适用(对参数敏感)。" in text
assert "两条规则结论不同" not in text
english = _nakshatra_context(packet, "en")
assert "| Day-night and Paksha (other lineages, recorded only): Shukla night or Krishna day | No | Shukla Paksha, day birth |" in english
assert not any("一" <= ch <= "鿿" for ch in english)
def test_annual_numeric_lists_chart_head_house_and_degree() -> None:
from scripts.report_render.parity_chapters import _annual_numeric
packet = {"worksheets": {"timing_and_predictive_systems": {"annual_tajika_pack": {"annual_year_pages": [{
"target_year": 2026, "local_datetime": "2026-08-08 15:14:41", "ascendant_longitude": 230.6,
"muntha_sign": "Sagittarius", "year_lord": "Jupiter",
"planet_longitudes": {"Sun": 112.9952, "Saturn": 351.8327},
}]}}}}
text = _annual_numeric(packet, "zh")
assert "| 2026 | 2026-08-08 15:14:41 | 天蝎座 20.60° | 射手座 | 木星 |" in text
assert "| 2026 | 太阳 | 巨蟹座 | 9 | 112.9952 | 22.9952 |" in text
assert "| 2026 | 土星 | 双鱼座 | 5 | 351.8327 | 21.8327 |" in text