agenda/tests/test_agenda.py

83 lines
2.5 KiB
Python
Raw Normal View History

2024-04-18 11:56:51 +01:00
"""Tests for agenda."""
2023-10-06 17:54:38 +01:00
import datetime
from decimal import Decimal
import pytest
from agenda import (
get_gbpusd,
get_next_bank_holiday,
get_next_timezone_transition,
next_economist,
next_uk_fathers_day,
next_uk_mothers_day,
timedelta_display,
uk_financial_year_end,
)
@pytest.fixture
2024-04-18 11:56:51 +01:00
def mock_today() -> datetime.date:
"""Mock the current date for testing purposes."""
2023-10-06 17:54:38 +01:00
return datetime.date(2023, 10, 5)
@pytest.fixture
2024-04-18 11:56:51 +01:00
def mock_now() -> datetime.datetime:
"""Mock the current date and time for testing purposes."""
2023-10-06 17:54:38 +01:00
return datetime.datetime(2023, 10, 5, 12, 0, 0)
2024-04-18 11:56:51 +01:00
def test_next_uk_mothers_day(mock_today: datetime.date) -> None:
"""Test next_uk_mothers_day function."""
2023-10-06 17:54:38 +01:00
next_mothers_day = next_uk_mothers_day(mock_today)
assert next_mothers_day == datetime.date(2024, 4, 21)
2024-04-18 11:56:51 +01:00
def test_next_uk_fathers_day(mock_today: datetime.date) -> None:
"""Test next_uk_fathers_day function."""
2023-10-06 17:54:38 +01:00
next_fathers_day = next_uk_fathers_day(mock_today)
assert next_fathers_day == datetime.date(2024, 6, 21)
2024-04-18 11:56:51 +01:00
def test_get_next_timezone_transition(mock_now: datetime.date) -> None:
"""Test get_next_timezone_transition function."""
2023-10-06 17:54:38 +01:00
next_transition = get_next_timezone_transition(mock_now, "Europe/London")
assert next_transition == datetime.date(2023, 10, 29)
2024-04-18 11:56:51 +01:00
def test_get_next_bank_holiday(mock_today: datetime.date) -> None:
"""Test get_next_bank_holiday function."""
2023-10-11 16:04:35 +01:00
next_holiday = get_next_bank_holiday(mock_today)[0]
assert next_holiday.date == datetime.date(2023, 12, 25)
assert next_holiday.title == "Christmas Day"
2023-10-06 17:54:38 +01:00
2024-04-18 11:56:51 +01:00
def test_get_gbpusd(mock_now: datetime.datetime) -> None:
"""Test get_gbpusd function."""
2023-10-11 16:04:35 +01:00
gbpusd = get_gbpusd()
2023-10-06 17:54:38 +01:00
assert isinstance(gbpusd, Decimal)
# You can add more assertions based on your specific use case.
2024-04-18 11:56:51 +01:00
def test_next_economist(mock_today: datetime.date) -> None:
"""Test next_economist function."""
2023-10-06 17:54:38 +01:00
next_publication = next_economist(mock_today)
assert next_publication == datetime.date(2023, 10, 5)
2024-04-18 11:56:51 +01:00
def test_uk_financial_year_end() -> None:
"""Test uk_financial_year_end function."""
2023-10-06 17:54:38 +01:00
financial_year_end = uk_financial_year_end(datetime.date(2023, 4, 1))
assert financial_year_end == datetime.date(2023, 4, 5)
2024-04-18 11:56:51 +01:00
def test_timedelta_display() -> None:
"""Test timedelta_display function."""
2023-10-06 17:54:38 +01:00
delta = datetime.timedelta(days=2, hours=5, minutes=30)
display = timedelta_display(delta)
assert display == " 2 days 5 hrs 30 mins"
# You can add more test cases for other functions as needed.