"""Tests for trip stats.""" from datetime import date import agenda from agenda.stats import calculate_yearly_stats from agenda.types import Trip def make_trip(start: date, country_code: str) -> Trip: """Build a trip with a single country visit.""" return Trip(start=start, accommodation=[{"country": country_code}]) def test_new_country_only_first_year() -> None: """Ensure new countries are only counted on their first visit year.""" trips = [ make_trip(date(2024, 5, 1), "CZ"), make_trip(date(2026, 6, 1), "CZ"), ] yearly_stats = calculate_yearly_stats(trips) czechia = agenda.get_country("CZ") assert czechia is not None assert czechia in yearly_stats[2024]["countries"] assert czechia in yearly_stats[2024]["new_countries"] assert czechia in yearly_stats[2026]["countries"] assert "new_countries" not in yearly_stats[2026]