Add docstrings and types

This commit is contained in:
Edward Betts 2024-04-18 11:56:51 +01:00
parent 0fcaf76104
commit b0381db3b5

View file

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