diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-01 10:01:14 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-01 10:01:14 (GMT) |
commit | 263dcd20a374d540c8f0bc07332f1657adf6da83 (patch) | |
tree | c44955a3ff494353583163d4634cae512e7836dc /Lib/test/test_threadedtempfile.py | |
parent | 8218bd4caf683ee98c450a093bf171dbca6c4849 (diff) | |
download | cpython-263dcd20a374d540c8f0bc07332f1657adf6da83.zip cpython-263dcd20a374d540c8f0bc07332f1657adf6da83.tar.gz cpython-263dcd20a374d540c8f0bc07332f1657adf6da83.tar.bz2 |
Issue #23799: Added test.support.start_threads() for running and cleaning up
multiple threads.
Diffstat (limited to 'Lib/test/test_threadedtempfile.py')
-rw-r--r-- | Lib/test/test_threadedtempfile.py | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/Lib/test/test_threadedtempfile.py b/Lib/test/test_threadedtempfile.py index 2dfd3a0..b742036 100644 --- a/Lib/test/test_threadedtempfile.py +++ b/Lib/test/test_threadedtempfile.py @@ -18,7 +18,7 @@ FILES_PER_THREAD = 50 import tempfile -from test.support import threading_setup, threading_cleanup, run_unittest, import_module +from test.support import start_threads, import_module threading = import_module('threading') import unittest import io @@ -46,33 +46,17 @@ class TempFileGreedy(threading.Thread): class ThreadedTempFileTest(unittest.TestCase): def test_main(self): - threads = [] - thread_info = threading_setup() - - for i in range(NUM_THREADS): - t = TempFileGreedy() - threads.append(t) - t.start() - - startEvent.set() - - ok = 0 - errors = [] - for t in threads: - t.join() - ok += t.ok_count - if t.error_count: - errors.append(str(t.name) + str(t.errors.getvalue())) - - threading_cleanup(*thread_info) + threads = [TempFileGreedy() for i in range(NUM_THREADS)] + with start_threads(threads, startEvent.set): + pass + ok = sum(t.ok_count for t in threads) + errors = [str(t.name) + str(t.errors.getvalue()) + for t in threads if t.error_count] msg = "Errors: errors %d ok %d\n%s" % (len(errors), ok, '\n'.join(errors)) self.assertEqual(errors, [], msg) self.assertEqual(ok, NUM_THREADS * FILES_PER_THREAD) -def test_main(): - run_unittest(ThreadedTempFileTest) - if __name__ == "__main__": - test_main() + unittest.main() |