from datetime import datetime, timezone from common.enums import Confidence, SkyGrade, SkyType from common.utils.geo import destination, haversine_km from services.calc.sky_score import Layers, best_times, confidence, grade, score CLEAR = Layers(0, 0, 0) def test_high_clouds_overhead_and_clear_horizon_is_best(): canvas = Layers(low=0, mid=20, high=50) assert score(canvas, CLEAR) == 100 def test_clear_sky_is_only_soft(): assert grade(score(CLEAR, CLEAR)) is SkyGrade.SOFT def test_low_clouds_toward_sun_block_the_light(): canvas = Layers(low=0, mid=20, high=50) assert grade(score(canvas, Layers(low=90, mid=50, high=0))) is SkyGrade.GRAY def test_overcast_low_clouds_is_gray(): gray = Layers(low=100, mid=100, high=100) assert grade(score(gray, gray)) is SkyGrade.GRAY def test_confidence_from_model_spread(): assert confidence([70, 72, 68, 71]) is Confidence.HIGH assert confidence([40, 80, 60, 90]) is Confidence.LOW assert confidence([70]) is Confidence.LOW def test_destination_point_is_at_given_distance(): lat, lon = destination(37.56, 126.91, 266, 50) assert abs(haversine_km(37.56, 126.91, lat, lon) - 50) < 0.1 assert lon < 126.91 def test_sunset_best_times_order(): sunset = datetime(2026, 10, 2, 9, 15, tzinfo=timezone.utc) dusk = datetime(2026, 10, 2, 9, 41, tzinfo=timezone.utc) labels = [t["label"] for t in best_times(SkyType.SUNSET, sunset, dusk, 50)] assert labels == ["해 져요", "가장 붉을 때", "보랏빛 하늘"]