- Moved the assignment of `phenology_phase` in assemble.py to ensure it is included only for valid days. - Updated the docstring in disease.py to clarify the rounding behavior of decimal values, enhancing the understanding of the formatting logic. - Removed unnecessary checks in the decimal formatting function to streamline the code.
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""Unit tests for advice-generation JSON assembly."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
from datetime import date, timedelta
|
|
|
|
from pipeline.stages.assemble import assemble_json_for_advice_generation
|
|
from pipeline.window import build_window, format_date
|
|
|
|
_AS_OF = date(2026, 4, 16)
|
|
_PHASE = "BBCH 15"
|
|
|
|
|
|
class AdviceGenerationPhenologyTests(unittest.TestCase):
|
|
def test_phenology_phase_only_on_past_and_today(self) -> None:
|
|
window = build_window(_AS_OF)
|
|
phenology = {day: _PHASE if day <= _AS_OF else None for day in window}
|
|
payload = assemble_json_for_advice_generation(
|
|
_AS_OF,
|
|
weather={},
|
|
phenology=phenology,
|
|
forecasts={},
|
|
)
|
|
|
|
self.assertEqual(payload["date_of_today"], format_date(_AS_OF))
|
|
self.assertEqual(len(payload["meteorological_data"]), 6)
|
|
self.assertEqual(len(payload["weather_forecasts"]), 5)
|
|
|
|
for entry in payload["meteorological_data"]:
|
|
self.assertIn("phenology_phase", entry)
|
|
self.assertEqual(entry["phenology_phase"], _PHASE)
|
|
|
|
for entry in payload["weather_forecasts"]:
|
|
self.assertNotIn("phenology_phase", entry)
|
|
|
|
last_meteo = payload["meteorological_data"][-1]
|
|
self.assertEqual(last_meteo["date"], format_date(_AS_OF))
|
|
first_forecast = payload["weather_forecasts"][0]
|
|
self.assertEqual(first_forecast["date"], format_date(_AS_OF + timedelta(days=1)))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|