Merge pull request #601 from niccokunzmann/refactor-test-5

Refactor time tests
pull/606/head^2
Jaca 2024-03-26 10:12:02 +01:00 zatwierdzone przez GitHub
commit a39369533f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 26 dodań i 19 usunięć

Wyświetl plik

@ -109,6 +109,14 @@ def fuzz_v1_calendar(request):
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')
@pytest.fixture()
def factory():
"""Return a new component factory."""

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()