]> granicus.if.org Git - python/commitdiff
Issue #25298: Add lock and rlock weakref tests (Contributed by Nir Soffer).
authorRaymond Hettinger <python@rcn.com>
Fri, 9 Oct 2015 04:03:51 +0000 (00:03 -0400)
committerRaymond Hettinger <python@rcn.com>
Fri, 9 Oct 2015 04:03:51 +0000 (00:03 -0400)
Lib/test/lock_tests.py

index afd68736832451c235038c565aa83f9df60bfc92..055bf28565d1f3f5537853a82ceb65e0fe7f3bec 100644 (file)
@@ -7,6 +7,7 @@ import time
 from _thread import start_new_thread, TIMEOUT_MAX
 import threading
 import unittest
+import weakref
 
 from test import support
 
@@ -198,6 +199,17 @@ class BaseLockTests(BaseTestCase):
         self.assertFalse(results[0])
         self.assertTimeout(results[1], 0.5)
 
+    def test_weakref_exists(self):
+        lock = self.locktype()
+        ref = weakref.ref(lock)
+        self.assertIsNotNone(ref())
+
+    def test_weakref_deleted(self):
+        lock = self.locktype()
+        ref = weakref.ref(lock)
+        del lock
+        self.assertIsNone(ref())
+
 
 class LockTests(BaseLockTests):
     """