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

Method test_datetime_weakref_cycle

Lib/test/test_gc.py:312–330  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

310 self.assertFalse(stderr)
311
312 def test_datetime_weakref_cycle(self):
313 # https://github.com/python/cpython/issues/132413
314 # If the weakref used by the datetime extension gets cleared by the GC (due to being
315 # in an unreachable cycle) then datetime functions would crash (get_module_state()
316 # was returning a NULL pointer). This bug is fixed by clearing weakrefs without
317 # callbacks *after* running finalizers.
318 code = """if 1:
319 import _datetime
320 class C:
321 def __del__(self):
322 print('__del__ called')
323 _datetime.timedelta(days=1) # crash?
324
325 l = [C()]
326 l.append(l)
327 """
328 rc, stdout, stderr = assert_python_ok("-c", code)
329 self.assertEqual(rc, 0)
330 self.assertEqual(stdout.strip(), b'__del__ called')
331
332 @refcount_test
333 def test_frame(self):

Callers

nothing calls this directly

Calls 3

assert_python_okFunction · 0.90
assertEqualMethod · 0.45
stripMethod · 0.45

Tested by

no test coverage detected