"""Tests for forecast.py, using a saved response instead of the network.

Author: YOUR NAME
Version: THE DATE
"""

import json
from pathlib import Path

from forecast import format_day, get_category, summarize_days

# Load the saved response once, from the folder this file is in
with open(Path(__file__).with_name("sample_forecast.json"), encoding="utf-8") as file:
    SAMPLE = json.load(file)


def test_get_category():
    assert get_category(0) == "sunny"


def test_summarize_days():
    days = summarize_days(SAMPLE)
    assert days[0] == {"date": "2026-12-04", "high": 48.2, "low": 29.4,
                       "precip": 3, "category": "sunny"}


def test_format_day():
    day = {"date": "2026-12-04", "high": 48.2, "low": 29.4, "precip": 3, "category": "sunny"}
    assert format_day(day) == "2026-12-04  High  48°F  Low  29°F  Precip   3%  ☀️ Sunny"
