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

Method test_tzinfo_fromtimestamp

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

Source from the content-addressed store, hash-verified

5164 self.fail("utcnow(), now(tz), or astimezone() may be broken")
5165
5166 def test_tzinfo_fromtimestamp(self):
5167 import time
5168 meth = self.theclass.fromtimestamp
5169 ts = time.time()
5170 # Ensure it doesn't require tzinfo (i.e., that this doesn't blow up).
5171 base = meth(ts)
5172 # Try with and without naming the keyword.
5173 off42 = FixedOffset(42, "42")
5174 another = meth(ts, off42)
5175 again = meth(ts, tz=off42)
5176 self.assertIs(another.tzinfo, again.tzinfo)
5177 self.assertEqual(another.utcoffset(), timedelta(minutes=42))
5178 # Bad argument with and w/o naming the keyword.
5179 self.assertRaises(TypeError, meth, ts, 16)
5180 self.assertRaises(TypeError, meth, ts, tzinfo=16)
5181 # Bad keyword name.
5182 self.assertRaises(TypeError, meth, ts, tinfo=off42)
5183 # Too many args.
5184 self.assertRaises(TypeError, meth, ts, off42, off42)
5185 # Too few args.
5186 self.assertRaises(TypeError, meth)
5187
5188 # Try to make sure tz= actually does some conversion.
5189 timestamp = 1000000000
5190 with self.assertWarns(DeprecationWarning):
5191 utcdatetime = datetime.utcfromtimestamp(timestamp)
5192 # In POSIX (epoch 1970), that's 2001-09-09 01:46:40 UTC, give or take.
5193 # But on some flavor of Mac, it's nowhere near that. So we can't have
5194 # any idea here what time that actually is, we can only test that
5195 # relative changes match.
5196 utcoffset = timedelta(hours=-15, minutes=39) # arbitrary, but not zero
5197 tz = FixedOffset(utcoffset, "tz", 0)
5198 expected = utcdatetime + utcoffset
5199 got = datetime.fromtimestamp(timestamp, tz)
5200 self.assertEqual(expected, got.replace(tzinfo=None))
5201
5202 def test_tzinfo_utcnow(self):
5203 meth = self.theclass.utcnow

Callers

nothing calls this directly

Calls 12

timedeltaClass · 0.90
methFunction · 0.85
assertWarnsMethod · 0.80
FixedOffsetClass · 0.70
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