Refactor time tests

pull/601/head
Nicco Kunzmann 2024-03-17 16:08:30 +00:00
rodzic 7db6b37f25
commit 33298918c6
3 zmienionych plików z 47 dodań i 19 usunięć

Wyświetl plik

@ -0,0 +1,21 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID://RESEARCH IN MOTION//BIS 3.0
METHOD:REQUEST
BEGIN:VEVENT
SEQUENCE:2
X-RIM-REVISION:0
SUMMARY:Test meeting from BB
X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
CLASS:PUBLIC
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="RembrandXS":MAILTO:rembrand@xs4all.nl
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="RembrandDX":MAILTO:rembrand@daxlab.com
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN="RembrandSB":MAILTO:rembspam@xs4all.nl
UID:XRIMCAL-628059586-522954492-9750559
DTSTART;VALUE=DATE:20120814
DTEND;VALUE=DATE:20120815
DESCRIPTION:Test meeting from BB
DTSTAMP:20120813T151458Z
ORGANIZER:mailto:rembrand@daxlab.com
END:VEVENT
END:VCALENDAR

Wyświetl plik

@ -104,3 +104,11 @@ FUZZ_V1 = [os.path.join(CALENDARS_FOLDER, key) for key in os.listdir(CALENDARS_F
def fuzz_v1_calendar(request):
"""Clusterfuzz calendars."""
return request.param
@pytest.fixture()
def x_sometime():
"""Map x_sometime to time"""
icalendar.cal.types_factory.types_map['X-SOMETIME'] = 'time'
yield
icalendar.cal.types_factory.types_map.pop('X-SOMETIME')

Wyświetl plik

@ -1,29 +1,28 @@
import unittest
import datetime
import icalendar
import os
def test_value_type_is_not_mapped():
"""Usually, the value should be absent."""
assert 'X-SOMETIME' not in icalendar.cal.types_factory.types_map
class TestTime(unittest.TestCase):
def setUp(self):
icalendar.cal.types_factory.types_map['X-SOMETIME'] = 'time'
def test_value_type_is_mapped(x_sometime):
"""The value is mapped for the test."""
assert 'X-SOMETIME' in icalendar.cal.types_factory.types_map
def tearDown(self):
icalendar.cal.types_factory.types_map.pop('X-SOMETIME')
def test_create_from_ical(self):
directory = os.path.dirname(__file__)
ics = open(os.path.join(directory, 'calendars', 'time.ics'), 'rb')
cal = icalendar.Calendar.from_ical(ics.read())
ics.close()
def test_create_from_ical(x_sometime):
directory = os.path.dirname(__file__)
ics = open(os.path.join(directory, 'calendars', 'time.ics'), 'rb')
cal = icalendar.Calendar.from_ical(ics.read())
ics.close()
self.assertEqual(cal['X-SOMETIME'].dt, datetime.time(17, 20, 10))
self.assertEqual(cal['X-SOMETIME'].to_ical(), '172010')
assert cal['X-SOMETIME'].dt == datetime.time(17, 20, 10)
assert cal['X-SOMETIME'].to_ical() == '172010'
def test_create_to_ical(self):
cal = icalendar.Calendar()
cal.add('X-SOMETIME', datetime.time(17, 20, 10))
self.assertTrue(b'X-SOMETIME;VALUE=TIME:172010' in
cal.to_ical().splitlines())
def test_create_to_ical(x_sometime):
cal = icalendar.Calendar()
cal.add('X-SOMETIME', datetime.time(17, 20, 10))
assert b'X-SOMETIME;VALUE=TIME:172010' in cal.to_ical().splitlines()