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

Method test_subclass_now

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

Source from the content-addressed store, hash-verified

3383 self.assertEqual(dt.extra, 7)
3384
3385 def test_subclass_now(self):
3386 # Test that alternate constructors call the constructor
3387 class DateTimeSubclass(self.theclass):
3388 def __new__(cls, *args, **kwargs):
3389 result = self.theclass.__new__(cls, *args, **kwargs)
3390 result.extra = 7
3391
3392 return result
3393
3394 test_cases = [
3395 ('now', 'now', {}),
3396 ('utcnow', 'utcnow', {}),
3397 ('now_utc', 'now', {'tz': timezone.utc}),
3398 ('now_fixed', 'now', {'tz': timezone(timedelta(hours=-5), "EST")}),
3399 ]
3400
3401 for name, meth_name, kwargs in test_cases:
3402 with self.subTest(name):
3403 constr = getattr(DateTimeSubclass, meth_name)
3404 if meth_name == "utcnow":
3405 with self.assertWarns(DeprecationWarning):
3406 dt = constr(**kwargs)
3407 else:
3408 dt = constr(**kwargs)
3409
3410 self.assertIsInstance(dt, DateTimeSubclass)
3411 self.assertEqual(dt.extra, 7)
3412
3413 def test_subclass_replace_fold(self):
3414 class DateTimeSubclass(self.theclass):

Callers

nothing calls this directly

Calls 6

timezoneClass · 0.90
timedeltaClass · 0.90
assertWarnsMethod · 0.80
assertIsInstanceMethod · 0.80
subTestMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected