fix: 초단기예보가 닿는 시간은 비·비 없음 모두 초단기예보를 따르게 (단기예보에 남은 비로 '지금' 칸·우산각이 비로 나오던 것)
This commit is contained in:
1 parent
e28a2e297e
commit
012d8a4821
9 files changed
+86
-96
No files matched your search
@@ -80,7 +80,6 @@ def offline(monkeypatch):
|
||||
|
||||
import scheduler.jobs as jobs
|
||||
import services.air_service as air_service
|
||||
import services.now_service as now_service
|
||||
import services.season_service as season_service
|
||||
import services.sky_service as sky_service
|
||||
import services.warning_service as warning_service
|
||||
@@ -118,7 +117,7 @@ def offline(monkeypatch):
|
||||
|
||||
clear = [("TMP", "20"), ("SKY", "1"), ("PTY", "0"), ("POP", "0"), ("PCP", "강수없음"), ("REH", "50"), ("WSD", "1.5")]
|
||||
monkeypatch.setattr(weather_service, "fetch_vilage", lambda *a: _async(hourly(24 * 4, clear)))
|
||||
monkeypatch.setattr(now_service, "fetch_ultra", lambda *a: _async(hourly(24 * 2, [("PTY", "0"), ("RN1", "강수없음"), ("T1H", "20")])))
|
||||
monkeypatch.setattr(weather_service, "fetch_ultra", lambda *a: _async(hourly(24 * 2, [("PTY", "0"), ("RN1", "강수없음"), ("T1H", "20")])))
|
||||
monkeypatch.setattr(air_service, "fetch_stations", lambda *a: _async([{"stationName": "테스트", "dmX": "37.56", "dmY": "126.91"}]))
|
||||
monkeypatch.setattr(air_service, "fetch_realtime", lambda *a: _async([{
|
||||
"stationName": "테스트", "pm25Value": "10", "pm10Value": "20", "pm25Grade": "1", "pm10Grade": "1",
|
||||
|
||||
@@ -6,8 +6,8 @@ from common.enums import RainType, Sky
|
||||
from common.utils.kma_time import KST, kst_midnight
|
||||
from services.calc.day_slot import slot_hours
|
||||
from services.calc.index_calc import Context
|
||||
from services.index_service import EARLY, WEATHER_SCORE_DEF, _shown_parts, current_slot, slot_results, with_ultra_rain
|
||||
from services.now_service import RainHour
|
||||
from services.index_service import EARLY, WEATHER_SCORE_DEF, _shown_parts, current_slot, slot_results
|
||||
from services.weather_service import RainHour, with_ultra_rain
|
||||
|
||||
DAY = date(2026, 10, 8)
|
||||
SUNSET = datetime(2026, 10, 8, 18, 0, tzinfo=KST)
|
||||
@@ -81,15 +81,17 @@ def _hourly(h: int, rain: RainType = RainType.NONE) -> WeatherHourly:
|
||||
)
|
||||
|
||||
|
||||
def test_ultra_rain_marks_dry_forecast_hours_as_rain():
|
||||
by_at = {r.forecast_at: r for r in (_hourly(9), _hourly(10), _hourly(11, RainType.SHOWER))}
|
||||
def test_ultra_overrides_vilage_rain_both_ways():
|
||||
"""초단기예보가 닿는 시각은 초단기예보가 이긴다: 단기예보가 맑아도 비로, 단기예보가 비여도 비 없음으로."""
|
||||
by_at = {r.forecast_at: r for r in (_hourly(9), _hourly(10), _hourly(11, RainType.SHOWER), _hourly(12, RainType.RAIN))}
|
||||
at = lambda h: kst_midnight(DAY) + timedelta(hours=h) # noqa: E731
|
||||
ultra = [RainHour(at=at(10), rain_type=RainType.RAIN, rain_mm=1.5), RainHour(at=at(9), rain_type=RainType.NONE, rain_mm=0),
|
||||
RainHour(at=at(11), rain_type=RainType.RAIN, rain_mm=3.0)]
|
||||
RainHour(at=at(11), rain_type=RainType.NONE, rain_mm=0)]
|
||||
out = with_ultra_rain(by_at, ultra)
|
||||
assert (out[at(10)].rain_type, float(out[at(10)].rain_mm)) == (RainType.RAIN.value, 1.5)
|
||||
assert out[at(9)] is by_at[at(9)] and out[at(11)] is by_at[at(11)]
|
||||
assert by_at[at(10)].rain_type == RainType.NONE.value
|
||||
assert (out[at(11)].rain_type, float(out[at(11)].rain_mm)) == (RainType.NONE.value, 0)
|
||||
assert out[at(9)] is by_at[at(9)] and out[at(12)] is by_at[at(12)]
|
||||
assert by_at[at(10)].rain_type == RainType.NONE.value and by_at[at(11)].rain_type == RainType.SHOWER.value
|
||||
|
||||
|
||||
def test_ultra_rain_lowers_slot_score():
|
||||
|
||||
@@ -4,7 +4,6 @@ from types import SimpleNamespace
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
import services.now_service as now_service
|
||||
import services.air_service as air_service
|
||||
import services.warning_service as warning_service
|
||||
import services.weather_service as weather_service
|
||||
@@ -52,7 +51,7 @@ def fakes(monkeypatch):
|
||||
}]))
|
||||
monkeypatch.setattr(warning_service, "fetch_warning_events", lambda *a: _async([]))
|
||||
monkeypatch.setattr(weather_service, "fetch_mid", lambda *a: _async(_mid()))
|
||||
monkeypatch.setattr(now_service, "fetch_ultra", lambda *a: _async([]))
|
||||
monkeypatch.setattr(weather_service, "fetch_ultra", lambda *a: _async([]))
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
|
||||
@@ -2,7 +2,6 @@ import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
import services.air_service as air_service
|
||||
import services.now_service as now_service
|
||||
import services.season_service as season_service
|
||||
import services.sky_service as sky_service
|
||||
import services.warning_service as warning_service
|
||||
@@ -16,7 +15,7 @@ REGION = "1114000000"
|
||||
ENDPOINTS = ["/v1/feed", "/v1/weather/today", "/v1/weather/now", "/v1/sky", "/v1/week", "/v1/index/list", "/v1/season/week"]
|
||||
SOURCES = {
|
||||
"vilage": (weather_service, "fetch_vilage", DataGoKrRequestFailed),
|
||||
"ultra": (now_service, "fetch_ultra", DataGoKrRequestFailed),
|
||||
"ultra": (weather_service, "fetch_ultra", DataGoKrRequestFailed),
|
||||
"air": (air_service, "fetch_realtime", DataGoKrRequestFailed),
|
||||
"warning": (warning_service, "fetch_warning_events", DataGoKrRequestFailed),
|
||||
"clouds": (sky_service, "fetch_clouds", OpenMeteoRequestFailed),
|
||||
|
||||
@@ -4,7 +4,7 @@ from types import SimpleNamespace
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
import services.now_service as now_service
|
||||
import services.weather_service as weather_service
|
||||
import services.week_service as week_service
|
||||
from common.cache.redis_client import REDIS
|
||||
from common.utils.kma_time import KST, now_kst
|
||||
@@ -94,7 +94,7 @@ async def test_watch_summary_flags_thunder_within_2_hours(offline, monkeypatch):
|
||||
{"category": c, "fcstDate": (start + timedelta(hours=h)).strftime("%Y%m%d"), "fcstTime": (start + timedelta(hours=h)).strftime("%H%M"), "fcstValue": v}
|
||||
for h in range(1, 7) for c, v in [("PTY", "1"), ("RN1", "5.0mm"), ("T1H", "20"), ("LGT", "2" if h == 1 else "0")]
|
||||
]
|
||||
monkeypatch.setattr(now_service, "fetch_ultra", lambda *a: _async(items))
|
||||
monkeypatch.setattr(weather_service, "fetch_ultra", lambda *a: _async(items))
|
||||
# 앞 테스트가 받아 둔 초단기예보 캐시(비 없음)를 지워야 새 예보를 읽는다
|
||||
await REDIS.conn.delete(f"ultra:{REGION}", f"lock:ultra:{REGION}")
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
|
||||
@@ -5,7 +5,6 @@ from httpx import ASGITransport, AsyncClient
|
||||
from sqlalchemy import text
|
||||
|
||||
import services.air_service as air_service
|
||||
import services.now_service as now_service
|
||||
import services.warning_service as warning_service
|
||||
import services.weather_service as weather_service
|
||||
from common.cache.redis_client import REDIS
|
||||
@@ -63,7 +62,7 @@ async def clean():
|
||||
async def test_now_combines_rain_tomorrow_air_and_warnings(monkeypatch, clean):
|
||||
now = now_kst()
|
||||
monkeypatch.setattr(weather_service, "fetch_vilage", lambda *a: _async(_vilage()))
|
||||
monkeypatch.setattr(now_service, "fetch_ultra", lambda *a: _async(_ultra()))
|
||||
monkeypatch.setattr(weather_service, "fetch_ultra", lambda *a: _async(_ultra()))
|
||||
monkeypatch.setattr(air_service, "fetch_stations", lambda *a: _async([{"stationName": "마포구", "dmX": "37.5555", "dmY": "126.9055"}]))
|
||||
monkeypatch.setattr(air_service, "fetch_realtime", lambda *a: _async([{
|
||||
"stationName": "마포구", "pm25Value": "11", "pm10Value": "24", "pm25Grade": "1", "pm10Grade": "1",
|
||||
@@ -92,7 +91,7 @@ async def test_now_warning_failure_is_unknown_not_none(monkeypatch, clean):
|
||||
raise DataGoKrRequestFailed("HTTP 504")
|
||||
|
||||
monkeypatch.setattr(weather_service, "fetch_vilage", lambda *a: _async(_vilage()))
|
||||
monkeypatch.setattr(now_service, "fetch_ultra", lambda *a: _async(_ultra()))
|
||||
monkeypatch.setattr(weather_service, "fetch_ultra", lambda *a: _async(_ultra()))
|
||||
monkeypatch.setattr(air_service, "fetch_stations", fail)
|
||||
monkeypatch.setattr(air_service, "fetch_realtime", fail)
|
||||
monkeypatch.setattr(warning_service, "fetch_warning_events", fail)
|
||||
|
||||
Reference in new issue
Block a user