◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
5 changes: 5 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ def test_lose_target_ref(self):
del c
p.start()
p.join()
self.assertIs(wr(), None)
self.assertEqual(q.get(), 5)
close_queue(q)
Expand Down Expand Up @@ -2667,6 +2668,7 @@ def test_release_task_refs(self):
self.pool.map(identity, objs)

del objs
time.sleep(DELTA) # let threaded cleanup code run
self.assertEqual(set(wr() for wr in refs), {None})
# With a process pool, copies of the objects are returned, check
Expand Down Expand Up @@ -4198,6 +4200,7 @@ def setUp(self):
util._finalizer_registry.clear()

def tearDown(self):
self.assertFalse(util._finalizer_registry)
util._finalizer_registry.update(self.registry_backup)

@@ -4209,12 +4212,14 @@ class Foo(object):
a = Foo()
util.Finalize(a, conn.send, args=('a',))
del a # triggers callback for a

b = Foo()
close_b = util.Finalize(b, conn.send, args=('b',))
close_b() # triggers callback for b
close_b() # does nothing because callback has already been called
del b # does nothing because callback has already been called

c = Foo()
util.Finalize(c, conn.send, args=('c',))
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/lock_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import os
import sys
import time
from _thread import start_new_thread, TIMEOUT_MAX
Expand Down Expand Up @@ -221,6 +222,7 @@ def test_weakref_deleted(self):
lock = self.locktype()
ref = weakref.ref(lock)
del lock
self.assertIsNone(ref())


Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_array.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ def test_weakref(self):
p = weakref.proxy(s)
self.assertEqual(p.tobytes(), s.tobytes())
s = None
self.assertRaises(ReferenceError, len, p)

@unittest.skipUnless(hasattr(sys, 'getrefcount'),
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_asyncgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest

from test.support.import_helper import import_module
asyncio = import_module("asyncio")


Expand Down Expand Up @@ -871,6 +872,7 @@ async def run():
await g.__anext__()
await g.__anext__()
del g

await asyncio.sleep(0.1)

Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
@@ -2690,6 +2690,7 @@ def coro():
self.new_task(self.loop, gen)
finally:
gen.close()

self.assertTrue(m_log.error.called)
message = m_log.error.call_args[0][0]
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_code.py
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@
except ImportError:
ctypes = None
from test.support import (run_doctest, run_unittest, cpython_only,
check_impl_detail)


def consts(t):
Expand Down Expand Up @@ -343,6 +343,7 @@ def callback(code):
coderef = weakref.ref(f.__code__, callback)
self.assertTrue(bool(coderef()))
del f
self.assertFalse(bool(coderef()))
self.assertTrue(self.called)

Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_concurrent_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ def test_thread_names_assigned(self):
executor.map(abs, range(-5, 5))
threads = executor._threads
del executor

for t in threads:
self.assertRegex(t.name, r'^SpecialPool_[0-4]$')
Expand All @@ -473,6 +474,7 @@ def test_thread_names_default(self):
executor.map(abs, range(-5, 5))
threads = executor._threads
del executor

for t in threads:
# Ensure that our default name is reasonably sane and unique when
Expand Down Expand Up @@ -535,6 +537,7 @@ def test_del_shutdown(self):
call_queue = executor._call_queue
executor_manager_thread = executor._executor_manager_thread
del executor

# Make sure that all the executor resources were properly cleaned by
# the shutdown process
Expand Down Expand Up @@ -759,13 +762,15 @@ def test_free_reference_yielded_future(self):
futures_list.remove(future)
wr = weakref.ref(future)
del future
self.assertIsNone(wr())

futures_list[0].set_result("test")
for future in futures.as_completed(futures_list):
futures_list.remove(future)
wr = weakref.ref(future)
del future
self.assertIsNone(wr())
if futures_list:
futures_list[0].set_result("test")
Expand Down Expand Up @@ -865,6 +870,7 @@ def test_free_reference(self):
for obj in self.executor.map(make_dummy_object, range(10)):
wr = weakref.ref(obj)
del obj
self.assertIsNone(wr())


Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from operator import le, lt, ge, gt, eq, ne

import unittest

order_comparisons = le, lt, ge, gt
equality_comparisons = eq, ne
Expand Down Expand Up @@ -805,6 +806,7 @@ class C(object):
self.assertEqual(v[c], d)
self.assertEqual(len(v), 2)
del c, d
self.assertEqual(len(v), 1)
x, y = C(), C()
# The underlying containers are decoupled
Expand Down Expand Up @@ -834,6 +836,7 @@ def __init__(self, i):
self.assertEqual(v[a].i, b.i)
self.assertEqual(v[c].i, d.i)
del c
self.assertEqual(len(v), 1)

def test_deepcopy_weakvaluedict(self):
Expand All @@ -857,6 +860,7 @@ def __init__(self, i):
self.assertIs(t, d)
del x, y, z, t
del d
self.assertEqual(len(v), 1)

def test_deepcopy_bound_method(self):
1 change: 1 addition & 0 deletions Lib/test/test_deque.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ def test_weakref(self):
p = weakref.proxy(d)
self.assertEqual(str(p), str(d))
d = None
self.assertRaises(ReferenceError, str, p)

def test_strange_subclass(self):
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ def inner_raising_func():
except MyException as e:
pass
obj = None
obj = wr()
self.assertIsNone(obj)

Expand All @@ -667,6 +668,7 @@ def inner_raising_func():
except MyException:
pass
obj = None
obj = wr()
self.assertIsNone(obj)

Expand All @@ -678,6 +680,7 @@ def inner_raising_func():
except:
pass
obj = None
obj = wr()
self.assertIsNone(obj)

@@ -690,6 +693,7 @@ def inner_raising_func():
except:
break
obj = None
obj = wr()
self.assertIsNone(obj)

Expand All @@ -708,6 +712,7 @@ def inner_raising_func():
# must clear the latter manually for our test to succeed.
e.__context__ = None
obj = None
obj = wr()
# guarantee no ref cycles on CPython (don't gc_collect)
if check_impl_detail(cpython=False):
Expand Down @@ -898,6 +903,7 @@ def raising_gen():
next(g)
testfunc(g)
g = obj = None
obj = wr()
self.assertIsNone(obj)

Expand Down Expand Up @@ -951,6 +957,7 @@ def __del__(self):
raise Exception(MyObject())
except:
pass
self.assertEqual(e, (None, None, None))

def test_raise_does_not_create_context_chain_cycle(self):
Expand Down Expand Up @@ -1413,6 +1420,7 @@ def inner():
self.assertNotEqual(wr(), None)
else:
self.fail("MemoryError not raised")
self.assertEqual(wr(), None)

@no_tracing
Expand All @@ -1433,6 +1441,7 @@ def inner():
self.assertNotEqual(wr(), None)
else:
self.fail("RecursionError not raised")
self.assertEqual(wr(), None)

def test_errno_ENOTDIR(self):
Expand All @@ -1453,6 +1462,7 @@ def __del__(self):
with support.catch_unraisable_exception() as cm:
del obj

self.assertEqual(cm.unraisable.object, BrokenDel.__del__)
self.assertIsNotNone(cm.unraisable.exc_traceback)

Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io
import _pyio as pyio

from test.support.os_helper import TESTFN
from test.support import os_helper
from test.support import warnings_helper
Expand All @@ -30,6 +31,7 @@ def testWeakRefs(self):
self.assertEqual(self.f.tell(), p.tell())
self.f.close()
self.f = None
self.assertRaises(ReferenceError, getattr, p, 'tell')

def testAttributes(self):
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def test_weakref(self):
p = proxy(f)
self.assertEqual(f.func, p.func)
f = None
self.assertRaises(ReferenceError, getattr, p, 'func')

def test_with_bound_and_unbound_methods(self):
Expand Down
6 changes: 4 additions & 2 deletions Lib/test/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,8 @@ def printsolution(self, x):
"""

coroutine_tests = """\
Sending a value into a started generator:

>>> def f():
Expand Down @@ -2189,7 +2191,7 @@ def printsolution(self, x):

>>> g = f()
>>> next(g)
>>> del g
exiting


Expand All @@ -2204,7 +2206,7 @@ def printsolution(self, x):

>>> g = f()
>>> next(g)
>>> del g
finally


Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,7 @@ def test_tee(self):
p = weakref.proxy(a)
self.assertEqual(getattr(p, '__class__'), type(b))
del a
self.assertRaises(ReferenceError, getattr, p, '__class__')

ans = list('abc')
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import unittest
import weakref
from test.support import import_helper
from test.support import threading_helper

Expand Down Expand Up @@ -590,6 +591,7 @@ class C:
q.put(C())
for i in range(N):
wr = weakref.ref(q.get())
self.assertIsNone(wr())


Expand Down
Loading
Toggle all file notes Toggle all file annotations