[Python-checkins] r76138 - in python/branches/py3k: Lib/test/lock_tests.py Lib/test/test_thread.py Lib/test/test_threading.py Misc/NEWS

antoine.pitrou python-checkins at python.org
Fri Nov 6 23:41:14 CET 2009


Author: antoine.pitrou
Date: Fri Nov  6 23:41:14 2009
New Revision: 76138

Log:
Merged revisions 76137 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r76137 | antoine.pitrou | 2009-11-06 23:34:35 +0100 (ven., 06 nov. 2009) | 4 lines
  
  Issue #7270: Add some dedicated unit tests for multi-thread synchronization
  primitives such as Lock, RLock, Condition, Event and Semaphore.
........


Added:
   python/branches/py3k/Lib/test/lock_tests.py
      - copied, changed from r76137, /python/trunk/Lib/test/lock_tests.py
Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/test_thread.py
   python/branches/py3k/Lib/test/test_threading.py
   python/branches/py3k/Misc/NEWS

Copied: python/branches/py3k/Lib/test/lock_tests.py (from r76137, /python/trunk/Lib/test/lock_tests.py)
==============================================================================
--- /python/trunk/Lib/test/lock_tests.py	(original)
+++ python/branches/py3k/Lib/test/lock_tests.py	Fri Nov  6 23:41:14 2009
@@ -4,11 +4,11 @@
 
 import sys
 import time
-from thread import start_new_thread, get_ident
+from _thread import start_new_thread, get_ident
 import threading
 import unittest
 
-from test import test_support as support
+from test import support
 
 
 def _wait():
@@ -401,7 +401,7 @@
 
     def test_constructor(self):
         self.assertRaises(ValueError, self.semtype, value = -1)
-        self.assertRaises(ValueError, self.semtype, value = -sys.maxint)
+        self.assertRaises(ValueError, self.semtype, value = -sys.maxsize)
 
     def test_acquire(self):
         sem = self.semtype(1)

Modified: python/branches/py3k/Lib/test/test_thread.py
==============================================================================
--- python/branches/py3k/Lib/test/test_thread.py	(original)
+++ python/branches/py3k/Lib/test/test_thread.py	Fri Nov  6 23:41:14 2009
@@ -6,6 +6,7 @@
 import time
 import weakref
 
+from test import lock_tests
 
 NUMTASKS = 10
 NUMTRIPS = 3
@@ -188,8 +189,12 @@
         if finished:
             self.done_mutex.release()
 
+class LockTests(lock_tests.LockTests):
+    locktype = thread.allocate_lock
+
+
 def test_main():
-    support.run_unittest(ThreadRunningTests, BarrierTest)
+    support.run_unittest(ThreadRunningTests, BarrierTest, LockTests)
 
 if __name__ == "__main__":
     test_main()

Modified: python/branches/py3k/Lib/test/test_threading.py
==============================================================================
--- python/branches/py3k/Lib/test/test_threading.py	(original)
+++ python/branches/py3k/Lib/test/test_threading.py	Fri Nov  6 23:41:14 2009
@@ -12,6 +12,8 @@
 import weakref
 import os
 
+from test import lock_tests
+
 # A trivial mutable counter.
 class Counter(object):
     def __init__(self):
@@ -487,22 +489,6 @@
         thread.start()
         self.assertRaises(RuntimeError, thread.start)
 
-    def test_releasing_unacquired_rlock(self):
-        rlock = threading.RLock()
-        self.assertRaises(RuntimeError, rlock.release)
-
-    def test_waiting_on_unacquired_condition(self):
-        cond = threading.Condition()
-        self.assertRaises(RuntimeError, cond.wait)
-
-    def test_notify_on_unacquired_condition(self):
-        cond = threading.Condition()
-        self.assertRaises(RuntimeError, cond.notify)
-
-    def test_semaphore_with_negative_value(self):
-        self.assertRaises(ValueError, threading.Semaphore, value = -1)
-        self.assertRaises(ValueError, threading.Semaphore, value = -sys.maxsize)
-
     def test_joining_current_thread(self):
         current_thread = threading.current_thread()
         self.assertRaises(RuntimeError, current_thread.join);
@@ -517,11 +503,37 @@
         self.assertRaises(RuntimeError, setattr, thread, "daemon", True)
 
 
+class LockTests(lock_tests.LockTests):
+    locktype = staticmethod(threading.Lock)
+
+class RLockTests(lock_tests.RLockTests):
+    locktype = staticmethod(threading.RLock)
+
+class EventTests(lock_tests.EventTests):
+    eventtype = staticmethod(threading.Event)
+
+class ConditionAsRLockTests(lock_tests.RLockTests):
+    # An Condition uses an RLock by default and exports its API.
+    locktype = staticmethod(threading.Condition)
+
+class ConditionTests(lock_tests.ConditionTests):
+    condtype = staticmethod(threading.Condition)
+
+class SemaphoreTests(lock_tests.SemaphoreTests):
+    semtype = staticmethod(threading.Semaphore)
+
+class BoundedSemaphoreTests(lock_tests.BoundedSemaphoreTests):
+    semtype = staticmethod(threading.BoundedSemaphore)
+
+
 def test_main():
-    test.support.run_unittest(ThreadTests,
-                                   ThreadJoinOnShutdown,
-                                   ThreadingExceptionTests,
-                                   )
+    test.support.run_unittest(LockTests, RLockTests, EventTests,
+                              ConditionAsRLockTests, ConditionTests,
+                              SemaphoreTests, BoundedSemaphoreTests,
+                              ThreadTests,
+                              ThreadJoinOnShutdown,
+                              ThreadingExceptionTests,
+                              )
 
 if __name__ == "__main__":
     test_main()

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Fri Nov  6 23:41:14 2009
@@ -357,6 +357,9 @@
 Tests
 -----
 
+- Issue #7270: Add some dedicated unit tests for multi-thread synchronization
+  primitives such as Lock, RLock, Condition, Event and Semaphore.
+
 - Issue #7248 (part 2): Use a unique temporary directory for importlib source
   tests instead of tempfile.tempdir. This prevents the tests from sharing state
   between concurrent executions on the same system.


More information about the Python-checkins mailing list