Files
Jyotisha/tests/test_upstream_sync10_kp_unrounded_inputs.py
T
ClaudeandClaude Opus 5.5 9d69cd5625 fix(kp): feed sub-lord analysis unrounded cusps, degrees and time (BUG-1543, upstream 26d5a52d)
cmd_kp handed calc_kp_analysis the cusps from calculate_bhava_boundaries
(rounded to 4 decimals), degree_in_sign (4 decimals) and the chart's
display julian_day (6 decimals). KP star, sub and sub-sub boundaries are
cut on raw longitude, so a body or cusp sitting on a boundary could land
one cell off. The fix recomputes the JD from the civil instant with the
compute_chart_data formula, uses calculate_cusps directly, and uses
degree_raw % 30.

Only the KP part of 26d5a52d is ported. Its Vivaha Saham day/night change
and Yoga status pass-through are left for a separate decision. Test ported
from upstream tests/test_kp_unrounded_inputs.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyeZrYn6ryNcSe5Y2Y
2026-11-04 12:01:47 +08:00

49 lines
2.2 KiB
Python

"""KP must not reuse display-rounded time, cusps or planet degrees (BUG-1543).
Ported from upstream yinduzhanxing 26d5a52d tests/test_kp_unrounded_inputs.py
(sync 10). Synthetic chart only.
"""
import sys
from pathlib import Path
from types import SimpleNamespace
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'scripts'))
import jyotish_engine as engine # noqa: E402
from bhava_chalit import BhavaChalitCalculator # noqa: E402
def test_kp_passes_raw_time_cusps_and_longitudes(monkeypatch):
args = SimpleNamespace(year=2000, month=1, day=2, hour=3, minute=4, second=5,
lat=20., lon=75., tz=5.5, ayanamsa='raman')
chart = {'ascendant': {'sign': 'Aries', 'degree_raw': 12.123456789},
'planets': {'Sun': {'sign': 'Aries', 'degree_raw': 1.234567891, 'degree_in_sign': 1.2346},
'Moon': {'sign': 'Taurus', 'degree_raw': 42.987654321, 'degree_in_sign': 12.9877}}}
raw_cusps = [12.123456789 + 30 * i for i in range(12)]
seen = {}
monkeypatch.setattr(engine, '_compute_chart_from_args', lambda a: (chart, 0, 2451545., 23.))
def cusps(self, asc, mc, hs, jd, lat, lon):
seen['jd'] = jd
return raw_cusps
monkeypatch.setattr(BhavaChalitCalculator, 'calculate_cusps', cusps)
monkeypatch.setattr(BhavaChalitCalculator, 'get_bhava_chalit_chart',
lambda *a, **k: {'planets': {'Sun': {'bhava_house': 12}, 'Moon': {'bhava_house': 2}}})
def analyze(planets, asc, **kwargs):
seen['planets'] = planets
seen.update(kwargs)
return {}
monkeypatch.setattr(engine, 'calc_kp_analysis', analyze)
monkeypatch.setattr(engine, 'attach_calculation_profile', lambda result, args: result)
monkeypatch.setattr(engine, '_build_response_envelope', lambda command, result, **k: result)
engine.cmd_kp(args)
expected = engine.swe.julday(2000, 1, 2, 3 + 4 / 60 + 5 / 3600 - 5.5)
assert seen['jd'] == expected and seen['jd'] != round(expected, 6)
assert seen['house_cusps'] == raw_cusps
assert seen['planets']['Sun']['degree'] == 1.234567891
assert seen['planets']['Moon']['degree'] == 42.987654321 % 30
assert seen['house_occupancy_basis'] == 'cusp_to_cusp'