MCPcopy Index your code
hub / github.com/python/cpython / test_utc_offset_out_of_bounds

Method test_utc_offset_out_of_bounds

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

Source from the content-addressed store, hash-verified

4408 self.assertIs(t.tzinfo, b)
4409
4410 def test_utc_offset_out_of_bounds(self):
4411 class Edgy(tzinfo):
4412 def __init__(self, offset):
4413 self.offset = timedelta(minutes=offset)
4414 def utcoffset(self, dt):
4415 return self.offset
4416
4417 cls = self.theclass
4418 for offset, legit in ((-1440, False),
4419 (-1439, True),
4420 (1439, True),
4421 (1440, False)):
4422 if cls is time:
4423 t = cls(1, 2, 3, tzinfo=Edgy(offset))
4424 elif cls is datetime:
4425 t = cls(6, 6, 6, 1, 2, 3, tzinfo=Edgy(offset))
4426 else:
4427 assert 0, "impossible"
4428 if legit:
4429 aofs = abs(offset)
4430 h, m = divmod(aofs, 60)
4431 tag = "%c%02d:%02d" % (offset < 0 and '-' or '+', h, m)
4432 if isinstance(t, datetime):
4433 t = t.timetz()
4434 self.assertEqual(str(t), "01:02:03" + tag)
4435 else:
4436 self.assertRaises(ValueError, str, t)
4437
4438 def test_tzinfo_classes(self):
4439 cls = self.theclass

Callers

nothing calls this directly

Calls 7

EdgyClass · 0.85
absFunction · 0.85
strFunction · 0.85
timetzMethod · 0.80
clsClass · 0.50
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected