test(yogas): lock Pancha Mahapurusha self-conjunction fix (BUG-1180)

Before 57782aea `_has_malefic_aspect` skipped `pn == planet_sign` (planet
name vs sign name), so Mars / Saturn counted themselves as a malefic
conjunction and Ruchaka / Shasha were never valid. Fictional placements;
red on 57782aea^ (Ruchaka is_valid False), green now.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N4f2nya58RoRu4yEmJgRGE
This commit is contained in:
Jesse_Chen
2026-10-02 12:32:01 +08:00
co-authored by Claude Opus 5.5
parent 3733b9787b
commit 3a40d42208
@@ -0,0 +1,54 @@
"""BUG-1180: a Mahapurusha planet must not count itself as the malefic conjunct with it.
Before 57782aea ``_has_malefic_aspect`` skipped ``pn == planet_sign`` (a planet name
compared with a sign name, never equal), so Mars and Saturn -- natural malefics --
always "afflicted" themselves and Ruchaka / Shasha were never valid. The fix passes
the yoga planet and skips it. Fictional placements; no birth data.
"""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))
from pancha_mahapurusha import _has_malefic_aspect, detect_pancha_mahapurusha # noqa: E402
def _yoga(yogas: list[dict], name: str) -> dict:
return next(item for item in yogas if item["name"] == name)
def test_ruchaka_mars_alone_in_own_kendra_is_valid() -> None:
planets = {"Mars": {"sign": "Aries", "house": 1, "degree": 10.0}}
ruchaka = _yoga(detect_pancha_mahapurusha(planets), "Ruchaka Yoga")
assert ruchaka["is_valid"] is True
assert ruchaka["cancellations"] == []
def test_shasha_saturn_exalted_in_kendra_is_valid() -> None:
planets = {"Saturn": {"sign": "Libra", "house": 10, "degree": 200.0}}
shasha = _yoga(detect_pancha_mahapurusha(planets), "Shasha Yoga")
assert shasha["is_valid"] is True
def test_another_malefic_in_the_same_sign_still_cancels_and_is_named() -> None:
planets = {
"Mars": {"sign": "Aries", "house": 1, "degree": 10.0},
"Saturn": {"sign": "Aries", "house": 1, "degree": 12.0},
}
ruchaka = _yoga(detect_pancha_mahapurusha(planets), "Ruchaka Yoga")
assert ruchaka["is_valid"] is False
assert any("Saturn" in reason and "Mars," not in reason for reason in ruchaka["cancellations"])
assert _has_malefic_aspect("Aries", planets, "Mars") == ["Saturn"]
def test_benefic_yoga_planet_unchanged() -> None:
planets = {
"Jupiter": {"sign": "Cancer", "house": 4, "degree": 95.0},
"Mars": {"sign": "Cancer", "house": 4, "degree": 100.0},
}
hamsa = _yoga(detect_pancha_mahapurusha(planets), "Hamsa Yoga")
assert hamsa["is_valid"] is False
assert _has_malefic_aspect("Cancer", planets, "Jupiter") == ["Mars"]