Skip to content

Commit

Permalink
Update test to use a fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
allenporter authored and N-Coder committed Jun 5, 2022
1 parent afb8755 commit ecf96e4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tests/issues/gh251.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import datetime, timedelta

import pytest

from ics import Calendar, Event, __version__
from ics.event import deterministic_event_data, default_uid_factory, default_dtstamp_factory
from ics.timezone import UTC
Expand Down Expand Up @@ -36,7 +38,7 @@
""".strip().replace("\n", "\r\n")


def make_calendar():
def make_calendar() -> Calendar:
cal = Calendar()
cal.events.append(Event("second", datetime(2000, 2, 1, 12, 0)))
cal.events.append(Event("fourth", datetime(2000, 4, 1, 12, 0)))
Expand All @@ -45,8 +47,13 @@ def make_calendar():
return cal


def test_chronological_order():
cal = make_calendar()
@pytest.fixture(name="cal")
def calendar() -> Calendar:
"""Fixture Calendar for tests."""
return make_calendar()


def test_chronological_order(cal: Calendar) -> None:
assert [e.summary for e in cal.events] == ["second", "fourth", "third", "first"]

cal.events = sorted(cal.events)
Expand All @@ -57,8 +64,7 @@ def test_chronological_order():


@deterministic_event_data
def test_deterministic_events_deco():
cal = make_calendar()
def test_deterministic_events_deco(cal: Calendar) -> None:
uid = default_uid_factory.get()()
dtstamp = default_dtstamp_factory.get()().strftime("%Y%m%dT%H%M%SZ")
assert cal.serialize().strip() == CALENDAR.format(uid=uid, dtstamp=dtstamp, version=__version__)
Expand Down

0 comments on commit ecf96e4

Please sign in to comment.