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

Method test_more_astimezone

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

Source from the content-addressed store, hash-verified

5409 self.assertRaises(ValueError, copy.replace, base, year=2001)
5410
5411 def test_more_astimezone(self):
5412 # The inherited test_astimezone covered some trivial and error cases.
5413 fnone = FixedOffset(None, "None")
5414 f44m = FixedOffset(44, "44")
5415 fm5h = FixedOffset(-timedelta(hours=5), "m300")
5416
5417 dt = self.theclass.now(tz=f44m)
5418 self.assertIs(dt.tzinfo, f44m)
5419 # Replacing with degenerate tzinfo raises an exception.
5420 self.assertRaises(ValueError, dt.astimezone, fnone)
5421 # Replacing with same tzinfo makes no change.
5422 x = dt.astimezone(dt.tzinfo)
5423 self.assertIs(x.tzinfo, f44m)
5424 self.assertEqual(x.date(), dt.date())
5425 self.assertEqual(x.time(), dt.time())
5426
5427 # Replacing with different tzinfo does adjust.
5428 got = dt.astimezone(fm5h)
5429 self.assertIs(got.tzinfo, fm5h)
5430 self.assertEqual(got.utcoffset(), timedelta(hours=-5))
5431 expected = dt - dt.utcoffset() # in effect, convert to UTC
5432 expected += fm5h.utcoffset(dt) # and from there to local time
5433 expected = expected.replace(tzinfo=fm5h) # and attach new tzinfo
5434 self.assertEqual(got.date(), expected.date())
5435 self.assertEqual(got.time(), expected.time())
5436 self.assertEqual(got.timetz(), expected.timetz())
5437 self.assertIs(got.tzinfo, expected.tzinfo)
5438 self.assertEqual(got, expected)
5439
5440 @support.run_with_tz('UTC')
5441 def test_astimezone_default_utc(self):

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected