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

Method test_subclass_datetime

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

Source from the content-addressed store, hash-verified

3303 dt_broken.astimezone()
3304
3305 def test_subclass_datetime(self):
3306
3307 class C(self.theclass):
3308 theAnswer = 42
3309
3310 def __new__(cls, *args, **kws):
3311 temp = kws.copy()
3312 extra = temp.pop('extra')
3313 result = self.theclass.__new__(cls, *args, **temp)
3314 result.extra = extra
3315 return result
3316
3317 def newmeth(self, start):
3318 return start + self.year + self.month + self.second
3319
3320 args = 2003, 4, 14, 12, 13, 41
3321
3322 dt1 = self.theclass(*args)
3323 dt2 = C(*args, **{'extra': 7})
3324
3325 self.assertEqual(dt2.__class__, C)
3326 self.assertEqual(dt2.theAnswer, 42)
3327 self.assertEqual(dt2.extra, 7)
3328 self.assertEqual(dt1.toordinal(), dt2.toordinal())
3329 self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month +
3330 dt1.second - 7)
3331
3332 def test_subclass_alternate_constructors_datetime(self):
3333 # Test that alternate constructors call the constructor

Callers

nothing calls this directly

Calls 4

newmethMethod · 0.95
toordinalMethod · 0.80
CClass · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected