| 2084 | |
| 2085 | |
| 2086 | class TZTest(unittest.TestCase): |
| 2087 | def testFileStart1(self): |
| 2088 | tzc = tz.tzfile(BytesIO(base64.b64decode(TZFILE_EST5EDT))) |
| 2089 | self.assertEqual(datetime(2003, 4, 6, 1, 59, tzinfo=tzc).tzname(), "EST") |
| 2090 | self.assertEqual( |
| 2091 | tz.enfold(datetime(2003, 4, 6, 2, 0, tzinfo=tzc), fold=0).tzname(), |
| 2092 | "EST", |
| 2093 | ) |
| 2094 | self.assertEqual( |
| 2095 | tz.enfold(datetime(2003, 4, 6, 2, 0, tzinfo=tzc), fold=1).tzname(), |
| 2096 | "EDT", |
| 2097 | ) |
| 2098 | self.assertEqual(datetime(2003, 4, 6, 3, 0, tzinfo=tzc).tzname(), "EDT") |
| 2099 | |
| 2100 | def testFileEnd1(self): |
| 2101 | tzc = tz.tzfile(BytesIO(base64.b64decode(TZFILE_EST5EDT))) |
| 2102 | self.assertEqual( |
| 2103 | datetime(2003, 10, 26, 0, 59, tzinfo=tzc).tzname(), "EDT" |
| 2104 | ) |
| 2105 | end_est = tz.enfold(datetime(2003, 10, 26, 1, 0, tzinfo=tzc)) |
| 2106 | self.assertEqual(end_est.tzname(), "EST") |
| 2107 | |
| 2108 | def testFileLastTransition(self): |
| 2109 | # After the last transition, it goes to standard time in perpetuity |
| 2110 | tzc = tz.tzfile(BytesIO(base64.b64decode(TZFILE_EST5EDT))) |
| 2111 | self.assertEqual(datetime(2037, 10, 25, 0, 59, tzinfo=tzc).tzname(), |
| 2112 | "EDT") |
| 2113 | |
| 2114 | last_date = tz.enfold(datetime(2037, 10, 25, 1, 0, tzinfo=tzc), fold=1) |
| 2115 | self.assertEqual(last_date.tzname(), "EST") |
| 2116 | |
| 2117 | self.assertEqual(datetime(2038, 5, 25, 12, 0, tzinfo=tzc).tzname(), |
| 2118 | "EST") |
| 2119 | |
| 2120 | def testInvalidFile(self): |
| 2121 | # Should throw a ValueError if an invalid file is passed |
| 2122 | with self.assertRaises(ValueError): |
| 2123 | tz.tzfile(BytesIO(b'BadFile')) |
| 2124 | |
| 2125 | def testFilestreamWithNameRepr(self): |
| 2126 | # If fileobj is a filestream with a "name" attribute this name should |
| 2127 | # be reflected in the tz object's repr |
| 2128 | fileobj = BytesIO(base64.b64decode(TZFILE_EST5EDT)) |
| 2129 | fileobj.name = 'foo' |
| 2130 | tzc = tz.tzfile(fileobj) |
| 2131 | self.assertEqual(repr(tzc), 'tzfile(' + repr('foo') + ')') |
| 2132 | |
| 2133 | def testLeapCountDecodesProperly(self): |
| 2134 | # This timezone has leapcnt, and failed to decode until |
| 2135 | # Eugene Oden notified about the issue. |
| 2136 | |
| 2137 | # As leap information is currently unused (and unstored) by tzfile() we |
| 2138 | # can only indirectly test this: Take advantage of tzfile() not closing |
| 2139 | # the input file if handed in as an opened file and assert that the |
| 2140 | # full file content has been read by tzfile(). Note: For this test to |
| 2141 | # work NEW_YORK must be in TZif version 1 format i.e. no more data |
| 2142 | # after TZif v1 header + data has been read |
| 2143 | fileobj = BytesIO(base64.b64decode(NEW_YORK)) |
nothing calls this directly
no outgoing calls
no test coverage detected