|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import json |
| 4 | +from datetime import datetime |
| 5 | +from pathlib import Path |
| 6 | +from zoneinfo import ZoneInfo |
| 7 | + |
| 8 | +from preflight_go_no_go.kp import parse_kp_json |
| 9 | +from preflight_go_no_go.metar import parse_metar_list |
| 10 | +from preflight_go_no_go.models import Thresholds, Verdict |
| 11 | +from preflight_go_no_go.scoring import evaluate |
| 12 | +from preflight_go_no_go.sun import compute_sun_times |
| 13 | + |
| 14 | + |
| 15 | +def _day_now(): |
| 16 | + return datetime(2026, 10, 7, 13, 0, tzinfo=ZoneInfo("America/New_York")) |
| 17 | + |
| 18 | + |
| 19 | +def test_vfr_quiet_is_fly(fixtures_dir: Path): |
| 20 | + metars = parse_metar_list(json.loads((fixtures_dir / "metar_vfr.json").read_text())) |
| 21 | + kp = parse_kp_json(json.loads((fixtures_dir / "kp_quiet.json").read_text())) |
| 22 | + primary = next(m for m in metars if m.icao == "KXMR") |
| 23 | + sun = compute_sun_times(28.39, -80.60, when=_day_now()) |
| 24 | + report = evaluate( |
| 25 | + primary, [m for m in metars if m.icao != "KXMR"], kp, sun, Thresholds(), |
| 26 | + location_label="KXMR", lat=28.39, lon=-80.60, generated_at=_day_now(), |
| 27 | + ) |
| 28 | + assert report.verdict == Verdict.FLY |
| 29 | + |
| 30 | + |
| 31 | +def test_mvfr_rain_is_marginal(fixtures_dir: Path): |
| 32 | + metars = parse_metar_list(json.loads((fixtures_dir / "metar_mvfr.json").read_text())) |
| 33 | + kp = parse_kp_json(json.loads((fixtures_dir / "kp_quiet.json").read_text())) |
| 34 | + primary = next(m for m in metars if m.icao == "KXMR") |
| 35 | + sun = compute_sun_times(28.39, -80.60, when=_day_now()) |
| 36 | + report = evaluate( |
| 37 | + primary, [], kp, sun, Thresholds(), |
| 38 | + location_label="KXMR", lat=28.39, lon=-80.60, generated_at=_day_now(), |
| 39 | + ) |
| 40 | + assert report.verdict == Verdict.MARGINAL |
| 41 | + weather = next(f for f in report.factors if f.name == "weather") |
| 42 | + assert weather.verdict == Verdict.MARGINAL |
| 43 | + |
| 44 | + |
| 45 | +def test_thunderstorm_is_dont_fly(fixtures_dir: Path): |
| 46 | + metars = parse_metar_list(json.loads((fixtures_dir / "metar_thunderstorm.json").read_text())) |
| 47 | + kp = parse_kp_json(json.loads((fixtures_dir / "kp_quiet.json").read_text())) |
| 48 | + sun = compute_sun_times(28.39, -80.60, when=_day_now()) |
| 49 | + report = evaluate( |
| 50 | + metars[0], [], kp, sun, Thresholds(), |
| 51 | + location_label="KXMR", lat=28.39, lon=-80.60, generated_at=_day_now(), |
| 52 | + ) |
| 53 | + assert report.verdict == Verdict.DONT_FLY |
| 54 | + |
| 55 | + |
| 56 | +def test_kp_storm_dont_fly_even_in_vfr(fixtures_dir: Path): |
| 57 | + metars = parse_metar_list(json.loads((fixtures_dir / "metar_vfr.json").read_text())) |
| 58 | + kp = parse_kp_json(json.loads((fixtures_dir / "kp_storm.json").read_text())) |
| 59 | + primary = next(m for m in metars if m.icao == "KXMR") |
| 60 | + sun = compute_sun_times(28.39, -80.60, when=_day_now()) |
| 61 | + report = evaluate( |
| 62 | + primary, [], kp, sun, Thresholds(), |
| 63 | + location_label="KXMR", lat=28.39, lon=-80.60, generated_at=_day_now(), |
| 64 | + ) |
| 65 | + assert report.verdict == Verdict.DONT_FLY |
| 66 | + kp_f = next(f for f in report.factors if f.name == "kp") |
| 67 | + assert kp_f.verdict == Verdict.DONT_FLY |
| 68 | + |
| 69 | + |
| 70 | +def test_kp_marginal(fixtures_dir: Path): |
| 71 | + metars = parse_metar_list(json.loads((fixtures_dir / "metar_vfr.json").read_text())) |
| 72 | + kp = parse_kp_json(json.loads((fixtures_dir / "kp_marginal.json").read_text())) |
| 73 | + primary = next(m for m in metars if m.icao == "KXMR") |
| 74 | + sun = compute_sun_times(28.39, -80.60, when=_day_now()) |
| 75 | + report = evaluate( |
| 76 | + primary, [], kp, sun, Thresholds(), |
| 77 | + location_label="KXMR", lat=28.39, lon=-80.60, generated_at=_day_now(), |
| 78 | + ) |
| 79 | + assert report.verdict == Verdict.MARGINAL |
| 80 | + |
| 81 | + |
| 82 | +def test_night_is_marginal_by_default(fixtures_dir: Path): |
| 83 | + metars = parse_metar_list(json.loads((fixtures_dir / "metar_vfr.json").read_text())) |
| 84 | + kp = parse_kp_json(json.loads((fixtures_dir / "kp_quiet.json").read_text())) |
| 85 | + primary = next(m for m in metars if m.icao == "KXMR") |
| 86 | + night = datetime(2026, 10, 7, 23, 0, tzinfo=ZoneInfo("America/New_York")) |
| 87 | + sun = compute_sun_times(28.39, -80.60, when=night) |
| 88 | + report = evaluate( |
| 89 | + primary, [], kp, sun, Thresholds(), |
| 90 | + location_label="KXMR", lat=28.39, lon=-80.60, generated_at=night, |
| 91 | + ) |
| 92 | + assert report.verdict == Verdict.MARGINAL |
| 93 | + day_f = next(f for f in report.factors if f.name == "daylight") |
| 94 | + assert day_f.verdict == Verdict.MARGINAL |
0 commit comments