C1 compute_chart_data and transit use the bundled Swiss .se1 files (flag 258, was Moshier 260) and record chart.meta; ephemeris_events sets the path too. C2 full-reading yoga runs on the D1 lagna (upstream a387e999 d11_asc_idx). C3 Raj Yoga dual lord needs two houses; kl==tl skipped (upstream e628118d). C4 rule library: Mahabhagya / Parihasaka evaluators with condition_status, Satkalatra, Subha Kartari (Moon), Varga Yoga, Jananatpurvam (Raman 242), Chakra Yoga, Raja Yoga mutual aspect; lords_relation same-planet guard; nodes cast no aspect; unplaced planets fail all_in_houses / exactly_n_signs; and bindings keep both sides; Chakra/Vajra Nabhasa, Kalanidhi, Dala retired; duplicate algorithmic solar/lunar block removed. Astrologer rulings kept. C5 jaimini.special_lagnas = jaimini_special_lagna_view (upstream ab5b8709). C6 chara_karaka_standard (BPHS 8) replaces chara_karaka_jh (upstream 2f52cfca). C7 conditional dashas get dasha_year_days and as_of (full-reading and consult). CLI: --gender (yoga/full-reading/pl9-export), --dasha-year-days. 产品 2026-11-07 与占星师上游引擎同步。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
188 lines
9.1 KiB
Python
188 lines
9.1 KiB
Python
"""产品 2026-11-07 与占星师上游引擎同步(yinduzhanxing 5fb8379c 对照审计 C1-C7)。
|
|
|
|
Each test pins one upstream fix that our engine lacked:
|
|
C1 bundled Swiss ephemeris (flag 258), C2 full-reading yoga on the D1 lagna,
|
|
C3 Raj Yoga dual lord needs two houses, C4 rule-library fixes, C5 Jaimini
|
|
special lagnas from the computed birth points, C6 BPHS 8-karaka table,
|
|
C7 conditional dashas take the year length and the observation date.
|
|
Steve Jobs 1955-02-24 19:15 San Francisco (AA) is a public chart.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
JOBS = dict(year=1955, month=2, day=24, hour=19, minute=15, second=0,
|
|
lat=37.7749, lon=-122.4194, tz=-8.0)
|
|
|
|
|
|
def test_chart_uses_bundled_swiss_ephemeris_files():
|
|
from scripts.jyotish_engine import compute_chart_data
|
|
|
|
chart, *_ = compute_chart_data(1997, 8, 8, 5, 0, 36.61, 114.49, 8, ayanamsa_name="raman")
|
|
meta = chart["meta"]
|
|
assert meta["ephemeris_flags"] == 258 # FLG_SWIEPH | FLG_SPEED, not Moshier 260
|
|
assert meta["ephemeris_provider"] == "swisseph"
|
|
assert meta["ephemeris_flags_verified"] is True
|
|
assert meta["ephemeris_path"].startswith("references/open_source_sources/vedic-astro-skills/")
|
|
assert (ROOT / meta["ephemeris_path"] / "semo_18.se1").is_file()
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def jobs_reading():
|
|
from scripts.jyotish_engine import cmd_full_reading
|
|
from scripts.professional_report_reference import _export_args
|
|
|
|
return cmd_full_reading(_export_args({**JOBS, "ayanamsa": "raman", "node_mode": "mean",
|
|
"today": "2026-11-07"}))
|
|
|
|
|
|
def test_full_reading_yoga_runs_on_the_d1_lagna(jobs_reading):
|
|
yoga = jobs_reading["modules"]["yoga"]
|
|
assert yoga["ascendant"] == "Virgo"
|
|
assert yoga["kendra_lords"] == ["Jupiter", "Mercury"]
|
|
assert yoga["trikona_lords"] == ["Mercury", "Saturn", "Venus"]
|
|
|
|
|
|
def test_jaimini_special_lagnas_are_the_computed_birth_points(jobs_reading):
|
|
modules = jobs_reading["modules"]
|
|
view = modules["jaimini"]["special_lagnas"]
|
|
for alias, key in {"HL": "Hora_Lagna", "GL": "Ghati_Lagna", "ViL": "ViGhati_Lagna",
|
|
"PP": "Pranapada_Lagna", "VL": "Varnada_Lagna"}.items():
|
|
assert view[alias]["sign"] == modules["special_lagnas"][key]["sign"], alias
|
|
assert {k: view[k]["sign"] for k in ("HL", "GL", "ViL", "PP", "VL")} == {
|
|
"HL": "Aquarius", "GL": "Virgo", "ViL": "Capricorn", "PP": "Aquarius", "VL": "Sagittarius"}
|
|
|
|
|
|
def test_jaimini_third_karaka_table_is_bphs_eight(jobs_reading):
|
|
jaimini = jobs_reading["modules"]["jaimini"]
|
|
assert "chara_karaka_jh" not in jaimini
|
|
table = jaimini["chara_karaka_standard"]
|
|
assert table["mode"] == "bphs"
|
|
assert {k: v["planet"] for k, v in table["karakas"].items()} == {
|
|
"AK": "Venus", "AmK": "Saturn", "BK": "Jupiter", "MK": "Mercury",
|
|
"PiK": "Rahu", "PK": "Moon", "GK": "Sun", "DK": "Mars"}
|
|
|
|
|
|
def test_conditional_dashas_use_the_cli_year_length(jobs_reading):
|
|
modules = jobs_reading["modules"]
|
|
for key in ("tribhagi_dasha", "tribhagi_40_dasha", "shattrimshatsama_dasha"):
|
|
assert modules[key]["dasha_year_days"] == 365.25, key
|
|
assert modules["dasha"]["year_days"] == 365.25
|
|
|
|
|
|
def test_reading_birth_info_carries_year_length_and_observation_date():
|
|
from scripts.dasha_registry import build_reading_birth_info
|
|
|
|
planets = {"Moon": {"degree_raw": 100.0}, "Sun": {"degree_raw": 10.0}}
|
|
alt, conditional, _ = build_reading_birth_info(
|
|
datetime(1990, 1, 1, 12), planets, {"degree_raw": 15.0}, {"as_of": "2026-11-07"})
|
|
assert alt["as_of"] == conditional["as_of"] == "2026-11-07"
|
|
assert conditional["dasha_year_days"] == 365.25
|
|
_, conditional, _ = build_reading_birth_info(
|
|
datetime(1990, 1, 1, 12), planets, {"degree_raw": 15.0}, {"dasha_year_days": 365.25636})
|
|
assert conditional["dasha_year_days"] == 365.25636
|
|
assert "as_of" not in conditional
|
|
|
|
|
|
def _planets(houses: dict[str, int], asc: str) -> dict:
|
|
from scripts.yoga_engine import SIGNS
|
|
|
|
a = SIGNS.index(asc)
|
|
return {p: {"sign": SIGNS[(a + h - 1) % 12], "house": h, "degree": 10.0} for p, h in houses.items()}
|
|
|
|
|
|
def test_raj_yoga_lagna_lord_alone_is_not_a_dual_lord():
|
|
from scripts.yogas_doshas import calc_raj_yogas
|
|
|
|
# Capricorn rising: Saturn rules 1 and 2 only (1 is kendra and trikona).
|
|
planets = _planets({"Sun": 7, "Moon": 5, "Mars": 3, "Mercury": 7, "Jupiter": 1,
|
|
"Venus": 8, "Saturn": 1, "Rahu": 6, "Ketu": 12}, "Capricorn")
|
|
rows = calc_raj_yogas(planets, {"asc_sign": "Capricorn"})["yogas"]
|
|
assert not [r for r in rows if r["subtype"] == "dual_lordship" and r["combination"].startswith("Saturn")]
|
|
assert not [r for r in rows if "Saturn(角宫主)" in r["combination"] and "Saturn(三方宫主)" in r["combination"]]
|
|
|
|
|
|
def _names(planets, asc, context=None):
|
|
from scripts.yoga_engine import detect_yogas
|
|
|
|
return {row["rule_id"]: row for row in detect_yogas(planets, asc, context=context)}
|
|
|
|
|
|
def test_one_planet_ruling_both_houses_is_not_a_lords_relation():
|
|
# Cancer rising: Mars rules the 5th and the 10th.
|
|
planets = _planets({"Sun": 2, "Moon": 4, "Mars": 6, "Mercury": 2, "Jupiter": 9,
|
|
"Venus": 3, "Saturn": 11, "Rahu": 8, "Ketu": 2}, "Cancer")
|
|
rows = _names(planets, "Cancer")
|
|
assert not [r for r in rows.values() if r["name"] == "Raja Yoga (5th & 10th Lords Combination)"]
|
|
|
|
|
|
def test_retired_rules_do_not_fire():
|
|
from scripts.yoga_engine import RETIRED_RULE_IDS
|
|
|
|
assert {"chakra_nabhasa", "vajra_nabhasa", "kalanidhi_yoga", "dala_yoga"} <= RETIRED_RULE_IDS
|
|
planets = _planets({"Sun": 1, "Moon": 4, "Mars": 7, "Mercury": 10, "Jupiter": 1,
|
|
"Venus": 4, "Saturn": 7, "Rahu": 10, "Ketu": 4}, "Aries")
|
|
assert not RETIRED_RULE_IDS & set(_names(planets, "Aries"))
|
|
|
|
|
|
def test_mahabhagya_needs_gender_and_day_night():
|
|
# Aries rising, Sun in Leo, Moon in Gemini: all odd signs (male day branch).
|
|
planets = _planets({"Sun": 5, "Moon": 3, "Mars": 2, "Mercury": 6, "Jupiter": 9,
|
|
"Venus": 4, "Saturn": 10, "Rahu": 11, "Ketu": 5}, "Aries")
|
|
unknown = _names(planets, "Aries")["mahabhagya_yoga"]
|
|
assert unknown["condition_status"] == "incomplete_conditions"
|
|
assert unknown["missing_inputs"] == ["gender", "birth_is_daytime"]
|
|
assert unknown["effects"] == [] and unknown["strength"] == "conditional"
|
|
met = _names(planets, "Aries", {"gender": "male", "birth_is_daytime": True})["mahabhagya_yoga"]
|
|
assert met["condition_status"] == "conditions_met" and met["effects"]
|
|
assert "mahabhagya_yoga" not in _names(planets, "Aries", {"gender": "female"})
|
|
assert "mahabhagya_yoga" not in _names(planets, "Aries", {"birth_is_daytime": False})
|
|
|
|
|
|
def test_varga_yoga_needs_the_same_d9_sign():
|
|
planets = _planets({"Sun": 5, "Moon": 3, "Mars": 1, "Mercury": 6, "Jupiter": 9,
|
|
"Venus": 4, "Saturn": 10, "Rahu": 11, "Ketu": 5}, "Aries")
|
|
# Mars own sign in D1 (Aries) but Taurus in D9: not a divisional match.
|
|
assert "varga_yoga_d1_d9_lord_same" not in _names(
|
|
planets, "Aries", {"d9": {"ascendant": "Leo", "planets": {"Mars": {"sign": "Taurus"}}}})
|
|
assert "varga_yoga_d1_d9_lord_same" in _names(
|
|
planets, "Aries", {"d9": {"ascendant": "Leo", "planets": {"Mars": {"sign": "Aries"}}}})
|
|
|
|
|
|
def test_subha_kartari_moon_reads_the_houses_either_side():
|
|
# Moon in 4; Jupiter in 3 and Venus in 5 hem it.
|
|
planets = _planets({"Sun": 10, "Moon": 4, "Mars": 11, "Mercury": 10, "Jupiter": 3,
|
|
"Venus": 5, "Saturn": 8, "Rahu": 12, "Ketu": 6}, "Aries")
|
|
assert "shubha_kartari_moon" in _names(planets, "Aries")
|
|
# Benefics only in the Moon's own house: not hemming.
|
|
planets = _planets({"Sun": 10, "Moon": 4, "Mars": 11, "Mercury": 10, "Jupiter": 4,
|
|
"Venus": 4, "Saturn": 8, "Rahu": 12, "Ketu": 6}, "Aries")
|
|
assert "shubha_kartari_moon" not in _names(planets, "Aries")
|
|
|
|
|
|
def test_nodes_cast_no_aspect_in_custom_rules():
|
|
from scripts.yoga_engine import YogaContext, YogaEngine
|
|
|
|
planets = _planets({"Sun": 1, "Moon": 7, "Mars": 3, "Mercury": 2, "Jupiter": 9,
|
|
"Venus": 2, "Saturn": 10, "Rahu": 1, "Ketu": 7}, "Aries")
|
|
engine = YogaEngine.__new__(YogaEngine)
|
|
env = engine._build_custom_exec_globals(YogaContext(planets, "Aries"), {}, {})
|
|
assert env["aspect"]("Sun", "Moon") is True
|
|
assert env["aspect"]("Rahu", "Moon") is False
|
|
assert env["aspects_house"]("Ketu", 1) is False
|
|
|
|
|
|
def test_rule_library_entries_follow_upstream():
|
|
rules = {r["id"]: r for r in json.loads((ROOT / "references" / "yoga_rules.json").read_text(encoding="utf-8"))["rules"]}
|
|
assert rules["mahabhagya_yoga"]["logic"]["type"] == "mahabhagya"
|
|
assert rules["bvr_parihasaka_yoga"]["logic"]["type"] == "parihasaka"
|
|
assert rules["bvr_jananatpurvam_pitru_marana_yog"]["bvr_id"] == "BVR-242"
|
|
assert "aspect(benefic, c)" in rules["bvr_satkalatra_precise"]["logic"]["expr"]
|
|
assert "aspect(k,t) and aspect(t,k)" in rules["raja_yoga_mutual_aspect"]["logic"]["conditions"][0]["expr"]
|