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

Method test_tzinfo_now

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

timedeltaClass · 0.90
timezoneClass · 0.90
methFunction · 0.85
nowMethod · 0.80
assertWarnsMethod · 0.80
utcnowMethod · 0.80
astimezoneMethod · 0.80
FixedOffsetClass · 0.70
absFunction · 0.50
assertIsMethod · 0.45
assertEqualMethod · 0.45
utcoffsetMethod · 0.45

Tested by

no test coverage detected