Annual clock captions no longer end with "this report's native calculation"; the general dasha reference drops its per-lord study-notes citation; the birth data section translates user_reported / family_exact and the other stored codes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
215 lines
11 KiB
Python
215 lines
11 KiB
Python
"""BUG-2077: annual timing tables keep the full period and the in-year interval apart.
|
|
|
|
Astrologer ruling 2026-11-20, question 14: the year starts at the actual solar return; a
|
|
running period's full start (back-computed from the Moon balance) may precede it; the
|
|
in-year interval is the intersection of the full period with the year; a period with an
|
|
empty intersection is extension material only. Every table names its own clock.
|
|
|
|
Synthetic inputs, plus the repository's public chart fixtures for the rendered report.
|
|
"""
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
import pytest
|
|
|
|
from scripts.pl9_reader_export import (
|
|
_annual_clock_caption,
|
|
in_year_clock_caption,
|
|
patyayini_clock_caption,
|
|
)
|
|
from scripts.report_render.annual_method_reference import render_annual_method_reference
|
|
from scripts.tajika_mudda import annual_mudda_dasha, year_rows
|
|
from tests.public_chart_reports import PUBLIC_REPORT_CASES, public_chart_reports
|
|
|
|
RETURN = datetime(2031, 5, 3, 9, 20, 0)
|
|
NEXT_RETURN = RETURN + timedelta(days=365, hours=6, minutes=11)
|
|
SPAN = 360.0 / 27.0
|
|
|
|
|
|
def _mudda(moon: float, *, next_return: datetime | None = NEXT_RETURN) -> dict:
|
|
return annual_mudda_dasha(
|
|
annual_start=RETURN,
|
|
completed_years=40,
|
|
natal_moon_longitude=moon,
|
|
coverage_end=next_return,
|
|
)
|
|
|
|
|
|
def _at(value: str) -> datetime:
|
|
return datetime.fromisoformat(value)
|
|
|
|
|
|
def test_first_full_period_precedes_the_return_and_the_in_year_start_is_the_return() -> None:
|
|
rows = [row for row in year_rows(_mudda(5 * SPAN + 8.0)) if row["level"] == "main"]
|
|
first = rows[0]
|
|
assert _at(first["full_start"]) < RETURN
|
|
assert _at(first["in_year_start"]) == RETURN
|
|
assert first["in_year"] is True
|
|
# Later rows start inside the year: both starts agree.
|
|
assert rows[1]["full_start"] == rows[1]["in_year_start"]
|
|
|
|
|
|
def test_last_period_past_the_year_end_is_cut_at_the_year_boundary() -> None:
|
|
rows = [row for row in year_rows(_mudda(5 * SPAN + 8.0)) if row["level"] == "main"]
|
|
last = [row for row in rows if row["in_year"]][-1]
|
|
assert _at(last["full_end"]) > NEXT_RETURN
|
|
assert _at(last["in_year_end"]) == NEXT_RETURN
|
|
for row in rows:
|
|
if row["in_year"]:
|
|
assert RETURN <= _at(row["in_year_start"]) < _at(row["in_year_end"]) <= NEXT_RETURN
|
|
|
|
|
|
def test_rows_with_no_part_inside_the_year_are_flagged_and_carry_no_in_year_dates() -> None:
|
|
subs = [row for row in year_rows(_mudda(5 * SPAN + 8.0)) if row["level"] == "sub"]
|
|
outside = [row for row in subs if not row["in_year"]]
|
|
assert outside
|
|
for row in outside:
|
|
assert row["in_year_start"] is None and row["in_year_end"] is None
|
|
assert _at(row["full_start"]) >= NEXT_RETURN
|
|
# Sub-period full starts chain without a gap inside one main period.
|
|
by_main: dict[int, list[dict]] = {}
|
|
for row in subs:
|
|
by_main.setdefault(row["main_order"], []).append(row)
|
|
for group in by_main.values():
|
|
for earlier, later in zip(group, group[1:]):
|
|
assert earlier["full_end"] == later["full_start"]
|
|
|
|
|
|
def test_zero_elapsed_balance_starts_on_the_return_and_the_tenth_group_is_outside_the_projected_year() -> None:
|
|
# The Moon exactly on a nakshatra start: nothing elapsed, the full start is the return.
|
|
mudda = _mudda(5 * SPAN, next_return=None)
|
|
mains = [row for row in year_rows(mudda) if row["level"] == "main"]
|
|
assert _at(mains[0]["full_start"]) == RETURN == _at(mains[0]["in_year_start"])
|
|
# No next return known: the year ends at the projected 365.25-day end, where the tenth
|
|
# group begins. Its intersection with the year is empty.
|
|
assert mudda["coverage_interval"]["basis"] == "nominal_year_fallback_next_return_unknown"
|
|
assert mains[-1]["in_year"] is False
|
|
assert [row["in_year"] for row in mains[:-1]] == [True] * 9
|
|
|
|
|
|
def _annual(offset: str, *, next_return: datetime | None = NEXT_RETURN) -> dict:
|
|
local = RETURN.isoformat() + offset
|
|
return {
|
|
"mudda_dasha": {"status": "partial_verified", "data": _mudda(5 * SPAN + 8.0, next_return=next_return)},
|
|
"annual_interval": {"solar_return_interval": {"start": {"local": local}}},
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize("offset", ("+05:30", "-08:00"))
|
|
def test_native_caption_names_anchor_zone_balance_year_length_both_year_ends_and_source(offset: str) -> None:
|
|
annual = _annual(offset)
|
|
chinese = _annual_clock_caption(annual, "zh")[0]
|
|
english = _annual_clock_caption(annual, "en")[0]
|
|
projected = (RETURN + timedelta(days=365.25)).isoformat(timespec="seconds")
|
|
for text in (chinese, english):
|
|
assert RETURN.isoformat(timespec="seconds") in text
|
|
assert f"UTC{offset}" in text
|
|
assert "365.25" in text
|
|
assert NEXT_RETURN.isoformat(timespec="seconds") in text and projected in text
|
|
assert "真实太阳回归时刻" in chinese and "出生时月亮" in chinese and "不是同一时刻" in chinese
|
|
# 原值:assert chinese.endswith("来源:本报告的原生计算。")
|
|
# 新值:不写「来源」
|
|
# 原因:BUG-2115 负责人 2026-11-21:报告里不给读者出现「来源」行
|
|
assert "来源" not in chinese
|
|
assert "actual solar return" in english and "Moon at birth" in english and "different moments" in english
|
|
assert "Source:" not in english
|
|
assert in_year_clock_caption(annual, "zh")[0].startswith("下表日期是 Mudda 各段的年内区间。")
|
|
assert in_year_clock_caption(annual, "en")[0].startswith("Dates below are in-year intervals")
|
|
|
|
|
|
def test_caption_says_so_when_the_next_return_is_unknown_and_stays_silent_without_a_clock() -> None:
|
|
chinese = _annual_clock_caption(_annual("+00:00", next_return=None), "zh")[0]
|
|
english = _annual_clock_caption(_annual("+00:00", next_return=None), "en")[0]
|
|
assert "下一次真实太阳回归时刻没有取得" in chinese
|
|
assert "was not obtained" in english
|
|
assert _annual_clock_caption({}, "zh") == [] and _annual_clock_caption({}, "en") == []
|
|
|
|
|
|
def test_patyayini_caption_only_on_the_native_table_and_separates_the_projected_end() -> None:
|
|
annual = _annual("+08:00")
|
|
last_end = RETURN + timedelta(days=365.25)
|
|
native = [
|
|
{"start": RETURN.isoformat(sep=" "), "end": "2031-08-01 00:00:00", "boundary": "2031-08-01 00:00:00"},
|
|
{"start": "2031-08-01 00:00:00", "end": last_end.isoformat(sep=" "), "boundary": last_end.isoformat(sep=" ")},
|
|
]
|
|
annual["native_patyayini"] = {"rows": native}
|
|
chinese = patyayini_clock_caption(annual, native, "zh")[0]
|
|
english = patyayini_clock_caption(annual, native, "en")[0]
|
|
assert "不计月亮余额" in chinese and "365.25" in chinese and "不是同一时刻" in chinese
|
|
assert "no Moon balance" in english and "365.25" in english and "different moments" in english
|
|
assert last_end.isoformat(timespec="seconds") in chinese and NEXT_RETURN.isoformat(timespec="seconds") in chinese
|
|
replayed = [{"boundary": "2031-07-30 00:00:00"}, {"boundary": "2032-05-02 00:00:00"}]
|
|
assert patyayini_clock_caption(annual, replayed, "zh") == []
|
|
|
|
|
|
def test_reference_tables_carry_their_own_clock_and_keep_their_numbers() -> None:
|
|
year = {
|
|
"requested_year": 2031,
|
|
"ayanamsa": "LAHIRI",
|
|
"ayanamsa_ok": True,
|
|
"node_header": "mean",
|
|
"patyayini_anchor": "2031-05-03 09:20:04",
|
|
"tajika_anchor": "2031-05-03 09:20:04",
|
|
"tables": {
|
|
"mudda_birth": {"ok": True, "rows": [
|
|
{"order": 1, "main_lord": "Jupiter", "sub_lord": "Jupiter", "start": "2031-04-11 10:00:00", "end": None, "duration": "6.49"},
|
|
]},
|
|
"mudda_annual": {"ok": False, "rows": []},
|
|
"patyayini": {"ok": False, "rows": []},
|
|
"tajika": {"ok": False, "rows": []},
|
|
},
|
|
}
|
|
packet = {"worksheets": {"timing_and_predictive_systems": {"pyjhora_annual_method_reference": {"years": [year]}}}}
|
|
chinese = render_annual_method_reference(packet, "zh")
|
|
english = render_annual_method_reference(packet, "en")
|
|
# 原值:时钟:PyJHora 的独立参照。回归锚点 …
|
|
# 新值:时钟:回归锚点 …(只留事实)
|
|
# 原因:BUG-2115 负责人 2026-11-21:报告里不给读者出现库名和「来源」行,这一章直接出数据
|
|
assert chinese.count("时钟:回归锚点 2031-05-03 09:20:04,岁差 LAHIRI,平交点。") == 3
|
|
assert "PyJHora" not in chinese and "PyJHora" not in english
|
|
assert "首段余额按出生时月亮。" in chinese and "首段余额按年盘月亮。" in chinese
|
|
assert "早于回归锚点的部分不在本年度内。" in chinese
|
|
assert english.count("Clock: return anchor 2031-05-03 09:20:04; ayanamsa LAHIRI; nodes mean.") == 3
|
|
assert "Any part before the return anchor is outside this year." in english
|
|
# The reference row is printed as returned: its pre-anchor start is not moved.
|
|
assert "| 1 | 木星 | 木星 | 2031-04-11 10:00:00 | 6.49 |" in chinese
|
|
assert "| 1 | Jupiter | Jupiter | 2031-04-11 10:00:00 | 6.49 |" in english
|
|
assert not any("一" <= char <= "鿿" for char in english)
|
|
|
|
|
|
@pytest.mark.parametrize("case", PUBLIC_REPORT_CASES)
|
|
def test_report_prints_full_and_in_year_columns_and_marks_rows_outside_the_year(case: str) -> None:
|
|
packet, chinese, english = public_chart_reports(case)
|
|
annual = packet["worksheets"]["timing_and_predictive_systems"]["annual_tajika_pack"]
|
|
mudda = annual["mudda_dasha"]["data"]
|
|
assert "| 余额口径 | 主星 | 完整周期起点 | 完整周期终点 | 年内起点 | 年内终点 | 边界口径 |" in chinese
|
|
assert "| Balance profile | Lord | Full period start | Full period end | In-year start | In-year end | Boundary |" in english
|
|
# One "start" column no longer serves both meanings.
|
|
assert "| 余额口径 | 主星 | 开始 | 结束 |" not in chinese
|
|
assert "| Balance profile | Lord | Start | End |" not in english
|
|
assert "| balance_profile | lord | start | end |" not in english
|
|
assert "| 余额口径 | 主星 | 年内起点 | 年内终点 | 边界状态 |" in chinese
|
|
assert "| Balance Profile | Lord | In-Year Start | In-Year End | Boundary Status |" in english
|
|
|
|
def shown(value: str) -> str:
|
|
return (_at(value) + timedelta(seconds=0.5)).isoformat(timespec="seconds")
|
|
|
|
rows = year_rows(mudda)
|
|
first = next(row for row in rows if row["level"] == "main")
|
|
assert _at(first["full_start"]) < _at(mudda["coverage_interval"]["start"])
|
|
cells = f"| {shown(first['full_start'])} | {shown(first['full_end'])} | {shown(first['in_year_start'])} | {shown(first['in_year_end'])} |"
|
|
assert cells in chinese and cells in english
|
|
outside = [row for row in rows if not row["in_year"]]
|
|
# Whether the year end falls inside the last sub-period depends on the chart; the
|
|
# second public chart has such rows, so the label is exercised on a real report.
|
|
assert outside or case != "barack_obama_1961_aa"
|
|
for row in outside:
|
|
tail = f"| {shown(row['full_start'])} | {shown(row['full_end'])} | "
|
|
assert tail + "不在本年度内 | 不在本年度内 | 只作延伸资料 |" in chinese
|
|
assert tail + "Outside this year | Outside this year | extension only |" in english
|
|
assert "时钟:年度起点是真实太阳回归时刻" in chinese
|
|
assert "Clock: the year starts at the actual solar return" in english
|
|
assert "| 阶段 | 主星 | 年盘宫位 | 年内区间 | 主题 |" in chinese
|
|
assert "| 序号 | 主星 | 月数 | 年内起点 | 年内终点 |" in chinese
|
|
assert "| Index | Lord | Months | In-year start | In-year end |" in english
|