summaryrefslogtreecommitdiff
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorCollin Winter <collinw@gmail.com>2007-06-06 00:17:35 +0000
committerCollin Winter <collinw@gmail.com>2007-06-06 00:17:35 +0000
commit50b79ce8e6629eb995a0b2091efebe9a5d458273 (patch)
tree7edb984160150dd3f8e7448b26d5dab78dd8ad86 /Lib/test/test_threading.py
parent956f0f71f9381130dd643e5b9d334a3902a42699 (diff)
downloadcpython-git-50b79ce8e6629eb995a0b2091efebe9a5d458273.tar.gz
Patch #1731049: make threading.py use a proper "raise" when checking internal state, rather than assert statements (which get stripped out by -O).
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py42
1 files changed, 41 insertions, 1 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 8614ecb49c..dced9cb17b 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -3,6 +3,7 @@
import test.test_support
from test.test_support import verbose
import random
+import sys
import threading
import thread
import time
@@ -201,8 +202,47 @@ class ThreadTests(unittest.TestCase):
t.join()
# else the thread is still running, and we have no way to kill it
+class ThreadingExceptionTests(unittest.TestCase):
+ # A RuntimeError should be raised if Thread.start() is called
+ # multiple times.
+ def test_start_thread_again(self):
+ thread = threading.Thread()
+ 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.maxint)
+
+ def test_joining_current_thread(self):
+ currentThread = threading.currentThread()
+ self.assertRaises(RuntimeError, currentThread.join);
+
+ def test_joining_inactive_thread(self):
+ thread = threading.Thread()
+ self.assertRaises(RuntimeError, thread.join)
+
+ def test_daemonize_active_thread(self):
+ thread = threading.Thread()
+ thread.start()
+ self.assertRaises(RuntimeError, thread.setDaemon, True)
+
+
def test_main():
- test.test_support.run_unittest(ThreadTests)
+ test.test_support.run_unittest(ThreadTests,
+ ThreadingExceptionTests)
if __name__ == "__main__":
test_main()