Fix trip stats new-country counting
This commit is contained in:
parent
91a74fd887
commit
8a0df48a73
5 changed files with 61 additions and 18 deletions
29
tests/test_trip_stats.py
Normal file
29
tests/test_trip_stats.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"""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]
|
||||
Loading…
Add table
Add a link
Reference in a new issue