(self)
| 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 |
nothing calls this directly
no test coverage detected