(self)
| 5126 | self.assertEqual(delta, self.theclass.min - self.theclass.max) |
| 5127 | |
| 5128 | def test_tzinfo_now(self): |
| 5129 | meth = self.theclass.now |
| 5130 | # Ensure it doesn't require tzinfo (i.e., that this doesn't blow up). |
| 5131 | base = meth() |
| 5132 | # Try with and without naming the keyword. |
| 5133 | off42 = FixedOffset(42, "42") |
| 5134 | another = meth(off42) |
| 5135 | again = meth(tz=off42) |
| 5136 | self.assertIs(another.tzinfo, again.tzinfo) |
| 5137 | self.assertEqual(another.utcoffset(), timedelta(minutes=42)) |
| 5138 | # Bad argument with and w/o naming the keyword. |
| 5139 | self.assertRaises(TypeError, meth, 16) |
| 5140 | self.assertRaises(TypeError, meth, tzinfo=16) |
| 5141 | # Bad keyword name. |
| 5142 | self.assertRaises(TypeError, meth, tinfo=off42) |
| 5143 | # Too many args. |
| 5144 | self.assertRaises(TypeError, meth, off42, off42) |
| 5145 | |
| 5146 | # We don't know which time zone we're in, and don't have a tzinfo |
| 5147 | # class to represent it, so seeing whether a tz argument actually |
| 5148 | # does a conversion is tricky. |
| 5149 | utc = FixedOffset(0, "utc", 0) |
| 5150 | for weirdtz in [FixedOffset(timedelta(hours=15, minutes=58), "weirdtz", 0), |
| 5151 | timezone(timedelta(hours=15, minutes=58), "weirdtz"),]: |
| 5152 | for dummy in range(3): |
| 5153 | now = datetime.now(weirdtz) |
| 5154 | self.assertIs(now.tzinfo, weirdtz) |
| 5155 | with self.assertWarns(DeprecationWarning): |
| 5156 | utcnow = datetime.utcnow().replace(tzinfo=utc) |
| 5157 | now2 = utcnow.astimezone(weirdtz) |
| 5158 | if abs(now - now2) < timedelta(seconds=30): |
| 5159 | break |
| 5160 | # Else the code is broken, or more than 30 seconds passed between |
| 5161 | # calls; assuming the latter, just try again. |
| 5162 | else: |
| 5163 | # Three strikes and we're out. |
| 5164 | self.fail("utcnow(), now(tz), or astimezone() may be broken") |
| 5165 | |
| 5166 | def test_tzinfo_fromtimestamp(self): |
| 5167 | import time |
nothing calls this directly
no test coverage detected