90 lines
3.3 KiB
Python
90 lines
3.3 KiB
Python
"""Degraded calculations leave a warning that names the function, not the chart."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SCRIPTS = ROOT / "scripts"
|
|
if str(SCRIPTS) not in sys.path:
|
|
sys.path.insert(0, str(SCRIPTS))
|
|
|
|
import daily_guidance_service # noqa: E402
|
|
import jyotish_engine # noqa: E402
|
|
import pl9_full_data_export # noqa: E402
|
|
|
|
_SENTINEL_DATE = "1990-01-01"
|
|
_SENTINEL_LAT = "28.6139"
|
|
_SENTINEL_LON = "77.2090"
|
|
|
|
|
|
def _warnings(caplog):
|
|
return [record.getMessage() for record in caplog.records if record.levelno >= logging.WARNING]
|
|
|
|
|
|
def test_sudarshana_failure_logs_the_function_not_the_chart(monkeypatch, caplog) -> None:
|
|
def boom(*_args, **_kwargs):
|
|
raise RuntimeError(f"{_SENTINEL_DATE} {_SENTINEL_LAT} {_SENTINEL_LON}")
|
|
|
|
monkeypatch.setattr(pl9_full_data_export, "_load_sudarshana", lambda: boom)
|
|
packet = {
|
|
"core_chart": {
|
|
"ascendant": {"longitude": 10.0, "sign": "Aries"},
|
|
"planets": {"Sun": {"longitude": 20.0, "sign": "Aries"}},
|
|
}
|
|
}
|
|
with caplog.at_level(logging.WARNING):
|
|
text = pl9_full_data_export._render_pl9_ai_density_raw_data_markdown_en(packet)
|
|
assert "Sudarshana" not in text
|
|
warnings = _warnings(caplog)
|
|
assert any(
|
|
"pl9_full_data_export._render_pl9_ai_density_raw_data_markdown_en degraded: RuntimeError" == item
|
|
for item in warnings
|
|
)
|
|
assert all(_SENTINEL_DATE not in item and _SENTINEL_LAT not in item and _SENTINEL_LON not in item for item in warnings)
|
|
|
|
|
|
def test_current_mahadasha_failure_logs_the_function_not_the_chart(monkeypatch, caplog) -> None:
|
|
def boom(**_kwargs):
|
|
raise ValueError(f"{_SENTINEL_DATE} {_SENTINEL_LAT}")
|
|
|
|
monkeypatch.setattr(daily_guidance_service, "compute_vimshottari_timeline", boom)
|
|
with caplog.at_level(logging.WARNING):
|
|
result = daily_guidance_service._current_mahadasha(
|
|
{"birth_info": {}, "planets": {"Moon": {"lon": 10.0}}},
|
|
{"year": 1990, "month": 1, "day": 1, "hour": 12, "minute": 0},
|
|
"2026-01-01",
|
|
)
|
|
assert result is None
|
|
warnings = _warnings(caplog)
|
|
assert any(
|
|
"daily_guidance_service._current_mahadasha degraded: ValueError" == item
|
|
for item in warnings
|
|
)
|
|
assert all(_SENTINEL_DATE not in item and _SENTINEL_LAT not in item for item in warnings)
|
|
|
|
|
|
def test_conflict_arbitration_failure_logs_the_function_not_the_chart(monkeypatch, caplog) -> None:
|
|
import ashtakavarga
|
|
|
|
def boom(*_args, **_kwargs):
|
|
raise RuntimeError(f"{_SENTINEL_DATE} {_SENTINEL_LON}")
|
|
|
|
monkeypatch.setattr(ashtakavarga, "calc_ashtakavarga", boom)
|
|
report = {
|
|
"planets": {},
|
|
"audit": {"P1_identity": {"asc_sign": "Aries"}},
|
|
"ashtakavarga": {"present": True},
|
|
}
|
|
with caplog.at_level(logging.WARNING):
|
|
conflicts = jyotish_engine._conflict_arbitration(report)
|
|
assert isinstance(conflicts, list)
|
|
warnings = _warnings(caplog)
|
|
assert any(
|
|
"jyotish_engine._conflict_arbitration degraded: RuntimeError" == item
|
|
for item in warnings
|
|
)
|
|
assert all(_SENTINEL_DATE not in item and _SENTINEL_LON not in item for item in warnings)
|