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

Method test_tzinfo_timetuple

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

Source from the content-addressed store, hash-verified

5413 self.assertRaises(TypeError, meth, ts, tzinfo=off42)
5414
5415 def test_tzinfo_timetuple(self):
5416 # TestDateTime tested most of this. datetime adds a twist to the
5417 # DST flag.
5418 class DST(tzinfo):
5419 def __init__(self, dstvalue):
5420 if isinstance(dstvalue, int):
5421 dstvalue = timedelta(minutes=dstvalue)
5422 self.dstvalue = dstvalue
5423 def dst(self, dt):
5424 return self.dstvalue
5425
5426 cls = self.theclass
5427 for dstvalue, flag in (-33, 1), (33, 1), (0, 0), (None, -1):
5428 d = cls(1, 1, 1, 10, 20, 30, 40, tzinfo=DST(dstvalue))
5429 t = d.timetuple()
5430 self.assertEqual(1, t.tm_year)
5431 self.assertEqual(1, t.tm_mon)
5432 self.assertEqual(1, t.tm_mday)
5433 self.assertEqual(10, t.tm_hour)
5434 self.assertEqual(20, t.tm_min)
5435 self.assertEqual(30, t.tm_sec)
5436 self.assertEqual(0, t.tm_wday)
5437 self.assertEqual(1, t.tm_yday)
5438 self.assertEqual(flag, t.tm_isdst)
5439
5440 # dst() returns wrong type.
5441 self.assertRaises(TypeError, cls(1, 1, 1, tzinfo=DST("x")).timetuple)
5442
5443 # dst() at the edge.
5444 self.assertEqual(cls(1,1,1, tzinfo=DST(1439)).timetuple().tm_isdst, 1)
5445 self.assertEqual(cls(1,1,1, tzinfo=DST(-1439)).timetuple().tm_isdst, 1)
5446
5447 # dst() out of range.
5448 self.assertRaises(ValueError, cls(1,1,1, tzinfo=DST(1440)).timetuple)
5449 self.assertRaises(ValueError, cls(1,1,1, tzinfo=DST(-1440)).timetuple)
5450
5451 def test_utctimetuple(self):
5452 class DST(tzinfo):

Callers

nothing calls this directly

Calls 5

DSTClass · 0.85
clsClass · 0.50
timetupleMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected