Various improvements
This commit is contained in:
parent
5f6cb57c2a
commit
bc7a2e89d0
4 changed files with 160 additions and 75 deletions
|
|
@ -7,21 +7,22 @@ from unittest.mock import patch
|
|||
|
||||
import pytest
|
||||
from agenda import format_list_with_ampersand, get_country, uk_time
|
||||
from agenda.data import timezone_transition
|
||||
from agenda.data import event_sort_datetime, timezone_transition
|
||||
from agenda.economist import publication_dates
|
||||
from agenda.event import Event
|
||||
from agenda.fx import get_gbpusd
|
||||
from agenda.holidays import get_all
|
||||
from agenda.uk_holiday import bank_holiday_list, get_mothers_day
|
||||
from agenda.utils import timedelta_display
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture # type: ignore[untyped-decorator]
|
||||
def mock_today() -> datetime.date:
|
||||
"""Mock the current date for testing purposes."""
|
||||
return datetime.date(2023, 10, 5)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture # type: ignore[untyped-decorator]
|
||||
def mock_now() -> datetime.datetime:
|
||||
"""Mock the current date and time for testing purposes."""
|
||||
return datetime.datetime(2023, 10, 5, 12, 0, 0)
|
||||
|
|
@ -44,6 +45,24 @@ def test_timezone_transition(mock_now: datetime.datetime) -> None:
|
|||
assert transitions[0].date.date() == datetime.date(2023, 10, 29)
|
||||
|
||||
|
||||
def test_event_sort_datetime_handles_mixed_timezone_awareness() -> None:
|
||||
"""Event sort keys should be comparable for date, naive, and aware datetimes."""
|
||||
events = [
|
||||
Event(
|
||||
name="aware",
|
||||
date=datetime.datetime(
|
||||
2026, 1, 1, 9, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=1))
|
||||
),
|
||||
),
|
||||
Event(name="date", date=datetime.date(2026, 1, 1)),
|
||||
Event(name="naive", date=datetime.datetime(2026, 1, 1, 8, 30)),
|
||||
]
|
||||
|
||||
sorted_events = sorted(events, key=lambda e: (event_sort_datetime(e), e.name))
|
||||
|
||||
assert [event.name for event in sorted_events] == ["date", "aware", "naive"]
|
||||
|
||||
|
||||
def test_get_gbpusd_function_exists() -> None:
|
||||
"""Test that get_gbpusd function exists and is callable."""
|
||||
# Simple test to verify the function exists and has correct signature
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue