#!/usr/bin/env python3 """Regressione visibilità ore nella tabella meteo 48h.""" import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from open_meteo_precip import ( apply_hourly_daily_precip, hourly_table_should_show, overlay_icon_precip_on_hourly, ) def test_first_24h_all_shown(): for h in range(24): assert hourly_table_should_show(h, 0.0, 3) is True def test_second_day_even_hours_shown(): assert hourly_table_should_show(24, 0.0, 3) is True # lun 08 assert hourly_table_should_show(32, 5.0, 63) is True # lun 16 def test_second_day_odd_dry_hidden(): assert hourly_table_should_show(31, 0.0, 3) is False # lun 15 secco def test_second_day_odd_wet_shown(): # Caso reale 17/08/2026: 15:00 = 17.4 mm (code 65) era nascosto → 48h mostrava solo 5 mm alle 16 assert hourly_table_should_show(31, 17.4, 65) is True assert hourly_table_should_show(31, 0.0, 65) is True # codice precip anche con mm 0 def test_apply_hourly_daily_precip_matches_hours(): hourly = { "time": [f"2026-08-17T{h:02d}:00" for h in range(24)], "precipitation": [0.0] * 24, "rain": [0.0] * 24, "showers": [0.0] * 24, "snowfall": [0.0] * 24, } hourly["rain"][15] = 17.4 hourly["rain"][16] = 5.0 hourly["precipitation"][15] = 17.4 hourly["precipitation"][16] = 5.0 daily = { "time": ["2026-08-17"], "precipitation_sum": [18.0], "rain_sum": [18.0], "showers_sum": [20.0], "snowfall_sum": [0.0], } out = apply_hourly_daily_precip(daily, hourly) assert out["precipitation_sum"][0] == 22.4 assert out["rain_sum"][0] == 22.4 assert out["showers_sum"][0] == 0.0 def test_overlay_matches_normalized_timestamps(): target = { "time": ["2026-08-17T15:00"], "precipitation": [0.0], "rain": [0.0], "showers": [0.0], "snowfall": [0.0], } icon = { "time": ["2026-08-17T15:00:00"], "precipitation": [17.4], "rain": [17.4], "showers": [0.0], "snowfall": [0.0], } out = overlay_icon_precip_on_hourly(target, icon) assert abs(out["precipitation"][0] - 17.4) < 0.01 if __name__ == "__main__": test_first_24h_all_shown() test_second_day_even_hours_shown() test_second_day_odd_dry_hidden() test_second_day_odd_wet_shown() test_apply_hourly_daily_precip_matches_hours() test_overlay_matches_normalized_timestamps() print("OK hourly_table_should_show")