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

Method test_more_astimezone

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

Source from the content-addressed store, hash-verified

5596 self.assertRaises(ValueError, copy.replace, base, year=2001)
5597
5598 def test_more_astimezone(self):
5599 # The inherited test_astimezone covered some trivial and error cases.
5600 fnone = FixedOffset(None, "None")
5601 f44m = FixedOffset(44, "44")
5602 fm5h = FixedOffset(-timedelta(hours=5), "m300")
5603
5604 dt = self.theclass.now(tz=f44m)
5605 self.assertIs(dt.tzinfo, f44m)
5606 # Replacing with degenerate tzinfo raises an exception.
5607 self.assertRaises(ValueError, dt.astimezone, fnone)
5608 # Replacing with same tzinfo makes no change.
5609 x = dt.astimezone(dt.tzinfo)
5610 self.assertIs(x.tzinfo, f44m)
5611 self.assertEqual(x.date(), dt.date())
5612 self.assertEqual(x.time(), dt.time())
5613
5614 # Replacing with different tzinfo does adjust.
5615 got = dt.astimezone(fm5h)
5616 self.assertIs(got.tzinfo, fm5h)
5617 self.assertEqual(got.utcoffset(), timedelta(hours=-5))
5618 expected = dt - dt.utcoffset() # in effect, convert to UTC
5619 expected += fm5h.utcoffset(dt) # and from there to local time
5620 expected = expected.replace(tzinfo=fm5h) # and attach new tzinfo
5621 self.assertEqual(got.date(), expected.date())
5622 self.assertEqual(got.time(), expected.time())
5623 self.assertEqual(got.timetz(), expected.timetz())
5624 self.assertIs(got.tzinfo, expected.tzinfo)
5625 self.assertEqual(got, expected)
5626
5627 @support.run_with_tz('UTC')
5628 def test_astimezone_default_utc(self):

Callers

nothing calls this directly

Calls 13

utcoffsetMethod · 0.95
timedeltaClass · 0.90
FixedOffsetClass · 0.85
nowMethod · 0.80
astimezoneMethod · 0.80
dateMethod · 0.80
timetzMethod · 0.80
assertIsMethod · 0.45
assertRaisesMethod · 0.45
assertEqualMethod · 0.45
timeMethod · 0.45
utcoffsetMethod · 0.45

Tested by

no test coverage detected