Files
Jyotisha/tests/test_bhava_bala_formal.py
T
jesse-uxandJesse_Chen 98c98aa535 feat(report): replace the reader edition with the full-data report
Generate the full-data edition (pl9_personal_long_report.v4) and remove the reader edition. English still contains Han, so the API withholds it (BUG-1272, investigating). This commit is not pushed to staging.
2026-10-08 22:29:31 +08:00

71 lines
3.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Bhava Bala is the formal three-component module on every surface (BUG-1210).
Astrologer rulings 2026-10-03 甲13: the local house score (benefic +2, malefic
-1.5 ...; `shadbala.calc_local_bhava_score`, formerly `calc_bhava_bala`) has no
source and is not shown; reports use `bhava_bala.bhava_bala_from_chart`
(Bhavadhipati + Bhava Dig + Bhava Drishti). Fictional chart.
"""
from __future__ import annotations
import copy
import re
from pathlib import Path
from scripts.bhava_bala import bhava_bala_from_chart, calc_bhava_adhipathi_bala
from scripts.jyotish_engine import cmd_full_reading
from scripts.pl9_reader_export import _pl9_export_markdown_for_edition
from scripts.shadbala import calc_local_bhava_score, calc_shadbala
from tests.test_report_english_edition import CASES, _packet
ROOT = Path(__file__).resolve().parents[1]
def test_local_score_is_renamed_and_not_in_shadbala_result() -> None:
import scripts.shadbala as shadbala
assert not hasattr(shadbala, "calc_bhava_bala")
planets = {"Sun": {"sign": "Leo", "house": 1, "degree": 10.0, "lon": 130.0},
"Moon": {"sign": "Cancer", "house": 12, "degree": 5.0, "lon": 95.0}}
assert calc_local_bhava_score(planets, "Leo")[1]["lord"] == "Sun"
result = calc_shadbala(planets, "Leo", 12.0, 130.0, 95.0)
assert "bhava_bala" not in result and "local_bhava_score" not in result
def test_full_reading_bhava_bala_is_the_formal_module() -> None:
case = CASES["day"]
reading = cmd_full_reading(type("Args", (), dict(case))())
module = reading["modules"]["bhava_bala"]
assert module["source"] == "scripts/bhava_bala.py" and module["unit"] == "virupa"
shadbala = reading["modules"]["shadbala"]["planets"]
lords = [row["lord"] for row in module["houses"]]
assert [row["adhipathi_bala"] for row in module["houses"]] == [round(shadbala[lord]["total_virupas"], 2) for lord in lords]
for row in module["houses"]:
assert row["total"] == round(row["adhipathi_bala"] + row["dig_bala"] + row["drik_bala"], 2) or abs(
row["total"] - (row["adhipathi_bala"] + row["dig_bala"] + row["drik_bala"])) < 0.02
assert row["total_rupas"] == round(row["total"] / 60.0, 2)
assert "factors" not in row and "score" not in row and "level" not in row
def test_reader_report_shows_three_components_and_no_plus_minus_scoring() -> None:
packet = _packet(CASES["day"])
for language in ("zh", "en"):
edition = copy.deepcopy(packet)
edition["report_language"] = language
markdown = _pl9_export_markdown_for_edition(edition, "full_data")
# 原值:两版都是 | House | Sign | Lord | Bhavadhipati | Dig | Drishti | Total (Virupa) | Total (Rupa) |
# 新值:中文表头为 | 宫位 | 星座 | 宫主 | Bhavadhipati | …;英文保持原表头
# 原因:完整数据版中文清理翻译 House/Sign/Lord。三项分量与禁止网站 +2/−1.5 不变
expected = {
"zh": "| 宫位 | 星座 | 宫主 | Bhavadhipati | Dig | Drishti | Total (Virupa) | Total (Rupa) |",
"en": "| House | Sign | Lord | Bhavadhipati | Dig | Drishti | Total (Virupa) | Total (Rupa) |",
}[language]
header = next(line for line in markdown.splitlines() if line.startswith(expected.split(" | Bhavadhipati")[0]))
assert header == expected
assert not re.search(r"\(Benefic\): \+2|\(Malefic\): -1\.5|吉星 \+2|凶星 −1\.5|凶星 -1\.5", markdown)
def test_adhipathi_is_the_lords_shadbala() -> None:
assert calc_bhava_adhipathi_bala(["Aries", "Taurus"], {"Mars": 400.0, "Venus": 350.0}) == [400.0, 350.0]
assert bhava_bala_from_chart({}, "Aries", 10.0, {}) == {}