"""Tests for agenda.""" import datetime import json from decimal import Decimal 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.economist import publication_dates 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 def mock_today() -> datetime.date: """Mock the current date for testing purposes.""" return datetime.date(2023, 10, 5) @pytest.fixture def mock_now() -> datetime.datetime: """Mock the current date and time for testing purposes.""" return datetime.datetime(2023, 10, 5, 12, 0, 0) def test_get_mothers_day(mock_today: datetime.date) -> None: """Test get_mothers_day function.""" mothers_day = get_mothers_day(mock_today) # UK Mother's Day 2024 is April 21st (3 weeks after Easter) assert mothers_day == datetime.date(2024, 4, 21) def test_timezone_transition(mock_now: datetime.datetime) -> None: """Test timezone_transition function.""" start = datetime.datetime(2023, 10, 1) end = datetime.datetime(2023, 11, 1) transitions = timezone_transition(start, end, "uk_clock_change", "Europe/London") assert len(transitions) == 1 assert transitions[0].name == "uk_clock_change" assert transitions[0].date.date() == datetime.date(2023, 10, 29) 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 from inspect import signature sig = signature(get_gbpusd) assert len(sig.parameters) == 1 assert "config" in sig.parameters assert sig.return_annotation == Decimal def test_publication_dates(mock_today: datetime.date) -> None: """Test publication_dates function.""" start_date = mock_today end_date = mock_today + datetime.timedelta(days=30) publications = publication_dates(start_date, end_date) assert len(publications) >= 0 # Should return some publications if publications: assert all(pub.name == "economist" for pub in publications) def test_timedelta_display() -> None: """Test timedelta_display function.""" delta = datetime.timedelta(days=2, hours=5, minutes=30) display = timedelta_display(delta) assert display == "2 days 5 hrs 30 mins" def test_format_list_with_ampersand() -> None: """Test format_list_with_ampersand function.""" # Test with multiple items items = ["apple", "banana", "cherry"] result = format_list_with_ampersand(items) assert result == "apple, banana & cherry" # Test with two items items = ["apple", "banana"] result = format_list_with_ampersand(items) assert result == "apple & banana" # Test with single item items = ["apple"] result = format_list_with_ampersand(items) assert result == "apple" # Test with empty list items = [] result = format_list_with_ampersand(items) assert result == "" def test_get_country() -> None: """Test get_country function.""" # Test with valid alpha-2 code country = get_country("US") assert country is not None assert country.name == "United States" # Test with valid alpha-3 code country = get_country("GBR") assert country is not None assert country.name == "United Kingdom" # Test with None country = get_country(None) assert country is None # Test with Kosovo special case country = get_country("xk") assert country is not None assert country.name == "Kosovo" def test_uk_time() -> None: """Test uk_time function.""" test_date = datetime.date(2023, 7, 15) # Summer time test_time = datetime.time(14, 30, 0) result = uk_time(test_date, test_time) assert isinstance(result, datetime.datetime) assert result.date() == test_date assert result.time() == test_time assert result.tzinfo is not None