Ports her yinduzhanxing 17a135457ec16b621f86dd57ba3926612ce1b9b8 (docs ee34700357): timing_evidence_packets.py (new), kp_monthly_report_packet / theme_support / vimshottari / transits, kp_system, with her tests. The report path (frozen engine, no timing systems supplied) keeps its earlier packet byte for byte; her profile and window run when the caller supplies the periods it already computed (engine tool kp_timing_packet, cached per chart and window). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
91 lines
4.3 KiB
Python
91 lines
4.3 KiB
Python
from transit_search import build_retrograde_calendar, find_exact_conjunctions, sidereal_position_at
|
|
from datetime import datetime
|
|
import pytest
|
|
from transit_search import find_moving_aspects, find_stations
|
|
|
|
|
|
@pytest.mark.parametrize('target,expected', [(10, 1), (10.0004, 2), (9.999, 0)])
|
|
def test_extremum_splits_two_crossings_and_retains_tangent(monkeypatch, target, expected):
|
|
origin = datetime(2026, 1, 1)
|
|
def position(planet, stamp, tz, ayanamsa):
|
|
d = (datetime.fromisoformat(stamp) - origin).total_seconds() / 86400
|
|
return {'longitude': 10 + (d-.125)**2, 'speed': 2*(d-.125)}
|
|
monkeypatch.setattr('transit_search.sidereal_position_at', position)
|
|
rows = find_exact_conjunctions('Mercury', target, '2026-01-01', 0, 'lahiri', 1)
|
|
assert len(rows) == expected
|
|
assert all(row['angular_error_degrees'] < 1e-5 for row in rows)
|
|
stations = find_stations('Mercury', '2026-01-01', 0, 'lahiri', 1)
|
|
assert len(stations) == 1
|
|
assert stations[0]['direction_after'] == 'direct'
|
|
|
|
|
|
def test_moving_aspect_uses_both_positions_and_directed_angle(monkeypatch):
|
|
origin = datetime(2026, 1, 1)
|
|
def position(planet, stamp, tz, ayanamsa):
|
|
d = (datetime.fromisoformat(stamp) - origin).total_seconds() / 86400
|
|
return {'longitude': 20*d if planet == 'Moon' else 5*d, 'speed': 20 if planet == 'Moon' else 5}
|
|
monkeypatch.setattr('transit_search.sidereal_position_at', position)
|
|
rows = find_moving_aspects('Moon', 'Sun', 7.5, '2026-01-01', 0, 'lahiri', 1)
|
|
assert len(rows) == 1
|
|
assert datetime.fromisoformat(rows[0]['timestamp_local']) == datetime(2026, 1, 1, 12)
|
|
assert find_moving_aspects('Sun', 'Moon', 7.5, '2026-01-01', 0, 'lahiri', 1) == []
|
|
|
|
|
|
def test_exact_search_preserves_seconds_and_excludes_antipodal_jump(monkeypatch):
|
|
origin = datetime(2026, 1, 1)
|
|
def position(planet, timestamp, tz, ayanamsa):
|
|
day = (datetime.fromisoformat(timestamp) - origin).total_seconds() / 86400
|
|
return {'longitude': (175 + 20 * day) % 360, 'speed': 20}
|
|
monkeypatch.setattr('transit_search.sidereal_position_at', position)
|
|
assert find_exact_conjunctions('Moon', 0, '2026-01-01', 0, 'lahiri', 1) == []
|
|
rows = find_exact_conjunctions('Moon', 185.12345, '2026-01-01', 0, 'lahiri', 1)
|
|
assert len(rows) == 1
|
|
seconds = (datetime.fromisoformat(rows[0]['timestamp_local']) - origin).total_seconds()
|
|
assert seconds == pytest.approx((185.12345 - 175) / 20 * 86400, abs=.01)
|
|
|
|
|
|
def test_position_second_resolution_is_not_truncated():
|
|
a = sidereal_position_at('Moon', '2026-01-01T12:00:00', 0, 'lahiri')
|
|
b = sidereal_position_at('Moon', '2026-01-01T12:00:30', 0, 'lahiri')
|
|
assert b['longitude'] != a['longitude']
|
|
|
|
|
|
def test_exact_search_start_inclusive_end_exclusive(monkeypatch):
|
|
origin = datetime(2026, 1, 1)
|
|
def position(planet, timestamp, tz, ayanamsa):
|
|
days = (datetime.fromisoformat(timestamp) - origin).total_seconds() / 86400
|
|
return {'longitude': days * 20, 'speed': 20}
|
|
monkeypatch.setattr('transit_search.sidereal_position_at', position)
|
|
assert len(find_exact_conjunctions('Moon', 0, '2026-01-01', 0, 'lahiri', 1)) == 1
|
|
assert find_exact_conjunctions('Moon', 20, '2026-01-01', 0, 'lahiri', 1) == []
|
|
|
|
|
|
def test_conjunction_search_finds_reference_longitude() -> None:
|
|
position = sidereal_position_at("Saturn", "2026-01-15T12:00:00", 8, "lahiri")
|
|
rows = find_exact_conjunctions("Saturn", position["longitude"], "2026-01-15", 8, "lahiri", 2)
|
|
|
|
assert rows
|
|
assert rows[0]["angular_error_degrees"] < 1 / 60
|
|
|
|
|
|
def test_retrograde_periods_refine_station_boundaries() -> None:
|
|
calendar = build_retrograde_calendar("2026-01-01", 3, 8, "lahiri")
|
|
mercury = next(
|
|
period
|
|
for bucket in calendar.values()
|
|
for period in bucket["periods"]
|
|
if period["planet"] == "Mercury"
|
|
)
|
|
|
|
assert mercury["station_start_local"] != mercury["start"]
|
|
assert mercury["station_end_local"] != mercury["end"]
|
|
assert abs(mercury["station_start_speed_degrees_per_day"]) < 0.001
|
|
assert abs(mercury["station_end_speed_degrees_per_day"]) < 0.001
|
|
|
|
|
|
def test_retrograde_calendar_returns_month_buckets() -> None:
|
|
calendar = build_retrograde_calendar("2026-01-01", 1, 8, "lahiri")
|
|
|
|
assert isinstance(calendar, dict)
|
|
assert all("retrograde" in row and "periods" in row for row in calendar.values())
|