def test_vtimezone_creation(self): tzs = dateutil.tz.tzical("test_files/timezones.ics") pacific = icalendar.TimezoneComponent(tzs.get('US/Pacific')) self.assertEqual(str(pacific), "<VTIMEZONE | <TZID{}US/Pacific>>") santiago = icalendar.TimezoneComponent(tzs.get('Santiago')) self.assertEqual(str(santiago), "<VTIMEZONE | <TZID{}Santiago>>") for year in range(2001, 2010): for month in (2, 9): dt = datetime.datetime(year, month, 15, tzinfo=tzs.get('Santiago')) #if dt.replace(tzinfo=tzs.get('Santiago')) != dt: self.assertTrue(dt.replace(tzinfo=tzs.get('Santiago')), dt)
def test_pytz_timezone_serializing(self): """ Serializing with timezones from pytz test """ try: import pytz except ImportError: return self.skipTest("pytz not installed") # NOQA # Avoid conflicting cached tzinfo from other tests def unregister_tzid(tzid): """Clear tzid from icalendar TZID registry""" if icalendar.getTzid(tzid, False): icalendar.registerTzid(tzid, None) unregister_tzid('US/Eastern') eastern = pytz.timezone('US/Eastern') cal = base.Component('VCALENDAR') cal.setBehavior(icalendar.VCalendar2_0) ev = cal.add('vevent') ev.add('dtstart').value = eastern.localize( datetime.datetime(2008, 10, 12, 9)) serialized = cal.serialize() expected_vtimezone = get_test_file("tz_us_eastern.ics") self.assertIn(expected_vtimezone.replace('\r\n', '\n'), serialized.replace('\r\n', '\n')) # Exhaustively test all zones (just looking for no errors) for tzname in pytz.all_timezones: unregister_tzid(tzname) tz = icalendar.TimezoneComponent(tzinfo=pytz.timezone(tzname)) tz.serialize()