fix(avastha): mark Shayanadi blocked when there is no sunrise instead of dropping the table

Polar day or night left determine_daytime without a sunrise, so the whole
avasthas module failed after the PVR activity formula was wired in. Only
the Shayanadi cell is blocked now; the other four states still compute
(BUG-1390).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HwMNZEzdzmrbPhuRNmZe3C
This commit is contained in:
Jesse_Chen
2026-10-18 18:46:02 +08:00
co-authored by Claude Opus 5.5
parent 84967d747f
commit 982c53dd17
3 changed files with 51 additions and 11 deletions
+26
View File
@@ -37,3 +37,29 @@ def test_full_reading_wires_hindu_sunrise_into_activity_formula(monkeypatch):
assert actual['method_status'] == 'pvr_15_4_4_running_ghati'
assert actual['components']['running_ghati'] == 43
assert actual['state_index'] == 10
def test_polar_birth_without_sunrise_keeps_other_avasthas(monkeypatch):
# BUG-1390:北极圈夏至没有日出。原来整个 avasthas 模块报错消失;现在只有姿态一项标无法计算。
repo = Path(__file__).resolve().parents[1]
monkeypatch.syspath_prepend(str(repo / 'scripts'))
tree = ast.parse((repo / 'scripts/jyotish_engine.py').read_text(encoding='utf-8'))
blocks = [node for node in ast.walk(tree) if isinstance(node, ast.Try)
and any(isinstance(item, ast.ImportFrom) and item.module == 'avastha_calculator'
for item in node.body)]
report = {'modules': {}, 'errors': []}
env = dict(
report=report,
args=SimpleNamespace(lat=69.65, lon=18.96, tz=2),
asc_deg=0,
planet_lons={'Sun': 90, 'Moon': 0},
planets={'Sun': {'degree': 90, 'degree_raw': 90, 'sign': 'Cancer', 'house': 4}},
_birth_datetime_from_args=lambda args: datetime(1990, 6, 21, 12, 0),
)
exec(compile(ast.Module(body=blocks, type_ignores=[]), '<avastha-polar>', 'exec'), env)
assert report['errors'] == []
sun = report['modules']['avasthas']['Sun']
assert sun['avasthas']['Shayanadi']['state'] is None
assert sun['avasthas']['Shayanadi']['method_status'] == 'blocked'
assert sun['avasthas']['Deeptadi']['state']
assert '无法计算' in sun['interpretation']