fix: restore ayanamsa state and keep tests hermetic
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_only_ayanamsa_utils_sets_process_sidereal_mode() -> None:
|
||||
violations = []
|
||||
for path in (ROOT / "scripts").rglob("*.py"):
|
||||
if path.name == "ayanamsa_utils.py":
|
||||
continue
|
||||
if re.search(r"\bset_sid_mode\s*\(", path.read_text(encoding="utf-8")):
|
||||
violations.append(str(path.relative_to(ROOT)))
|
||||
assert violations == []
|
||||
@@ -14,15 +14,16 @@ INDEX = ROOT / "references/oracle/evidence_packet_index_2026_07_19.json"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def matrix_packet() -> dict:
|
||||
def matrix_packet(tmp_path_factory: pytest.TempPathFactory) -> dict:
|
||||
output_dir = tmp_path_factory.mktemp("full-technique-invocation-matrix")
|
||||
subprocess.run(
|
||||
[sys.executable, "scripts/full_technique_invocation_matrix.py"],
|
||||
[sys.executable, "scripts/full_technique_invocation_matrix.py", "--output-dir", str(output_dir)],
|
||||
cwd=ROOT,
|
||||
check=True,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
)
|
||||
return json.loads(PACKET.read_text(encoding="utf-8"))
|
||||
return json.loads((output_dir / PACKET.name).read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def test_full_matrix_scans_all_required_runtime_layers(matrix_packet: dict) -> None:
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
import swisseph as swe
|
||||
|
||||
from scripts.gulika import calculate_gulika
|
||||
from ayanamsa_utils import DEFAULT_AYANAMSA_NAME, apply_ayanamsa
|
||||
|
||||
|
||||
def _moon_longitude() -> float:
|
||||
jd = swe.julday(2000, 1, 1, 12.0)
|
||||
return float(swe.calc_ut(jd, swe.MOON, swe.FLG_SWIEPH | swe.FLG_SIDEREAL)[0][0])
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("previous", "requested"), [("lahiri", "raman"), ("raman", "lahiri")])
|
||||
def test_gulika_restores_process_ayanamsa(previous: str, requested: str) -> None:
|
||||
try:
|
||||
assert apply_ayanamsa(previous, swe)
|
||||
before = _moon_longitude()
|
||||
|
||||
result = calculate_gulika(
|
||||
datetime(1990, 1, 1, 12, 0),
|
||||
lat=39.9042,
|
||||
lon=116.4074,
|
||||
tz=8,
|
||||
ayanamsa=requested,
|
||||
)
|
||||
|
||||
assert result["ayanamsa"] == requested
|
||||
assert _moon_longitude() == pytest.approx(before, abs=1e-10)
|
||||
finally:
|
||||
apply_ayanamsa(DEFAULT_AYANAMSA_NAME, swe)
|
||||
@@ -7,10 +7,10 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
PACKET = ROOT / "references/oracle/muhurta_factor_only_scoring_packet_2026_07_23.json"
|
||||
|
||||
|
||||
def test_muhurta_factor_only_packet_generator_captures_ten_factors():
|
||||
def test_muhurta_factor_only_packet_generator_captures_ten_factors(tmp_path: Path):
|
||||
data = json.loads(
|
||||
subprocess.check_output(
|
||||
["python3", "scripts/muhurta_factor_only_scoring_packet.py"],
|
||||
["python3", "scripts/muhurta_factor_only_scoring_packet.py", "--output-dir", str(tmp_path)],
|
||||
cwd=ROOT,
|
||||
text=True,
|
||||
)
|
||||
|
||||
@@ -22,6 +22,8 @@ def test_prashna_context_uses_backend_chart_from_question_moment():
|
||||
assert packet["ascendant"]["degree"] >= 0
|
||||
assert "Sun" in packet["planets"]
|
||||
assert "question_timestamp" in packet
|
||||
assert packet["ayanamsa"] == "lahiri"
|
||||
assert packet["supporting_indicators"]["gulika"]["ayanamsa"] == "lahiri"
|
||||
|
||||
|
||||
def test_prashna_context_rejects_missing_time_or_non_wgs84_location():
|
||||
|
||||
@@ -7,8 +7,8 @@ ARTIFACT = ROOT / "references/oracle/prashna_sphuta_oss_case_probe_2026_07_20.js
|
||||
INDEX = ROOT / "references/oracle/evidence_packet_index_2026_07_19.json"
|
||||
|
||||
|
||||
def test_prashna_sphuta_oss_case_probe_runs_pyjhora_case_in_isolation():
|
||||
data = json.loads(subprocess.check_output(["python3", "scripts/prashna_sphuta_oss_case_probe.py", "--date", "2026-07-20"], cwd=ROOT, text=True))
|
||||
def test_prashna_sphuta_oss_case_probe_runs_pyjhora_case_in_isolation(tmp_path: Path):
|
||||
data = json.loads(subprocess.check_output(["python3", "scripts/prashna_sphuta_oss_case_probe.py", "--date", "2026-07-20", "--output-dir", str(tmp_path)], cwd=ROOT, text=True))
|
||||
assert data["scope"] == "prashna_sphuta_oss_case_probe"
|
||||
assert data["claim_status"] == "tooling_observation_only"
|
||||
assert data["license_boundary"] == "agpl_observation_only_do_not_vendor"
|
||||
|
||||
@@ -79,10 +79,10 @@ def test_solar_return_julian_datetime_helpers_work_without_greg_flag_constant():
|
||||
assert roundtrip.minute == 30
|
||||
|
||||
|
||||
def test_muhurta_sun_moon_helper_defaults_to_lahiri_after_global_raman_switch():
|
||||
def test_muhurta_sun_moon_helper_defaults_to_product_ayanamsa():
|
||||
jd = swe.julday(2026, 6, 25, 4.0)
|
||||
expected_sun = _sidereal_lon(jd, swe.SUN, swe.SIDM_LAHIRI)
|
||||
expected_moon = _sidereal_lon(jd, swe.MOON, swe.SIDM_LAHIRI)
|
||||
expected_sun = _sidereal_lon(jd, swe.SUN, swe.SIDM_RAMAN)
|
||||
expected_moon = _sidereal_lon(jd, swe.MOON, swe.SIDM_RAMAN)
|
||||
|
||||
_apply_ayanamsa('raman')
|
||||
actual = _swisseph_sun_moon_lon(jd)
|
||||
@@ -92,10 +92,10 @@ def test_muhurta_sun_moon_helper_defaults_to_lahiri_after_global_raman_switch():
|
||||
assert _angular_diff(actual[1], expected_moon) < 1e-9
|
||||
|
||||
|
||||
def test_cmd_muhurta_helper_defaults_to_lahiri_after_global_raman_switch():
|
||||
def test_cmd_muhurta_helper_defaults_to_product_ayanamsa():
|
||||
jd = swe.julday(2026, 6, 25, 4)
|
||||
expected_sun = _sidereal_lon(jd, swe.SUN, swe.SIDM_LAHIRI)
|
||||
expected_moon = _sidereal_lon(jd, swe.MOON, swe.SIDM_LAHIRI)
|
||||
expected_sun = _sidereal_lon(jd, swe.SUN, swe.SIDM_RAMAN)
|
||||
expected_moon = _sidereal_lon(jd, swe.MOON, swe.SIDM_RAMAN)
|
||||
|
||||
_apply_ayanamsa('raman')
|
||||
sun, moon, has_swe = _get_sun_moon_lons(2026, 6, 25, hour=4)
|
||||
|
||||
Reference in New Issue
Block a user