Files
Jyotisha/tests/test_dasha_year_length_alignment.py
T
jesse-uxandGrok (agent loop) 5ac88e58f5 让大运接口走完整解读的同一套算法,不再返回编出来的周期。
Ashtottari 在适用时把出生前已经走过的部分算进时间线。

Co-Authored-By: Grok (agent loop)
2026-10-16 00:52:29 +08:00

54 lines
2.0 KiB
Python

"""BUG-1321: the API fallback dasha year matches dasha_analyzer's 365.25 days.
Upstream 4d543209. The two 365.25636 constants in the API server made the
fallback timeline and the years-into-mahadasha figure drift from the analyzer.
"""
from __future__ import annotations
import importlib.util
import os
import sys
from datetime import datetime
SCRIPTS = os.path.join(os.path.dirname(__file__), "..", "scripts")
if SCRIPTS not in sys.path:
sys.path.insert(0, SCRIPTS)
def _api_handler():
"""Reuse the existing unbound handler helper. Do not add another forgery site."""
path = os.path.join(os.path.dirname(__file__), "test_api_server_security.py")
spec = importlib.util.spec_from_file_location("_api_security_helpers_dasha", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module._handler()
def test_placeholder_fallback_periods_are_gone() -> None:
"""原值:_fallback_dasha_periods 用 365.25 日对齐分析器。
新值:该方法不存在。
原因:占位回退会编造周期,BUG-1341 要求删掉;仍在用的年长对齐由下一条 years_into 测试锁住。
"""
handler = _api_handler()
assert not hasattr(handler, "_fallback_dasha_periods")
source = open(
os.path.join(os.path.dirname(__file__), "..", "scripts", "jyotish_api_server.py"),
encoding="utf-8",
).read()
assert "_fallback_dasha_periods" not in source
assert "precision = 'generic'" not in source
assert "precision = 'calculator'" not in source
def test_years_into_mahadasha_uses_the_analyzer_year() -> None:
birth = datetime(2000, 1, 1)
today = datetime(2003, 1, 1)
handler = _api_handler()
layer = handler._compute_vimshottari_analysis_layer(birth, 0.0, current_date="2003-01-01")
days = (today - birth).days
years_into = layer["five_levels"]["mahadasha"]["years_into_period"]
assert years_into == days / 365.25
assert years_into != days / 365.25636