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

Method test_tzinfo_fromtimestamp

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

Source from the content-addressed store, hash-verified

5351 self.fail("utcnow(), now(tz), or astimezone() may be broken")
5352
5353 def test_tzinfo_fromtimestamp(self):
5354 import time
5355 meth = self.theclass.fromtimestamp
5356 ts = time.time()
5357 # Ensure it doesn't require tzinfo (i.e., that this doesn't blow up).
5358 base = meth(ts)
5359 # Try with and without naming the keyword.
5360 off42 = FixedOffset(42, "42")
5361 another = meth(ts, off42)
5362 again = meth(ts, tz=off42)
5363 self.assertIs(another.tzinfo, again.tzinfo)
5364 self.assertEqual(another.utcoffset(), timedelta(minutes=42))
5365 # Bad argument with and w/o naming the keyword.
5366 self.assertRaises(TypeError, meth, ts, 16)
5367 self.assertRaises(TypeError, meth, ts, tzinfo=16)
5368 # Bad keyword name.
5369 self.assertRaises(TypeError, meth, ts, tinfo=off42)
5370 # Too many args.
5371 self.assertRaises(TypeError, meth, ts, off42, off42)
5372 # Too few args.
5373 self.assertRaises(TypeError, meth)
5374
5375 # Try to make sure tz= actually does some conversion.
5376 timestamp = 1000000000
5377 with self.assertWarns(DeprecationWarning):
5378 utcdatetime = datetime.utcfromtimestamp(timestamp)
5379 # In POSIX (epoch 1970), that's 2001-09-09 01:46:40 UTC, give or take.
5380 # But on some flavor of Mac, it's nowhere near that. So we can't have
5381 # any idea here what time that actually is, we can only test that
5382 # relative changes match.
5383 utcoffset = timedelta(hours=-15, minutes=39) # arbitrary, but not zero
5384 tz = FixedOffset(utcoffset, "tz", 0)
5385 expected = utcdatetime + utcoffset
5386 got = datetime.fromtimestamp(timestamp, tz)
5387 self.assertEqual(expected, got.replace(tzinfo=None))
5388
5389 def test_tzinfo_utcnow(self):
5390 meth = self.theclass.utcnow

Callers

nothing calls this directly

Calls 12

timedeltaClass · 0.90
methFunction · 0.85
FixedOffsetClass · 0.85
assertWarnsMethod · 0.80
timeMethod · 0.45
assertIsMethod · 0.45
assertEqualMethod · 0.45
utcoffsetMethod · 0.45
assertRaisesMethod · 0.45
utcfromtimestampMethod · 0.45
fromtimestampMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected