kopia lustrzana https://github.com/jazzband/icalevents
Remove tests
Remove tests for methods, that have been removed. Use dateutil timezones instead of pytz timezones.pull/29/head
rodzic
c53f4716cd
commit
8c7390dc3b
|
@ -1,8 +1,7 @@
|
|||
import unittest
|
||||
import icalevents.icalparser
|
||||
from datetime import datetime, date
|
||||
from pytz import utc, timezone
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from dateutil.tz import UTC, gettz
|
||||
|
||||
|
||||
class ICalParserTests(unittest.TestCase):
|
||||
|
@ -10,20 +9,20 @@ class ICalParserTests(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.eventA = icalevents.icalparser.Event()
|
||||
self.eventA.uid = 1234
|
||||
self.eventA.start = datetime(year=2017, month=2, day=3, hour=12, minute=5, tzinfo=utc)
|
||||
self.eventA.end = datetime(year=2017, month=2, day=3, hour=15, minute=5, tzinfo=utc)
|
||||
self.eventA.start = datetime(year=2017, month=2, day=3, hour=12, minute=5, tzinfo=UTC)
|
||||
self.eventA.end = datetime(year=2017, month=2, day=3, hour=15, minute=5, tzinfo=UTC)
|
||||
self.eventA.all_day = False
|
||||
self.eventA.summary = "Event A"
|
||||
|
||||
self.eventB = icalevents.icalparser.Event()
|
||||
self.eventB.uid = 1234
|
||||
self.eventB.start = datetime(year=2017, month=2, day=1, hour=15, minute=5, tzinfo=utc)
|
||||
self.eventB.end = datetime(year=2017, month=2, day=1, hour=16, minute=5, tzinfo=utc)
|
||||
self.eventB.start = datetime(year=2017, month=2, day=1, hour=15, minute=5, tzinfo=UTC)
|
||||
self.eventB.end = datetime(year=2017, month=2, day=1, hour=16, minute=5, tzinfo=UTC)
|
||||
self.eventB.all_day = False
|
||||
self.eventB.summary = "Event B"
|
||||
|
||||
self.dtA = datetime(2018, 6, 21, 12)
|
||||
self.dtB = timezone('Europe/Berlin').localize(datetime(2018, 6, 21 ,12))
|
||||
self.dtB = datetime(2018, 6, 21, 12, tzinfo=gettz('Europe/Berlin'))
|
||||
|
||||
def test_now(self):
|
||||
n = icalevents.icalparser.now()
|
||||
|
@ -32,13 +31,13 @@ class ICalParserTests(unittest.TestCase):
|
|||
self.assertTrue(n.tzinfo, "result of now has a timezone info")
|
||||
|
||||
def test_time_left(self):
|
||||
dt = datetime(year=2017, month=2, day=2, hour=11, minute=2, tzinfo=utc)
|
||||
dt = datetime(year=2017, month=2, day=2, hour=11, minute=2, tzinfo=UTC)
|
||||
time_left = self.eventA.time_left(time=dt)
|
||||
self.assertEqual(time_left.days, 1)
|
||||
self.assertEqual(time_left.seconds, 3780)
|
||||
|
||||
def test_event_copy_to(self):
|
||||
new_start = utc.normalize(datetime(year=2017, month=2, day=5, hour=12, minute=5, tzinfo=utc))
|
||||
new_start = datetime(year=2017, month=2, day=5, hour=12, minute=5, tzinfo=UTC)
|
||||
eventC = self.eventA.copy_to(new_start)
|
||||
|
||||
self.assertNotEqual(eventC.uid, self.eventA.uid, "new event has new UID")
|
||||
|
@ -59,30 +58,6 @@ class ICalParserTests(unittest.TestCase):
|
|||
def test_event_order(self):
|
||||
self.assertTrue(self.eventA > self.eventB, "order of events")
|
||||
|
||||
def test_next_year(self):
|
||||
date = utc.normalize(datetime(year=2016, month=1, day=1, hour=0, minute=0, tzinfo=utc))
|
||||
|
||||
other = icalevents.icalparser.next_year_at(date, count=2)
|
||||
|
||||
self.assertEqual(date.year + 2, other.year, "year is changed")
|
||||
self.assertEqual(date.month, other.month, "month is same")
|
||||
self.assertEqual(date.day, other.day, "day is same")
|
||||
self.assertEqual(date.hour, other.hour, "hour is same")
|
||||
self.assertEqual(date.minute, other.minute, "minute is same")
|
||||
self.assertEqual(date.tzinfo, other.tzinfo, "timezone is same")
|
||||
|
||||
def test_next_month(self):
|
||||
dt = utc.normalize(datetime(year=2016, month=10, day=1, hour=0, minute=0, tzinfo=utc))
|
||||
|
||||
other = icalevents.icalparser.next_month_at(dt, count=5)
|
||||
|
||||
self.assertEqual(2017, other.year, "year is same")
|
||||
self.assertEqual(3, other.month, "month is changed")
|
||||
self.assertEqual(dt.day, other.day, "day is same")
|
||||
self.assertEqual(dt.hour, other.hour, "hour is same")
|
||||
self.assertEqual(dt.minute, other.minute, "minute is same")
|
||||
self.assertEqual(dt.tzinfo, other.tzinfo, "timezone is same")
|
||||
|
||||
def test_normalize(self):
|
||||
dt = date(year=2016, month=11, day=13)
|
||||
norm = icalevents.icalparser.normalize(dt)
|
||||
|
@ -95,7 +70,7 @@ class ICalParserTests(unittest.TestCase):
|
|||
self.assertEqual(0, norm.minute, "minute")
|
||||
self.assertEqual(0, norm.second, "second")
|
||||
self.assertEqual(0, norm.microsecond, "microsecond")
|
||||
self.assertEqual(utc, norm.tzinfo, "timezone")
|
||||
self.assertEqual(UTC, norm.tzinfo, "timezone")
|
||||
|
||||
dt = datetime(year=2016, month=11, day=13, hour=1, minute=2, second=3)
|
||||
norm = icalevents.icalparser.normalize(dt)
|
||||
|
@ -108,49 +83,4 @@ class ICalParserTests(unittest.TestCase):
|
|||
self.assertEqual(2, norm.minute, "minute")
|
||||
self.assertEqual(3, norm.second, "second")
|
||||
self.assertEqual(0, norm.microsecond, "microsecond")
|
||||
self.assertEqual(utc, norm.tzinfo, "timezone")
|
||||
|
||||
def test_in_range(self):
|
||||
range_start = datetime(year=2017, month=2, day=2, hour=12, minute=0, tzinfo=utc)
|
||||
range_end = datetime(year=2017, month=2, day=4, hour=12, minute=0, tzinfo=utc)
|
||||
|
||||
events = [self.eventA, self.eventB]
|
||||
|
||||
filtered = icalevents.icalparser.in_range(events, range_start, range_end)
|
||||
|
||||
self.assertEqual(len(filtered), 1, "one event is left")
|
||||
self.assertEqual(filtered[0], self.eventA, "event A is left")
|
||||
|
||||
def test_generate_day_deltas_by_weekday(self):
|
||||
by_day = {'MO', 'WE', 'SU'}
|
||||
result = icalevents.icalparser.generate_day_deltas_by_weekday(by_day)
|
||||
|
||||
self.assertEqual(2, result[0], 'Mon to Wed')
|
||||
self.assertEqual(4, result[2], 'Wed to Sun')
|
||||
self.assertEqual(1, result[6], 'Sun to Mon')
|
||||
|
||||
by_day = {'MO'}
|
||||
result = icalevents.icalparser.generate_day_deltas_by_weekday(by_day)
|
||||
|
||||
self.assertEqual(7, result[0], 'Mon to Mon')
|
||||
|
||||
def test_next_month_byday_delta(self):
|
||||
dt = date(2018, 9, 15)
|
||||
|
||||
result = icalevents.icalparser.next_month_byday_delta(dt, "3SA")
|
||||
self.assertEqual(date(2018, 10, 20), result, '3rd Saturday next month')
|
||||
|
||||
result = icalevents.icalparser.next_month_byday_delta(dt, "2TU")
|
||||
self.assertEqual(date(2018, 10, 9), result, '2nd Tuesday next month')
|
||||
|
||||
with self.assertRaises(ValueError, msg='Invalid weekday'):
|
||||
icalevents.icalparser.next_month_byday_delta(dt, "1ZZ")
|
||||
|
||||
def test_adjust_dst(self):
|
||||
shift = relativedelta(months=12)
|
||||
|
||||
shiftedA = self.dtA + shift
|
||||
self.assertEqual(self.dtA.hour, icalevents.icalparser.adjust_dst(shiftedA).hour, "DST adjustment on naive datetime.")
|
||||
|
||||
shiftedB = self.dtB + shift
|
||||
self.assertEqual(self.dtB.hour, icalevents.icalparser.adjust_dst(shiftedB).hour, "DST adjustment on timezone aware datetime.")
|
||||
self.assertEqual(UTC, norm.tzinfo, "timezone")
|
||||
|
|
Ładowanie…
Reference in New Issue