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

Method test_subclass_now

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

Source from the content-addressed store, hash-verified

3218 self.assertEqual(dt.extra, 7)
3219
3220 def test_subclass_now(self):
3221 # Test that alternate constructors call the constructor
3222 class DateTimeSubclass(self.theclass):
3223 def __new__(cls, *args, **kwargs):
3224 result = self.theclass.__new__(cls, *args, **kwargs)
3225 result.extra = 7
3226
3227 return result
3228
3229 test_cases = [
3230 ('now', 'now', {}),
3231 ('utcnow', 'utcnow', {}),
3232 ('now_utc', 'now', {'tz': timezone.utc}),
3233 ('now_fixed', 'now', {'tz': timezone(timedelta(hours=-5), "EST")}),
3234 ]
3235
3236 for name, meth_name, kwargs in test_cases:
3237 with self.subTest(name):
3238 constr = getattr(DateTimeSubclass, meth_name)
3239 if meth_name == "utcnow":
3240 with self.assertWarns(DeprecationWarning):
3241 dt = constr(**kwargs)
3242 else:
3243 dt = constr(**kwargs)
3244
3245 self.assertIsInstance(dt, DateTimeSubclass)
3246 self.assertEqual(dt.extra, 7)
3247
3248 def test_subclass_replace_fold(self):
3249 class DateTimeSubclass(self.theclass):

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected