MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_fromutc

Method test_fromutc

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

Source from the content-addressed store, hash-verified

6348 self.assertEqual(dt_winter.replace(fold=1).utcoffset(), -5 * HOUR)
6349
6350 def test_fromutc(self):
6351 # Let's first establish that things work in regular times.
6352 u_summer = datetime(2002, 10, 27, 6, tzinfo=Eastern2) - timedelta.resolution
6353 u_winter = datetime(2002, 10, 27, 7, tzinfo=Eastern2)
6354 t_summer = Eastern2.fromutc(u_summer)
6355 t_winter = Eastern2.fromutc(u_winter)
6356 self.assertEqual(t_summer, u_summer - 4 * HOUR)
6357 self.assertEqual(t_winter, u_winter - 5 * HOUR)
6358 self.assertEqual(t_summer.fold, 0)
6359 self.assertEqual(t_winter.fold, 0)
6360
6361 # What happens in the fall-back fold?
6362 u = datetime(2002, 10, 27, 5, 30, tzinfo=Eastern2)
6363 t0 = Eastern2.fromutc(u)
6364 u += HOUR
6365 t1 = Eastern2.fromutc(u)
6366 self.assertEqual(t0, t1)
6367 self.assertEqual(t0.fold, 0)
6368 self.assertEqual(t1.fold, 1)
6369 # The tricky part is when u is in the local fold:
6370 u = datetime(2002, 10, 27, 1, 30, tzinfo=Eastern2)
6371 t = Eastern2.fromutc(u)
6372 self.assertEqual((t.day, t.hour), (26, 21))
6373 # .. or gets into the local fold after a standard time adjustment
6374 u = datetime(2002, 10, 27, 6, 30, tzinfo=Eastern2)
6375 t = Eastern2.fromutc(u)
6376 self.assertEqual((t.day, t.hour), (27, 1))
6377
6378 # What happens in the spring-forward gap?
6379 u = datetime(2002, 4, 7, 2, 0, tzinfo=Eastern2)
6380 t = Eastern2.fromutc(u)
6381 self.assertEqual((t.day, t.hour), (6, 21))
6382
6383 def test_mixed_compare_regular(self):
6384 t = datetime(2000, 1, 1, tzinfo=Eastern2)

Callers

nothing calls this directly

Calls 3

datetimeClass · 0.90
fromutcMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected