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

Method test_tzinfo_classes

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

Source from the content-addressed store, hash-verified

4253 self.assertRaises(ValueError, str, t)
4254
4255 def test_tzinfo_classes(self):
4256 cls = self.theclass
4257 class C1(tzinfo):
4258 def utcoffset(self, dt): return None
4259 def dst(self, dt): return None
4260 def tzname(self, dt): return None
4261 for t in (cls(1, 1, 1),
4262 cls(1, 1, 1, tzinfo=None),
4263 cls(1, 1, 1, tzinfo=C1())):
4264 self.assertIsNone(t.utcoffset())
4265 self.assertIsNone(t.dst())
4266 self.assertIsNone(t.tzname())
4267
4268 class C3(tzinfo):
4269 def utcoffset(self, dt): return timedelta(minutes=-1439)
4270 def dst(self, dt): return timedelta(minutes=1439)
4271 def tzname(self, dt): return "aname"
4272 t = cls(1, 1, 1, tzinfo=C3())
4273 self.assertEqual(t.utcoffset(), timedelta(minutes=-1439))
4274 self.assertEqual(t.dst(), timedelta(minutes=1439))
4275 self.assertEqual(t.tzname(), "aname")
4276
4277 # Wrong types.
4278 class C4(tzinfo):
4279 def utcoffset(self, dt): return "aname"
4280 def dst(self, dt): return 7
4281 def tzname(self, dt): return 0
4282 t = cls(1, 1, 1, tzinfo=C4())
4283 self.assertRaises(TypeError, t.utcoffset)
4284 self.assertRaises(TypeError, t.dst)
4285 self.assertRaises(TypeError, t.tzname)
4286
4287 # Offset out of range.
4288 class C6(tzinfo):
4289 def utcoffset(self, dt): return timedelta(hours=-24)
4290 def dst(self, dt): return timedelta(hours=24)
4291 t = cls(1, 1, 1, tzinfo=C6())
4292 self.assertRaises(ValueError, t.utcoffset)
4293 self.assertRaises(ValueError, t.dst)
4294
4295 # Not a whole number of seconds.
4296 class C7(tzinfo):
4297 def utcoffset(self, dt): return timedelta(microseconds=61)
4298 def dst(self, dt): return timedelta(microseconds=-81)
4299 t = cls(1, 1, 1, tzinfo=C7())
4300 self.assertEqual(t.utcoffset(), timedelta(microseconds=61))
4301 self.assertEqual(t.dst(), timedelta(microseconds=-81))
4302
4303 def test_aware_compare(self):
4304 cls = self.theclass

Callers

nothing calls this directly

Calls 13

timedeltaClass · 0.90
assertIsNoneMethod · 0.80
C1Class · 0.70
C3Class · 0.70
C4Class · 0.70
C6Class · 0.70
C7Class · 0.70
clsClass · 0.50
utcoffsetMethod · 0.45
dstMethod · 0.45
tznameMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected