Spaces:
Running
Running
Download test_vedic_chart.py from sisithefox/sisi-astrology-api: direct link, hf CLI and curl.
- Browser
- Download file 2.2 kB
-
https://huggingface.co/spaces/sisithefox/sisi-astrology-api/resolve/main/test_vedic_chart.py
- Command line
-
hf download hf://spaces/sisithefox/sisi-astrology-api/test_vedic_chart.py
-
curl -L -o test_vedic_chart.py https://huggingface.co/spaces/sisithefox/sisi-astrology-api/resolve/main/test_vedic_chart.py
2.2 kB
| """ | |
| 印度占星端点测试 — 计算层 + 端点层 | |
| 跑法: <spike-venv>/bin/python test_vedic_chart.py | |
| 固定输入: 1990-01-01 12:00, New Delhi (28.6139, 77.2090), Asia/Kolkata | |
| 基准值来自 Task 0 spike 验证 + 与 kerykeion 交叉一致。 | |
| """ | |
| import sys, os, io | |
| VEDIC = os.path.join(os.path.dirname(os.path.abspath(__file__)), "vedic") | |
| sys.path.insert(0, VEDIC) | |
| FIXED = dict(year=1990, month=1, day=1, hour=12, minute=0, | |
| lat=28.6139, lon=77.2090, tz_str="Asia/Kolkata") | |
| def _calc(): | |
| _real = sys.stdout | |
| sys.stdout = io.StringIO() # 静音 PyJHora noisy import/print | |
| try: | |
| from engine import calculate_full_chart | |
| return calculate_full_chart(**FIXED) | |
| finally: | |
| sys.stdout = _real | |
| def test_lagna_correct(): | |
| c = _calc() | |
| assert c["lagna"]["sign"] == "Pisces", c["lagna"]["sign"] | |
| assert c["lagna"]["nakshatra"]["name"] == "Uttara Bhadrapada", c["lagna"]["nakshatra"] | |
| print(" ✓ test_lagna_correct") | |
| def test_all_sections_present(): | |
| c = _calc() | |
| for k in ["ayanamsa", "lagna", "planets", "dashas", "shadbala", "d9", "karakas", "aspects"]: | |
| assert k in c, f"missing section: {k}" | |
| for g in ["Sun", "Moon", "Mars", "Mercury", "Jupiter", "Venus", "Saturn", "Rahu", "Ketu"]: | |
| assert g in c["planets"], f"missing graha: {g}" | |
| print(" ✓ test_all_sections_present") | |
| def test_dasha_has_periods(): | |
| c = _calc() | |
| assert c["dashas"], "dashas empty" | |
| print(f" ✓ test_dasha_has_periods ({len(c['dashas'])} periods)") | |
| def test_json_serializable(): | |
| """端点核心: 整盘能用端点的 default lambda 安全序列化成 JSON (numpy/tuple 不炸)""" | |
| import json | |
| c = _calc() | |
| s = json.dumps(c, default=lambda o: float(o) if hasattr(o, "__float__") else str(o)) | |
| back = json.loads(s) | |
| assert back["lagna"]["sign"] == "Pisces" | |
| assert "shadbala" in back and "dashas" in back | |
| print(f" ✓ test_json_serializable ({len(s)} bytes)") | |
| if __name__ == "__main__": | |
| print("=== Vedic calc-layer tests ===") | |
| test_lagna_correct() | |
| test_all_sections_present() | |
| test_dasha_has_periods() | |
| test_json_serializable() | |
| print("✅ ALL CALC-LAYER TESTS PASS") | |