Files
Jyotisha/tests/test_report_fields_2065a.py
T
ClaudeandClaude Opus 5.5 d70866e493 fix(report): no book titles, author citations, pages or chapter numbers in front of the reader (BUG-2129)
Owner 2026-11-21: after BUG-2115 the full-data report still printed source
lines and book references (Goel 出处 line, the PVR 2014 article in the
conditional-dasha note, PVR / Light on Life / BPHS verse in the calculation
notes, Tithi lord table source, rashi-dasha 出处 lines, Narayana p.43 label and
p.50 / Table 13 direction notes, functional profile source row, Ashtakavarga
book calibration). Method names stay; the book, page, chapter and ruling round
go. Engine labels for the consultation card are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
2026-11-21 19:36:15 +08:00

323 lines
17 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-2065 (list A): report tables printed a value under a header that named
something else, dropped engine fields, or blanked values the engine had.
All values here are synthetic.
"""
from __future__ import annotations
import pytest
from scripts import tajika
from scripts.annual_native.saham_traces import attach_formula_traces
from scripts.report_render import parity_chapters as pc
def _table(markdown: str) -> list[list[str]]:
rows = []
for line in markdown.splitlines():
if line.startswith("|") and not set(line) <= set("|- "):
rows.append([cell.strip() for cell in line.strip().strip("|").split("|")])
return rows
def _advanced(**modules) -> dict:
return {"advanced_systems": modules}
# 1. Aspect geometry -------------------------------------------------------
ASPECTS = [
{"planet1": "Rahu", "planet2": "Ketu", "type": "opposition", "aspect_degree": 180,
"actual_diff": 180.0, "orb": 0.0, "applying": None, "phase": "exact"},
{"planet1": "Saturn", "planet2": "Moon", "type": "Saturn_aspect_3", "aspect_degree": 60,
"actual_diff": 62.5, "orb": 2.5, "applying": True, "phase": "applying"},
{"planet1": "Sun", "planet2": "Mercury", "type": "conjunction", "aspect_degree": 0,
"actual_diff": 4.0, "orb": 4.0, "applying": False, "phase": "separating"},
{"planet1": "Mars", "planet2": "Venus", "type": "Mars_aspect_8", "aspect_degree": 210,
"actual_diff": 211.0, "orb": 1.0, "applying": None, "phase": "unknown_without_velocity"},
{"planet1": "Sun", "planet2": "Moon", "type": "some_new_kind", "aspect_degree": 45,
"actual_diff": 45.5, "orb": 0.5},
]
def test_aspect_table_headers_orb_and_types() -> None:
packet = _advanced(aspects={"aspects": ASPECTS})
en = _table(pc._aspects(packet, "en"))
zh = _table(pc._aspects(packet, "zh"))
assert en[0] == ["Planet", "Aspected planet", "Aspect", "Aspect angle (°)", "Separation (°)", "Orb (°)", "Applying or separating"]
assert zh[0] == ["行星", "被照行星", "相位", "相位角度(度)", "实际角距(度)", "偏差(度)", "入相或离相"]
# 原值: Rahu–Ketu printed as "7th aspect (opposition)" / 「第 7 相位(对冲)」, orb 0, "Exact" / 「正好成相」
# 新值: the 180 stays in the separation column; the pair is not classed or timed as an aspect
# 原因: BUG-2109, the nodes are always 180° apart (astrologer B1: keep the geometry, not as aspect evidence)
assert en[1] == ["Rahu", "Ketu", "Always 180° apart; not read as an aspect", "—", "180", "—", "—"]
assert zh[1] == ["罗睺", "计都", "恒相距 180°,不作相位", "—", "180", "—", "—"]
assert en[2] == ["Saturn", "Moon", "Saturn's 3rd aspect", "60", "62.5", "2.5", "Applying"]
assert zh[2] == ["土星", "月亮", "土星第 3 相位", "60", "62.5", "2.5", "入相位"]
assert en[3][2:] == ["Conjunction", "0", "4", "4", "Separating"]
assert zh[3][2:] == ["合相", "0", "4", "4", "离相位"]
assert en[4][2] == "Mars's 8th aspect" and zh[4][2] == "火星第 8 相位"
assert en[4][6] == "Not determined" and zh[4][6] == "未判定"
# An unknown engine type keeps its raw value.
assert en[5][2] == "some_new_kind" and zh[5][2] == "some_new_kind"
for text in (pc._aspects(packet, "en"), pc._aspects(packet, "zh")):
assert "Orb days" not in text and "容许天数" not in text
def test_every_engine_aspect_type_has_reader_text() -> None:
from scripts.aspects import SPECIAL_ASPECTS
kinds = ["conjunction", "opposition"] + [
f"{planet}_aspect_{number}" for planet, numbers in SPECIAL_ASPECTS.items() for number in numbers if number != 7
]
for kind in kinds:
for language in ("en", "zh"):
text = pc._aspect_type_text(kind, language)
assert "_" not in text and text not in ("Not determined", "未判定"), (kind, language, text)
def test_dasha_sandhi_keeps_the_days_label() -> None:
assert pc.lab("orb", "en") == "Orb days" and pc.lab("orb", "zh") == "容许天数"
# 2. Ayana intermediate angle ---------------------------------------------
def test_ayana_angle_is_not_called_declination() -> None:
packet = {
"core_chart": {"planets": {"Sun": {"speed": 1.01}}},
"strengths_and_scores": {"shadbala": {"planets": {"Sun": {"kala_bala": {"declination": -12.5}}}}},
}
en, zh = _table(pc._coordinates(packet, "en")), _table(pc._coordinates(packet, "zh"))
# 原值: 三列 ["Planet", "Ayana intermediate angle", "Speed"] / ["行星", "Ayana 中间角", "速度"]
# 新值: 多一列真实的赤道赤纬,三个数值列的表头都带单位;这个合成包没有出生儒略日,赤纬一格写「未算出」
# 原因: BUG-2088,占星师 2026-11-20 B2:Ayana 中间角与赤纬分两列,各带定义、单位和来源
assert en == [["Planet", "Equatorial declination (°, north positive)", "Ayana intermediate angle (°)", "Speed (°/day)"],
["Sun", "Not calculated", "-12.5", "1.01"]]
assert zh == [["行星", "赤道赤纬(度,北为正)", "Ayana 中间角(度)", "速度(度/日)"], ["太阳", "未算出", "-12.5", "1.01"]]
# 3. D30 source input -----------------------------------------------------
def test_d30_source_prints_the_d1_degree() -> None:
packet = {
"core_chart": {"planets": {
"Sun": {"sign": "Aries", "degree_in_sign": 11.25},
"Rahu": {"sign": "Leo", "degree_in_sign": 2.5},
}},
"strengths_and_scores": {"shadbala": {"planets": {"Sun": {"sthana_bala": {"sapta_d30": 15}}}}},
"divisional_and_special_charts": {"varga_full": {"D30_Trimsamsa": {
"Sun": {"sign": "Sagittarius"}, "Rahu": {"sign": "Taurus"},
}}},
}
en, zh = _table(pc._d30(packet, "en", True)), _table(pc._d30(packet, "zh", True))
assert en == [
["Planet", "D1 sign", "D1 degree in sign", "Saptavargaja D30 (virupa)"],
["Sun", "Aries", "11.25", "15"],
["Rahu", "Leo", "2.5", "—"],
]
assert zh[0] == ["行星", "D1 星座", "D1 座内度数", "Saptavargaja D30(virupa)"]
assert zh[1] == ["太阳", "白羊座", "11.25", "15"]
assert zh[2] == ["罗睺", "狮子座", "2.5", "—"]
# 4. Pushkara -------------------------------------------------------------
def test_pushkara_headers_and_engine_detail() -> None:
packet = {"strengths_and_scores": {"pushkara": {
"Sun": {"degree_in_sign": 21.5, "pushkara_navamsa": True,
"pushkara_navamsa_meta": {"element": "fire", "range": [20.0, 23.3333]},
"pushkara_bhaga": True,
"pushkara_bhaga_meta": {"element": "fire", "target_degree": 21, "orb": 1.0, "delta": 0.5}},
"Moon": {"degree_in_sign": 2.0, "pushkara_navamsa": False, "pushkara_navamsa_meta": None,
"pushkara_bhaga": False,
"pushkara_bhaga_meta": {"element": "air", "target_degree": 24, "orb": 1.0, "delta": 22.0}},
}}}
en, zh = _table(pc._pushkara(packet, "en")), _table(pc._pushkara(packet, "zh"))
assert en[0] == ["Planet", "Degree in sign", "Pushkara Navamsa", "Pushkara Navamsa range (° in sign)",
"Pushkara Bhaga", "Pushkara Bhaga degree (°)", "Allowed orb (°)", "Distance from Bhaga degree (°)"]
assert zh[0] == ["行星", "落座度数", "Pushkara Navamsa", "Pushkara Navamsa 范围(座内度数)",
"Pushkara Bhaga", "Pushkara Bhaga 度数(度)", "容许偏差(度)", "与 Bhaga 度数的差(度)"]
assert en[1] == ["Sun", "21.5", "Yes", "20–23.3333", "Yes", "21", "1", "0.5"]
assert en[2] == ["Moon", "2", "No", "—", "No", "24", "1", "22"]
assert zh[1] == ["太阳", "21.5", "是", "20–23.3333", "是", "21", "1", "0.5"]
assert zh[2] == ["月亮", "2", "否", "—", "否", "24", "1", "22"]
# 5. A10 ------------------------------------------------------------------
def test_special_points_include_a10() -> None:
packet = {"divisional_and_special_charts": {"special_lagnas": {
"Arudha_Lagna": {"sign": "Gemini"},
"Upapada_Lagna": {"sign": "Libra"},
"A10_Karma_Pada": {"sign": "Virgo", "degree": None},
"Hora_Lagna": {"sign": "Aries"},
}}}
en, zh = _table(pc._special_points(packet, "en")), _table(pc._special_points(packet, "zh"))
assert ["A10 (Karma Pada)", "Virgo"] in en
assert ["A10(Karma Pada)", "处女座"] in zh
assert len(en) == 4 and len(zh) == 4
# 6. Graha Pada -----------------------------------------------------------
def test_graha_pada_names_each_column() -> None:
packet = _advanced(jaimini={"graha_padas": {"graha_padas": {"Moon": {
"planet_sign": "Aquarius", "lord": "Saturn", "lord_sign": "Sagittarius",
"graha_pada_sign": "Libra", "graha_pada_sign_idx": 6, "distance": 11,
}}}})
en, zh = _table(pc._graha_pada(packet, "en")), _table(pc._graha_pada(packet, "zh"))
assert en == [
["Planet", "Planet's sign", "Lord of that sign", "Lord's sign", "Count from planet's sign to lord's sign", "Graha Pada sign"],
["Moon", "Aquarius", "Saturn", "Sagittarius", "11", "Libra"],
]
assert zh == [
["行星", "行星所在星座", "该星座主星", "主星所在星座", "从行星星座数到主星星座", "Graha Pada 星座"],
["月亮", "水瓶座", "土星", "射手座", "11", "天秤座"],
]
# 7. Argala three-state ---------------------------------------------------
def test_argala_detail_cell_is_three_state() -> None:
from scripts.argala import _pair_status
assert _pair_status(["Sun"], ["Moon"]) == "strength_comparison_required"
def entry(house: int, blocked_by: int, effective):
return {"house_from_reference": house, "planets": ["Sun"], "blocked_by_house": blocked_by,
"blockers": ["Moon"], "effective": effective}
houses = {"house_1": {"primary": {"H2": entry(2, 12, True), "H4": entry(4, 10, False), "H11": entry(11, 3, None)}}}
en, zh = _table(pc._argala_detail(houses, "en")), _table(pc._argala_detail(houses, "zh"))
assert en[0][-1] == "Effective" and zh[0][-1] == "成立"
assert [row[-1] for row in en[1:]] == ["Yes", "No", "Undecided (equal count)"]
assert [row[-1] for row in zh[1:]] == ["是", "否", "同数未决"]
# 8. Gana -----------------------------------------------------------------
def test_gana_accepts_the_bracketed_engine_spelling() -> None:
from scripts.nakshatra_advanced import NAK_GANA
assert {"Dev(神圣)", "Manushya(人类)", "Rakshasa(罗刹)"} <= set(NAK_GANA.values())
natal = {
"Sun": {"nakshatra": "Ashwini", "pada": 1, "nakshatra_lord": "Ketu", "gana": "Dev(神圣)"},
"Moon": {"nakshatra": "Bharani", "pada": 1, "nakshatra_lord": "Venus", "gana": "Manushya(人类)"},
"Mars": {"nakshatra": "Krittika", "pada": 1, "nakshatra_lord": "Sun", "gana": "Rakshasa(罗刹)"},
"Mercury": {"nakshatra": "Rohini", "pada": 1, "nakshatra_lord": "Moon", "gana": "Dev"},
}
packet = _advanced(nakshatra_adv={"natal_nakshatras": natal})
en, zh = _table(pc._nakshatra_reference(packet, "en")), _table(pc._nakshatra_reference(packet, "zh"))
column = en[0].index("Gana")
assert [row[column] for row in en[1:]] == ["Deva", "Manushya", "Rakshasa", "Deva"]
assert [row[column] for row in zh[1:]] == ["天神", "人", "罗刹", "天神"]
# 9. Darakaraka and annual contract headers -------------------------------
def test_darakaraka_d9_sign_has_its_own_header() -> None:
packet = _advanced(jaimini={"darakaraka": {
"dk_planet": "Mercury", "dk_sign": "Capricorn", "dk_house": 11, "dk_degree": 3.5, "d9_sign": "Aquarius",
}})
en, zh = _table(pc._one_point(packet, "en", "darakaraka")), _table(pc._one_point(packet, "zh", "darakaraka"))
assert en == [["Planet", "Sign", "House", "Degree in sign", "D9 sign"], ["Mercury", "Capricorn", "11", "3.5", "Aquarius"]]
assert zh == [["行星", "星座", "宫位", "落座度数", "九分盘星座"], ["水星", "摩羯座", "11", "3.5", "水瓶座"]]
def test_annual_contract_headers_say_what_the_cells_are() -> None:
pack = {
"solar_return": {"data": {"dt_local": "2031-03-04 05:06:07"}},
"annual_chart": {"data": {"asc_sign": "Leo"}},
"muntha": {"data": {"muntha_sign": "Taurus"}},
"year_lord": {"data": {"year_lord": "Venus"}},
}
en, zh = _table(pc._annual_contract(pack, "en")), _table(pc._annual_contract(pack, "zh"))
assert en[:2] == [
["Solar return time (local)", "Annual Lagna sign", "Muntha sign", "Year lord"],
["2031-03-04 05:06:07", "Leo", "Taurus", "Venus"],
]
assert zh[:2] == [
["太阳回归时刻(当地时间)", "年盘上升星座", "Muntha 星座", "年主"],
["2031-03-04 05:06:07", "狮子座", "金牛座", "金星"],
]
# 10. Rashi Tulya Navamsa -------------------------------------------------
def test_rashi_tulya_header_says_other_occupants() -> None:
packet = _advanced(rashi_tulya_navamsa={"analysis": {"lagna_sign": "Aries", "planets": [
{"planet": "Sun", "d9_sign": "Leo", "d1_house": 5, "dignity_d1": "own", "d1_conjunctions": ["Moon"]},
]}})
en, zh = pc._rashi_tulya(packet, "en"), pc._rashi_tulya(packet, "zh")
assert _table(en)[0][-1] == "Other natal occupants there"
assert _table(zh)[0][-1] == "该处其他本命行星"
# 11. Natal calculation conventions ---------------------------------------
def test_settings_show_three_named_columns_without_a_profile() -> None:
packet = {"birth_info": {"ayanamsa_display": "Raman", "node_mode": "mean"}}
assert _table(pc._settings(packet, "en")) == [["Ayanamsa", "Node mode", "House system"], ["Raman", "Mean node", "Whole sign"]]
assert _table(pc._settings(packet, "zh")) == [["岁差", "交点口径", "宫位制"], ["Raman", "平交点", "整宫制"]]
def test_settings_add_only_what_the_profile_carries() -> None:
packet = {
"birth_info": {"ayanamsa_name": "lahiri", "node_mode": "true"},
"calculation_profile": {"house_system": "whole_sign", "effective_settings": {
"ayanamsa": "lahiri", "node_mode": "true", "position_mode": "apparent", "house_system": "whole_sign",
"dasha_year_days": 365.25, "timezone_offset": "+02:00",
}},
}
assert _table(pc._settings(packet, "en")) == [
["Ayanamsa", "Node mode", "House system", "Position mode", "Dasha year length (days)", "UTC offset"],
["Lahiri", "True node", "Whole sign", "Apparent positions", "365.25", "+02:00"],
]
assert _table(pc._settings(packet, "zh")) == [
["岁差", "交点口径", "宫位制", "行星位置口径", "大运一年的天数", "时区(UTC 偏移)"],
["Lahiri", "真交点", "整宫制", "视位置", "365.25", "+02:00"],
]
# 12. Shayanadi method ----------------------------------------------------
def test_shayanadi_method_has_reader_text() -> None:
entry = {"method_status": "pvr_15_4_4_running_ghati"}
# 原值: "PVR 15.4.4, running ghati" /「PVR 15.4.4,按出生后的 ghati」
# 新值: 不写书的节号
# 原因: BUG-2129 负责人 2026-11-21:报告里不给读者出现书名、作者出处、页码和章节号
assert pc._avastha_method(entry, "en") == "Running ghati"
assert pc._avastha_method(entry, "zh") == "按出生后的 ghati"
assert pc._avastha_method({"method_status": "simplified_heuristic"}, "en") == "Simplified rule"
# 13. Saham formula operators ---------------------------------------------
def _evaluate(rule: str, longitudes: dict[str, float]) -> float:
total, sign = 0.0, 1.0
for token in rule.split():
if token in "+-":
sign = 1.0 if token == "+" else -1.0
else:
total += sign * (float(token.rstrip("°")) if token.endswith("°") else longitudes[token])
return total % 360
@pytest.mark.parametrize("ascendant, plus_thirty", [(50.0, False), (200.0, True)])
def test_saham_rule_text_evaluates_to_the_printed_longitude(ascendant: float, plus_thirty: bool) -> None:
longitudes = {"Sun": 10.0, "Moon": 100.0}
trace = tajika._formula_saham_trace("Punya_Saham", longitudes, ascendant, True, {})
assert trace["formula_operands"] == ["Moon", "Sun", "Ascendant"]
assert trace["zodiacal_order_exception_applied"] is plus_thirty
results = {"punya_saham": {"name": "Punya Saham", "longitude": trace["longitude"]}}
meta = {key: trace[key] for key in ("rule_name", "formula_operands", "formula_variant", "zodiacal_order_exception_applied")}
row = attach_formula_traces(results, is_day=True, formula_meta={"punya_saham": meta})[0]
assert row["rule"] == "Moon - Sun + Ascendant" + (" + 30°" if plus_thirty else "")
printed = _evaluate(row["rule"], {**longitudes, "Ascendant": ascendant})
assert printed == pytest.approx(row["longitude"] % 360)
# The old text read as a sum, which gives a different point.
assert (longitudes["Moon"] + longitudes["Sun"] + ascendant) % 360 != pytest.approx(row["longitude"] % 360)
for language in ("en", "zh"):
table = _table(pc._trace_table([row], language))
assert table[1][1] == row["rule"]