feat: 달 '밝기 %' 대신 모양 + 잘 보이는지(구름·뜨고 지는 시각), 달 모양을 실제 해·달 위치로
This commit is contained in:
1 parent
3a73a44cb0
commit
fb47f59d57
8 files changed
+204
-32
No files matched your search
@@ -1,9 +1,9 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from types import SimpleNamespace
|
||||
|
||||
from common.enums import PostType
|
||||
from common.utils.kma_time import KST
|
||||
from services.calc.moon import nearest, phase_name
|
||||
from services.calc.moon import altitude, nearest, night, phase_name, view_line
|
||||
from services.feed_service import FeedService, _tonight
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ def test_tonight_follows_feed_day_starting_at_3am():
|
||||
|
||||
def _moon_post(now: datetime):
|
||||
base = dict(post_id=1, post_type=PostType.MOON, like_count=0, comment_count=0, published_at=now)
|
||||
c = SimpleNamespace(now=now, region=SimpleNamespace(short_name="분당구"), hourly=[], board=None)
|
||||
c = SimpleNamespace(now=now, region=SimpleNamespace(short_name="분당구", lat=37.38, lon=127.12), hourly=[], board=None)
|
||||
return FeedService._moon(None, base, c)
|
||||
|
||||
|
||||
@@ -38,3 +38,38 @@ def test_moon_post_every_night_with_full_and_new_moon_stories():
|
||||
assert new.title == "오늘 밤 달 없는 밤"
|
||||
plain = _moon_post(datetime(2025, 10, 4, 20, 0, tzinfo=KST)) # 보름 사흘 전
|
||||
assert plain.title == "오늘 밤 차오르는 달" and plain.slides[0].rows[-1].label == "다음 보름" and plain.slides[0].rows[-1].value.startswith("10.07")
|
||||
|
||||
|
||||
SEOUL = (37.57, 126.98)
|
||||
|
||||
|
||||
def _night_of(at):
|
||||
"""그 시각과 23시가 가장 가까운 밤."""
|
||||
return (at.astimezone(KST) - timedelta(hours=11)).date()
|
||||
|
||||
|
||||
def test_full_moon_is_up_all_night_and_highest_near_solar_midnight():
|
||||
full = nearest(datetime(2026, 10, 25, tzinfo=KST), True)
|
||||
day = _night_of(full)
|
||||
m = night(day, *SEOUL)
|
||||
assert m.name == "보름달" and set(range(20, 29)) <= set(m.up_hours)
|
||||
start = datetime.combine(day, datetime.min.time(), tzinfo=KST)
|
||||
peak = max((start + timedelta(hours=22, minutes=10 * i) for i in range(24)), key=lambda t: altitude(t, *SEOUL))
|
||||
assert 23 <= (peak.hour if peak.hour >= 12 else peak.hour + 24) <= 25
|
||||
assert view_line(m, 0.0) == "밤새 잘 보여요"
|
||||
assert view_line(m, 0.8) == "구름에 가려요"
|
||||
|
||||
|
||||
def test_first_quarter_sets_around_midnight_and_new_moon_is_not_seen():
|
||||
new = nearest(datetime(2026, 10, 12, tzinfo=KST), False)
|
||||
quarter = night(_night_of(new + timedelta(days=7.4)), *SEOUL)
|
||||
assert quarter.set_at is not None and quarter.set_at.astimezone(KST).hour in (21, 22, 23, 0, 1, 2)
|
||||
assert view_line(quarter, 0.0).endswith("까지 보여요")
|
||||
assert view_line(night(_night_of(new), *SEOUL), 0.0) == "달이 안 보여요"
|
||||
|
||||
|
||||
def test_waning_moon_rises_late():
|
||||
full = nearest(datetime(2026, 10, 25, tzinfo=KST), True)
|
||||
m = night(_night_of(full + timedelta(days=7.4)), *SEOUL)
|
||||
assert m.rise_at is not None and m.rise_at.astimezone(KST).hour in (21, 22, 23, 0, 1, 2)
|
||||
assert view_line(m, 0.0).endswith("에 떠요")
|
||||
Reference in new issue
Block a user