MCPcopy Index your code
hub / github.com/python/cpython / test_isoformat_timezone

Method test_isoformat_timezone

Lib/test/datetimetester.py:2321–2349  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2319 self.assertEqual(t.isoformat(), "0002-03-02T00:00:00+00:00:16")
2320
2321 def test_isoformat_timezone(self):
2322 tzoffsets = [
2323 ('05:00', timedelta(hours=5)),
2324 ('02:00', timedelta(hours=2)),
2325 ('06:27', timedelta(hours=6, minutes=27)),
2326 ('12:32:30', timedelta(hours=12, minutes=32, seconds=30)),
2327 ('02:04:09.123456', timedelta(hours=2, minutes=4, seconds=9, microseconds=123456))
2328 ]
2329
2330 tzinfos = [
2331 ('', None),
2332 ('+00:00', timezone.utc),
2333 ('+00:00', timezone(timedelta(0))),
2334 ]
2335
2336 tzinfos += [
2337 (prefix + expected, timezone(sign * td))
2338 for expected, td in tzoffsets
2339 for prefix, sign in [('-', -1), ('+', 1)]
2340 ]
2341
2342 dt_base = self.theclass(2016, 4, 1, 12, 37, 9)
2343 exp_base = '2016-04-01T12:37:09'
2344
2345 for exp_tz, tzi in tzinfos:
2346 dt = dt_base.replace(tzinfo=tzi)
2347 exp = exp_base + exp_tz
2348 with self.subTest(tzi=tzi):
2349 self.assertEqual(dt.isoformat(), exp)
2350
2351 def test_format(self):
2352 dt = self.theclass(2007, 9, 10, 4, 5, 1, 123)

Callers

nothing calls this directly

Calls 6

timedeltaClass · 0.90
timezoneClass · 0.90
replaceMethod · 0.45
subTestMethod · 0.45
assertEqualMethod · 0.45
isoformatMethod · 0.45

Tested by

no test coverage detected