Add comprehensive test coverage for 8 modules
Increases overall test coverage from 53% to 56% by adding tests for: - accommodation.py (60% → 100%) - birthday.py (24% → 100%) - calendar.py (19% → 100%) - carnival.py (33% → 100%) - domains.py (75% → 100%) - events_yaml.py (50% → 96%) - fx.py (14% → 21% for tested functions) - sun.py (55% → 100%) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8db777ae8b
commit
e6327780aa
8 changed files with 1390 additions and 0 deletions
125
tests/test_carnival.py
Normal file
125
tests/test_carnival.py
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
"""Tests for carnival functionality."""
|
||||
|
||||
from datetime import date
|
||||
|
||||
from agenda.carnival import rio_carnival_events
|
||||
from agenda.event import Event
|
||||
|
||||
|
||||
class TestRioCarnivalEvents:
|
||||
"""Test the rio_carnival_events function."""
|
||||
|
||||
def test_carnival_events_single_year(self) -> None:
|
||||
"""Test getting carnival events for a single year."""
|
||||
# 2024 Easter is March 31, so carnival should be around Feb 9-14
|
||||
start_date = date(2024, 1, 1)
|
||||
end_date = date(2024, 12, 31)
|
||||
|
||||
events = rio_carnival_events(start_date, end_date)
|
||||
|
||||
assert len(events) == 1
|
||||
event = events[0]
|
||||
assert event.name == "carnival"
|
||||
assert event.title == "Rio Carnival"
|
||||
assert event.url == "https://en.wikipedia.org/wiki/Rio_Carnival"
|
||||
assert event.date.year == 2024
|
||||
assert event.end_date is not None
|
||||
assert event.end_date.year == 2024
|
||||
# Should be about 51 days before Easter (around early-mid February)
|
||||
assert event.date.month == 2
|
||||
assert event.end_date.month == 2
|
||||
|
||||
def test_carnival_events_multiple_years(self) -> None:
|
||||
"""Test getting carnival events for multiple years."""
|
||||
start_date = date(2023, 1, 1)
|
||||
end_date = date(2025, 12, 31)
|
||||
|
||||
events = rio_carnival_events(start_date, end_date)
|
||||
|
||||
# Should have carnival for 2023, 2024, and 2025
|
||||
assert len(events) == 3
|
||||
|
||||
years = [event.date.year for event in events]
|
||||
assert sorted(years) == [2023, 2024, 2025]
|
||||
|
||||
# All events should be carnival events
|
||||
for event in events:
|
||||
assert event.name == "carnival"
|
||||
assert event.title == "Rio Carnival"
|
||||
assert event.url == "https://en.wikipedia.org/wiki/Rio_Carnival"
|
||||
|
||||
def test_carnival_events_no_overlap(self) -> None:
|
||||
"""Test when date range doesn't overlap with carnival."""
|
||||
# Choose a range that's unlikely to include carnival (summer)
|
||||
start_date = date(2024, 6, 1)
|
||||
end_date = date(2024, 8, 31)
|
||||
|
||||
events = rio_carnival_events(start_date, end_date)
|
||||
|
||||
assert events == []
|
||||
|
||||
def test_carnival_events_partial_overlap_start(self) -> None:
|
||||
"""Test when carnival start overlaps with date range."""
|
||||
# 2024 carnival should be around Feb 9-14
|
||||
start_date = date(2024, 2, 10) # Might overlap with carnival start
|
||||
end_date = date(2024, 2, 15)
|
||||
|
||||
events = rio_carnival_events(start_date, end_date)
|
||||
|
||||
# Should include carnival if there's any overlap
|
||||
if events:
|
||||
assert len(events) == 1
|
||||
assert events[0].name == "carnival"
|
||||
|
||||
def test_carnival_events_partial_overlap_end(self) -> None:
|
||||
"""Test when carnival end overlaps with date range."""
|
||||
# 2024 carnival should be around Feb 9-14
|
||||
start_date = date(2024, 2, 12)
|
||||
end_date = date(2024, 2, 20) # Might overlap with carnival end
|
||||
|
||||
events = rio_carnival_events(start_date, end_date)
|
||||
|
||||
# Should include carnival if there's any overlap
|
||||
if events:
|
||||
assert len(events) == 1
|
||||
assert events[0].name == "carnival"
|
||||
|
||||
def test_carnival_dates_relative_to_easter(self) -> None:
|
||||
"""Test that carnival dates are correctly calculated relative to Easter."""
|
||||
start_date = date(2024, 1, 1)
|
||||
end_date = date(2024, 12, 31)
|
||||
|
||||
events = rio_carnival_events(start_date, end_date)
|
||||
|
||||
assert len(events) == 1
|
||||
event = events[0]
|
||||
|
||||
# Carnival should be 5 days long
|
||||
duration = (event.end_date - event.date).days + 1
|
||||
assert duration == 6 # 51 days before to 46 days before Easter (6 days total)
|
||||
|
||||
# Both dates should be in February for 2024
|
||||
assert event.date.month == 2
|
||||
assert event.end_date.month == 2
|
||||
|
||||
# End date should be after start date
|
||||
assert event.end_date > event.date
|
||||
|
||||
def test_carnival_events_empty_date_range(self) -> None:
|
||||
"""Test with empty date range."""
|
||||
start_date = date(2024, 6, 15)
|
||||
end_date = date(2024, 6, 10) # End before start
|
||||
|
||||
events = rio_carnival_events(start_date, end_date)
|
||||
|
||||
# Should return empty list for invalid range
|
||||
assert events == []
|
||||
|
||||
def test_carnival_events_same_start_end_date(self) -> None:
|
||||
"""Test with same start and end date."""
|
||||
# Pick a date that's definitely not carnival
|
||||
test_date = date(2024, 7, 15)
|
||||
|
||||
events = rio_carnival_events(test_date, test_date)
|
||||
|
||||
assert events == []
|
||||
Loading…
Add table
Add a link
Reference in a new issue