Index: Lib/ctypes/test/test_errno.py =================================================================== --- Lib/ctypes/test/test_errno.py (révision 78770) +++ Lib/ctypes/test/test_errno.py (copie de travail) @@ -1,76 +1,84 @@ import unittest, os, errno from ctypes import * from ctypes.util import find_library -import threading +from test import test_support +try: + import threading +except ImportError: + threading = None +libc_name = find_library("c") + class Test(unittest.TestCase): + @unittest.skipUnless(libc_name, 'Unable to find the C library') def test_open(self): - libc_name = find_library("c") - if libc_name is not None: - libc = CDLL(libc_name, use_errno=True) + libc = CDLL(libc_name, use_errno=True) + if os.name == "nt": + libc_open = libc._open + else: + libc_open = libc.open + + libc_open.argtypes = c_char_p, c_int + + self.assertEqual(libc_open("", 0), -1) + self.assertEqual(get_errno(), errno.ENOENT) + + self.assertEqual(set_errno(32), errno.ENOENT) + self.assertEqual(get_errno(), 32) + + @unittest.skipUnless(libc_name, 'Unable to find the C library') + @unittest.skipUnless(threading, 'This test requires threading.') + def test_open_thread(self): + self.assertEqual(set_errno(32), errno.ENOENT) + + def _worker(): + set_errno(0) + + libc = CDLL(libc_name, use_errno=False) if os.name == "nt": libc_open = libc._open else: libc_open = libc.open - libc_open.argtypes = c_char_p, c_int - self.assertEqual(libc_open("", 0), -1) - self.assertEqual(get_errno(), errno.ENOENT) + self.assertEqual(get_errno(), 0) - self.assertEqual(set_errno(32), errno.ENOENT) - self.assertEqual(get_errno(), 32) + t = threading.Thread(target=_worker) + t.start() + t.join() + self.assertEqual(get_errno(), 32) + set_errno(0) - def _worker(): - set_errno(0) + @unittest.skipUnless(os.name == "nt", 'Test specific to Windows') + def test_GetLastError(self): + dll = WinDLL("kernel32", use_last_error=True) + GetModuleHandle = dll.GetModuleHandleA + GetModuleHandle.argtypes = [c_wchar_p] - libc = CDLL(libc_name, use_errno=False) - if os.name == "nt": - libc_open = libc._open - else: - libc_open = libc.open - libc_open.argtypes = c_char_p, c_int - self.assertEqual(libc_open("", 0), -1) - self.assertEqual(get_errno(), 0) + self.assertEqual(0, GetModuleHandle("foo")) + self.assertEqual(get_last_error(), 126) - t = threading.Thread(target=_worker) - t.start() - t.join() + self.assertEqual(set_last_error(32), 126) + self.assertEqual(get_last_error(), 32) - self.assertEqual(get_errno(), 32) - set_errno(0) + def _worker(): + set_last_error(0) - if os.name == "nt": - - def test_GetLastError(self): - dll = WinDLL("kernel32", use_last_error=True) - GetModuleHandle = dll.GetModuleHandleA + dll = WinDLL("kernel32", use_last_error=False) + GetModuleHandle = dll.GetModuleHandleW GetModuleHandle.argtypes = [c_wchar_p] + GetModuleHandle("bar") - self.assertEqual(0, GetModuleHandle("foo")) - self.assertEqual(get_last_error(), 126) + self.assertEqual(get_last_error(), 0) - self.assertEqual(set_last_error(32), 126) - self.assertEqual(get_last_error(), 32) + t = threading.Thread(target=_worker) + t.start() + t.join() - def _worker(): - set_last_error(0) + self.assertEqual(get_last_error(), 32) - dll = WinDLL("kernel32", use_last_error=False) - GetModuleHandle = dll.GetModuleHandleW - GetModuleHandle.argtypes = [c_wchar_p] - GetModuleHandle("bar") + set_last_error(0) - self.assertEqual(get_last_error(), 0) - - t = threading.Thread(target=_worker) - t.start() - t.join() - - self.assertEqual(get_last_error(), 32) - - set_last_error(0) - if __name__ == "__main__": unittest.main() Index: Lib/sqlite3/test/dbapi.py =================================================================== --- Lib/sqlite3/test/dbapi.py (révision 78770) +++ Lib/sqlite3/test/dbapi.py (copie de travail) @@ -23,8 +23,11 @@ import unittest import sys -import threading import sqlite3 as sqlite +try: + import threading +except ImportError: + threading = None class ModuleTests(unittest.TestCase): def CheckAPILevel(self): @@ -465,6 +468,7 @@ except TypeError: pass +@unittest.skipUnless(threading, 'This test requires threading.') class ThreadTests(unittest.TestCase): def setUp(self): self.con = sqlite.connect(":memory:") Index: Lib/test/test_urllib2_localnet.py =================================================================== --- Lib/test/test_urllib2_localnet.py (révision 78770) +++ Lib/test/test_urllib2_localnet.py (copie de travail) @@ -1,6 +1,5 @@ #!/usr/bin/env python -import threading import urlparse import urllib2 import BaseHTTPServer @@ -8,6 +7,7 @@ import hashlib from test import test_support mimetools = test_support.import_module('mimetools', deprecated=True) +threading = test_support.import_module('threading') # Loopback http server infrastructure Index: Lib/test/regrtest.py =================================================================== --- Lib/test/regrtest.py (révision 78770) +++ Lib/test/regrtest.py (copie de travail) @@ -476,7 +476,11 @@ tests = iter(tests) if use_mp: - from threading import Thread + try: + from threading import Thread + except ImportError: + print "Multiprocess option requires thread support" + sys.exit(2) from Queue import Queue from subprocess import Popen, PIPE from collections import deque Index: Lib/test/test_xmlrpc.py =================================================================== --- Lib/test/test_xmlrpc.py (révision 78770) +++ Lib/test/test_xmlrpc.py (copie de travail) @@ -5,7 +5,6 @@ import unittest import xmlrpclib import SimpleXMLRPCServer -import threading import mimetools import httplib import socket @@ -15,6 +14,11 @@ from test import test_support try: + import threading +except ImportError: + threading = None + +try: unicode except NameError: have_unicode = False @@ -410,10 +414,12 @@ return False +@unittest.skipUnless(threading, 'Threading required for this test.') class BaseServerTestCase(unittest.TestCase): requestHandler = None request_count = 1 threadFunc = staticmethod(http_server) + def setUp(self): # enable traceback reporting SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True @@ -692,6 +698,9 @@ connection.putheader("Content-Encoding", "gzip") return xmlrpclib.Transport.send_content(self, connection, body) + def setUp(self): + BaseServerTestCase.setUp(self) + def test_gzip_request(self): t = self.Transport() t.encode_threshold = None @@ -728,13 +737,20 @@ #Test special attributes of the ServerProxy object class ServerProxyTestCase(unittest.TestCase): + def setUp(self): + unittest.TestCase.setUp(self) + if threading: + self.url = URL + else: + self.url = 'http:' + def test_close(self): - p = xmlrpclib.ServerProxy(URL) + p = xmlrpclib.ServerProxy(self.url) self.assertEqual(p('close')(), None) def test_transport(self): t = xmlrpclib.Transport() - p = xmlrpclib.ServerProxy(URL, transport=t) + p = xmlrpclib.ServerProxy(self.url, transport=t) self.assertEqual(p('transport'), t) # This is a contrived way to make a failure occur on the server side @@ -747,6 +763,7 @@ return mimetools.Message.__getitem__(self, key) +@unittest.skipUnless(threading, 'Threading required for this test.') class FailingServerTestCase(unittest.TestCase): def setUp(self): self.evt = threading.Event() Index: Lib/test/test_file2k.py =================================================================== --- Lib/test/test_file2k.py (révision 78770) +++ Lib/test/test_file2k.py (copie de travail) @@ -3,9 +3,12 @@ import unittest import itertools import time -import threading from array import array from weakref import proxy +try: + import threading +except ImportError: + threading = None from test import test_support from test.test_support import TESTFN, run_unittest @@ -404,6 +407,7 @@ self.assertTrue(f.subclass_closed) +@unittest.skipUnless(threading, 'Threading required for this test.') class FileThreadingTests(unittest.TestCase): # These tests check the ability to call various methods of file objects # (including close()) concurrently without crashing the Python interpreter. Index: Lib/test/test_cmd.py =================================================================== --- Lib/test/test_cmd.py (révision 78770) +++ Lib/test/test_cmd.py (copie de travail) @@ -7,6 +7,7 @@ import cmd import sys +from test import test_support class samplecmdclass(cmd.Cmd): """ @@ -168,11 +169,11 @@ return True def test_main(verbose=None): - from test import test_support, test_cmd + from test import test_cmd test_support.run_doctest(test_cmd, verbose) def test_coverage(coverdir): - import trace + trace = test_support.import_module('trace') tracer=trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,], trace=0, count=1) tracer.run('reload(cmd);test_main()') Index: Lib/test/test_io.py =================================================================== --- Lib/test/test_io.py (révision 78770) +++ Lib/test/test_io.py (copie de travail) @@ -26,7 +26,6 @@ import sys import time import array -import threading import random import unittest import warnings @@ -39,6 +38,10 @@ import codecs import io # C implementation of io import _pyio as pyio # Python implementation of io +try: + import threading +except ImportError: + threading = None __metaclass__ = type bytes = support.py3k_bytes @@ -750,6 +753,7 @@ self.assertEquals(b"abcdefg", bufio.read()) + @unittest.skipUnless(threading, 'Threading required for this test.') def test_threads(self): try: # Write out many bytes with exactly the same number of 0's, @@ -997,6 +1001,7 @@ with self.open(support.TESTFN, "rb", buffering=0) as f: self.assertEqual(f.read(), b"abc") + @unittest.skipUnless(threading, 'Threading required for this test.') def test_threads(self): try: # Write out many bytes from many threads and test they were @@ -2101,7 +2106,7 @@ with self.open(support.TESTFN, "w", errors="replace") as f: self.assertEqual(f.errors, "replace") - + @unittest.skipUnless(threading, 'Threading required for this test.') def test_threads_write(self): # Issue6750: concurrent writes could duplicate data event = threading.Event() Index: Lib/test/test_smtplib.py =================================================================== --- Lib/test/test_smtplib.py (révision 78770) +++ Lib/test/test_smtplib.py (copie de travail) @@ -1,7 +1,6 @@ import asyncore import email.utils import socket -import threading import smtpd import smtplib import StringIO @@ -9,9 +8,14 @@ import time import select -from unittest import TestCase +import unittest from test import test_support +try: + import threading +except ImportError: + threading = None + HOST = test_support.HOST def server(evt, buf, serv): @@ -36,7 +40,8 @@ serv.close() evt.set() -class GeneralTests(TestCase): +@unittest.skipUnless(threading, 'Threading required for this test.') +class GeneralTests(unittest.TestCase): def setUp(self): self._threads = test_support.threading_setup() @@ -138,7 +143,8 @@ # test server times out, causing the test to fail. # Test behavior of smtpd.DebuggingServer -class DebuggingServerTests(TestCase): +@unittest.skipUnless(threading, 'Threading required for this test.') +class DebuggingServerTests(unittest.TestCase): def setUp(self): # temporarily replace sys.stdout to capture DebuggingServer output @@ -233,7 +239,7 @@ self.assertEqual(self.output.getvalue(), mexpect) -class NonConnectingTests(TestCase): +class NonConnectingTests(unittest.TestCase): def testNotConnected(self): # Test various operations on an unconnected SMTP object that @@ -254,7 +260,8 @@ # test response of client to a non-successful HELO message -class BadHELOServerTests(TestCase): +@unittest.skipUnless(threading, 'Threading required for this test.') +class BadHELOServerTests(unittest.TestCase): def setUp(self): self.old_stdout = sys.stdout @@ -378,7 +385,8 @@ # Test various SMTP & ESMTP commands/behaviors that require a simulated server # (i.e., something with more features than DebuggingServer) -class SMTPSimTests(TestCase): +@unittest.skipUnless(threading, 'Threading required for this test.') +class SMTPSimTests(unittest.TestCase): def setUp(self): self._threads = test_support.threading_setup() Index: Lib/test/test_asyncore.py =================================================================== --- Lib/test/test_asyncore.py (révision 78770) +++ Lib/test/test_asyncore.py (copie de travail) @@ -3,7 +3,6 @@ import select import os import socket -import threading import sys import time @@ -11,6 +10,11 @@ from test.test_support import TESTFN, run_unittest, unlink from StringIO import StringIO +try: + import threading +except ImportError: + threading = None + HOST = test_support.HOST class dummysocket: @@ -319,6 +323,7 @@ def tearDown(self): asyncore.close_all() + @unittest.skipUnless(threading, 'Threading required for this test.') @test_support.reap_threads def test_send(self): evt = threading.Event() Index: Lib/test/test_threadedtempfile.py =================================================================== --- Lib/test/test_threadedtempfile.py (révision 78770) +++ Lib/test/test_threadedtempfile.py (copie de travail) @@ -16,11 +16,10 @@ NUM_THREADS = 20 FILES_PER_THREAD = 50 -import thread # If this fails, we can't test this module -import threading import tempfile -from test.test_support import threading_setup, threading_cleanup, run_unittest +from test.test_support import threading_setup, threading_cleanup, run_unittest, import_module +threading = import_module('threading') import unittest import StringIO from traceback import print_exc Index: Lib/test/test_fork1.py =================================================================== --- Lib/test/test_fork1.py (révision 78770) +++ Lib/test/test_fork1.py (copie de travail) @@ -6,10 +6,10 @@ import signal import sys import time -import threading from test.fork_wait import ForkWait -from test.test_support import run_unittest, reap_children, get_attribute +from test.test_support import run_unittest, reap_children, get_attribute, import_module +threading = import_module('threading') #Skip test if fork does not exist. get_attribute(os, 'fork') Index: Lib/test/test_socket.py =================================================================== --- Lib/test/test_socket.py (révision 78770) +++ Lib/test/test_socket.py (copie de travail) @@ -6,7 +6,6 @@ import errno import socket import select -import thread, threading import time import traceback import Queue @@ -16,6 +15,13 @@ from weakref import proxy import signal +try: + import thread + import threading +except ImportError: + thread = None + threading = None + HOST = test_support.HOST MSG = 'Michael Gilfix was here\n' @@ -549,6 +555,7 @@ s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100)) +@unittest.skipUnless(thread, 'Threading required for this test.') class BasicTCPTest(SocketConnectedTest): def __init__(self, methodName='runTest'): @@ -629,6 +636,7 @@ self.serv_conn.send(MSG) self.serv_conn.shutdown(2) +@unittest.skipUnless(thread, 'Threading required for this test.') class BasicUDPTest(ThreadedUDPSocketTest): def __init__(self, methodName='runTest'): @@ -657,6 +665,7 @@ def _testRecvFromNegative(self): self.cli.sendto(MSG, 0, (HOST, self.port)) +@unittest.skipUnless(thread, 'Threading required for this test.') class TCPCloserTest(ThreadedTCPSocketTest): def testClose(self): @@ -672,6 +681,7 @@ self.cli.connect((HOST, self.port)) time.sleep(1.0) +@unittest.skipUnless(thread, 'Threading required for this test.') class BasicSocketPairTest(SocketPairTest): def __init__(self, methodName='runTest'): @@ -691,6 +701,7 @@ msg = self.cli.recv(1024) self.assertEqual(msg, MSG) +@unittest.skipUnless(thread, 'Threading required for this test.') class NonBlockingTCPTests(ThreadedTCPSocketTest): def __init__(self, methodName='runTest'): @@ -759,6 +770,7 @@ time.sleep(0.1) self.cli.send(MSG) +@unittest.skipUnless(thread, 'Threading required for this test.') class FileObjectClassTestCase(SocketConnectedTest): bufsize = -1 # Use default buffer size @@ -988,6 +1000,7 @@ lambda: socket.create_connection((HOST, port)) ) +@unittest.skipUnless(thread, 'Threading required for this test.') class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest): def __init__(self, methodName='runTest'): @@ -1050,6 +1063,7 @@ self.cli = socket.create_connection((HOST, self.port), 30) self.assertEqual(self.cli.gettimeout(), 30) +@unittest.skipUnless(thread, 'Threading required for this test.') class NetworkConnectionBehaviourTest(SocketTCPTest, ThreadableTest): def __init__(self, methodName='runTest'): @@ -1219,6 +1233,7 @@ self.assertRaises(socket.error, s.bind, address) +@unittest.skipUnless(thread, 'Threading required for this test.') class BufferIOTest(SocketConnectedTest): """ Test the buffer versions of socket.recv() and socket.send(). Index: Lib/test/test_docxmlrpc.py =================================================================== --- Lib/test/test_docxmlrpc.py (révision 78770) +++ Lib/test/test_docxmlrpc.py (copie de travail) @@ -2,7 +2,7 @@ import httplib import sys from test import test_support -import threading +threading = test_support.import_module('threading') import time import socket import unittest Index: Lib/test/test_logging.py =================================================================== --- Lib/test/test_logging.py (révision 78770) +++ Lib/test/test_logging.py (copie de travail) @@ -41,12 +41,14 @@ from test.test_support import captured_stdout, run_with_locale, run_unittest,\ find_unused_port import textwrap -import threading import unittest import warnings import weakref +try: + import threading +except ImportError: + threading = None - class BaseTest(unittest.TestCase): """Base class for logging tests.""" @@ -759,6 +761,7 @@ self.server_close() +@unittest.skipUnless(threading, 'Threading required for this test.') class SocketHandlerTest(BaseTest): """Test for SocketHandler objects.""" @@ -1653,6 +1656,7 @@ def test_config13_failure(self): self.assertRaises(StandardError, self.apply_config, self.config13) + @unittest.skipUnless(threading, 'listen() needs threading to work') def setup_via_listener(self, text): port = find_unused_port() t = logging.config.listen(port) Index: Lib/test/test_threadsignals.py =================================================================== --- Lib/test/test_threadsignals.py (révision 78770) +++ Lib/test/test_threadsignals.py (copie de travail) @@ -1,11 +1,11 @@ """PyUnit testing that threads honor our signal semantics""" import unittest -import thread import signal import os import sys -from test.test_support import run_unittest +from test.test_support import run_unittest, import_module +thread = import_module('thread') if sys.platform[:3] in ('win', 'os2') or sys.platform=='riscos': raise unittest.SkipTest, "Can't test signal on %s" % sys.platform Index: Lib/test/test_doctest.py =================================================================== --- Lib/test/test_doctest.py (révision 78770) +++ Lib/test/test_doctest.py (copie de travail) @@ -2466,8 +2466,9 @@ from test import test_doctest test_support.run_doctest(test_doctest, verbosity=True) -import trace, sys +import sys def test_coverage(coverdir): + trace = test_support.import_module('trace') tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,], trace=0, count=1) tracer.run('reload(doctest); test_main()') Index: Lib/test/test_thread.py =================================================================== --- Lib/test/test_thread.py (révision 78770) +++ Lib/test/test_thread.py (copie de travail) @@ -2,7 +2,7 @@ import unittest import random from test import test_support -import thread +thread = test_support.import_module('thread') import time import sys import weakref Index: Lib/test/test_hashlib.py =================================================================== --- Lib/test/test_hashlib.py (révision 78770) +++ Lib/test/test_hashlib.py (copie de travail) @@ -299,10 +299,9 @@ "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973eb"+ "de0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b") + @unittest.skipUnless(threading, 'Threading required for this test.') + @test_support.reap_threads def test_threaded_hashing(self): - if not threading: - raise unittest.SkipTest('No threading module.') - # Updating the same hash object from several threads at once # using data chunk sizes containing the same byte sequences. # @@ -337,7 +336,6 @@ self.assertEqual(expected_hash, hasher.hexdigest()) -@test_support.reap_threads def test_main(): test_support.run_unittest(HashLibTestCase) Index: Lib/test/test_capi.py =================================================================== --- Lib/test/test_capi.py (révision 78770) +++ Lib/test/test_capi.py (copie de travail) @@ -6,10 +6,14 @@ import time import random import unittest -import threading from test import test_support +try: + import threading +except ImportError: + threading = None import _testcapi +@unittest.skipUnless(threading, 'Threading required for this test.') class TestPendingCalls(unittest.TestCase): def pendingcalls_submit(self, l, n): @@ -47,7 +51,6 @@ print "(%i)"%(len(l),) def test_pendingcalls_threaded(self): - #do every callback on a separate thread n = 32 #total callbacks threads = [] @@ -123,17 +126,10 @@ raise test_support.TestFailed, \ "Couldn't find main thread correctly in the list" - try: - _testcapi._test_thread_state - have_thread_state = True - except AttributeError: - have_thread_state = False - - if have_thread_state: + if threading: import thread import time TestThreadState() - import threading t=threading.Thread(target=TestThreadState) t.start() t.join() Index: Lib/test/test_asynchat.py =================================================================== --- Lib/test/test_asynchat.py (révision 78770) +++ Lib/test/test_asynchat.py (copie de travail) @@ -1,93 +1,96 @@ # test asynchat -import asyncore, asynchat, socket, threading, time +import asyncore, asynchat, socket, time import unittest import sys from test import test_support +try: + import threading +except ImportError: + threading = None -# Skip tests if thread module does not exist. -test_support.import_module('thread') - HOST = test_support.HOST SERVER_QUIT = 'QUIT\n' -class echo_server(threading.Thread): - # parameter to determine the number of bytes passed back to the - # client each send - chunk_size = 1 +if threading: + class echo_server(threading.Thread): + # parameter to determine the number of bytes passed back to the + # client each send + chunk_size = 1 - def __init__(self, event): - threading.Thread.__init__(self) - self.event = event - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.port = test_support.bind_port(self.sock) + def __init__(self, event): + threading.Thread.__init__(self) + self.event = event + self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.port = test_support.bind_port(self.sock) - def run(self): - self.sock.listen(1) - self.event.set() - conn, client = self.sock.accept() - self.buffer = "" - # collect data until quit message is seen - while SERVER_QUIT not in self.buffer: - data = conn.recv(1) - if not data: - break - self.buffer = self.buffer + data + def run(self): + self.sock.listen(1) + self.event.set() + conn, client = self.sock.accept() + self.buffer = "" + # collect data until quit message is seen + while SERVER_QUIT not in self.buffer: + data = conn.recv(1) + if not data: + break + self.buffer = self.buffer + data - # remove the SERVER_QUIT message - self.buffer = self.buffer.replace(SERVER_QUIT, '') + # remove the SERVER_QUIT message + self.buffer = self.buffer.replace(SERVER_QUIT, '') - # re-send entire set of collected data - try: - # this may fail on some tests, such as test_close_when_done, since - # the client closes the channel when it's done sending - while self.buffer: - n = conn.send(self.buffer[:self.chunk_size]) - time.sleep(0.001) - self.buffer = self.buffer[n:] - except: - pass + # re-send entire set of collected data + try: + # this may fail on some tests, such as test_close_when_done, since + # the client closes the channel when it's done sending + while self.buffer: + n = conn.send(self.buffer[:self.chunk_size]) + time.sleep(0.001) + self.buffer = self.buffer[n:] + except: + pass - conn.close() - self.sock.close() + conn.close() + self.sock.close() -class echo_client(asynchat.async_chat): + class echo_client(asynchat.async_chat): - def __init__(self, terminator, server_port): - asynchat.async_chat.__init__(self) - self.contents = [] - self.create_socket(socket.AF_INET, socket.SOCK_STREAM) - self.connect((HOST, server_port)) - self.set_terminator(terminator) - self.buffer = '' + def __init__(self, terminator, server_port): + asynchat.async_chat.__init__(self) + self.contents = [] + self.create_socket(socket.AF_INET, socket.SOCK_STREAM) + self.connect((HOST, server_port)) + self.set_terminator(terminator) + self.buffer = '' - def handle_connect(self): - pass - - if sys.platform == 'darwin': - # select.poll returns a select.POLLHUP at the end of the tests - # on darwin, so just ignore it - def handle_expt(self): + def handle_connect(self): pass - def collect_incoming_data(self, data): - self.buffer += data + if sys.platform == 'darwin': + # select.poll returns a select.POLLHUP at the end of the tests + # on darwin, so just ignore it + def handle_expt(self): + pass - def found_terminator(self): - self.contents.append(self.buffer) - self.buffer = "" + def collect_incoming_data(self, data): + self.buffer += data + def found_terminator(self): + self.contents.append(self.buffer) + self.buffer = "" -def start_echo_server(): - event = threading.Event() - s = echo_server(event) - s.start() - event.wait() - event.clear() - time.sleep(0.01) # Give server time to start accepting. - return s, event + def start_echo_server(): + event = threading.Event() + s = echo_server(event) + s.start() + event.wait() + event.clear() + time.sleep(0.01) # Give server time to start accepting. + return s, event + +@unittest.skipUnless(threading, 'Threading required for this test.') class TestAsynchat(unittest.TestCase): usepoll = False Index: Lib/test/test_socketserver.py =================================================================== --- Lib/test/test_socketserver.py (révision 78770) +++ Lib/test/test_socketserver.py (copie de travail) @@ -9,12 +9,15 @@ import signal import socket import tempfile -import threading import unittest import SocketServer import test.test_support from test.test_support import reap_children, reap_threads, verbose +try: + import threading +except ImportError: + threading = None test.test_support.requires("network") @@ -119,6 +122,7 @@ self.assertEquals(server.server_address, server.socket.getsockname()) return server + @unittest.skipUnless(threading, 'Threading required for this test.') @reap_threads def run_server(self, svrcls, hdlrbase, testfunc): server = self.make_server(self.pickaddr(svrcls.address_family), Index: Lib/test/test_queue.py =================================================================== --- Lib/test/test_queue.py (révision 78770) +++ Lib/test/test_queue.py (copie de travail) @@ -1,10 +1,10 @@ # Some simple queue module tests, plus some failure conditions # to ensure the Queue locks remain stable. import Queue -import threading import time import unittest from test import test_support +threading = test_support.import_module('threading') QUEUE_SIZE = 5 Index: Lib/test/test_poplib.py =================================================================== --- Lib/test/test_poplib.py (révision 78770) +++ Lib/test/test_poplib.py (copie de travail) @@ -4,7 +4,6 @@ # a real test suite import poplib -import threading import asyncore import asynchat import socket @@ -14,8 +13,8 @@ from unittest import TestCase from test import test_support from test.test_support import HOST +threading = test_support.import_module('threading') - # the dummy data returned by server when LIST and RETR commands are issued LIST_RESP = '1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n.\r\n' RETR_RESP = """From: postmaster@python.org\ Index: Lib/test/test_bz2.py =================================================================== --- Lib/test/test_bz2.py (révision 78770) +++ Lib/test/test_bz2.py (copie de travail) @@ -7,8 +7,12 @@ import os import subprocess import sys -import threading +try: + import threading +except ImportError: + threading = None + bz2 = import_module('bz2') from bz2 import BZ2File, BZ2Compressor, BZ2Decompressor @@ -307,6 +311,7 @@ else: self.fail("1/0 didn't raise an exception") + @unittest.skipUnless(threading, 'Threading required for this test.') def testThreading(self): # Using a BZ2File from several threads doesn't deadlock (issue #7205). data = "1" * 2**20 Index: Lib/test/test_httpservers.py =================================================================== --- Lib/test/test_httpservers.py (révision 78770) +++ Lib/test/test_httpservers.py (copie de travail) @@ -16,10 +16,10 @@ import urllib import httplib import tempfile -import threading import unittest from test import test_support +threading = test_support.import_module('threading') class NoLogRequestHandler: Index: Lib/test/test_contextlib.py =================================================================== --- Lib/test/test_contextlib.py (révision 78770) +++ Lib/test/test_contextlib.py (copie de travail) @@ -5,10 +5,13 @@ import sys import tempfile import unittest -import threading from contextlib import * # Tests __all__ from test import test_support import warnings +try: + import threading +except ImportError: + threading = None class ContextManagerTestCase(unittest.TestCase): @@ -287,6 +290,7 @@ except os.error: pass +@unittest.skipUnless(threading, 'Threading required for this test.') class LockContextTestCase(unittest.TestCase): def boilerPlate(self, lock, locked): Index: Lib/test/test_threaded_import.py =================================================================== --- Lib/test/test_threaded_import.py (révision 78770) +++ Lib/test/test_threaded_import.py (copie de travail) @@ -5,9 +5,9 @@ # complains several times about module random having no attribute # randrange, and then Python hangs. -import thread import unittest -from test.test_support import verbose, TestFailed +from test.test_support import verbose, TestFailed, import_module +thread = import_module('thread') critical_section = thread.allocate_lock() done = thread.allocate_lock() Index: Lib/test/test_ftplib.py =================================================================== --- Lib/test/test_ftplib.py (révision 78770) +++ Lib/test/test_ftplib.py (copie de travail) @@ -4,7 +4,6 @@ # environment import ftplib -import threading import asyncore import asynchat import socket @@ -19,8 +18,8 @@ from unittest import TestCase from test import test_support from test.test_support import HOST +threading = test_support.import_module('threading') - # the dummy data returned by server over the data channel when # RETR, LIST and NLST commands are issued RETR_DATA = 'abcde12345\r\n' * 1000 Index: Lib/test/test_telnetlib.py =================================================================== --- Lib/test/test_telnetlib.py (révision 78770) +++ Lib/test/test_telnetlib.py (copie de travail) @@ -1,11 +1,11 @@ import socket -import threading import telnetlib import time import Queue from unittest import TestCase from test import test_support +threading = test_support.import_module('threading') HOST = test_support.HOST EOF_sigil = object() Index: Lib/test/fork_wait.py =================================================================== --- Lib/test/fork_wait.py (révision 78770) +++ Lib/test/fork_wait.py (copie de travail) @@ -1,6 +1,6 @@ """This test case provides support for checking forking and wait behavior. -To test different wait behavior, overrise the wait_impl method. +To test different wait behavior, override the wait_impl method. We want fork1() semantics -- only the forking thread survives in the child after a fork(). @@ -12,7 +12,9 @@ the same application, the present example should work just fine. DC """ -import os, sys, time, thread, unittest +import os, sys, time, unittest +import test.test_support as test_support +thread = test_support.import_module('thread') LONGSLEEP = 2 SHORTSLEEP = 0.5 Index: Lib/test/test_threading_local.py =================================================================== --- Lib/test/test_threading_local.py (révision 78770) +++ Lib/test/test_threading_local.py (copie de travail) @@ -1,7 +1,7 @@ import unittest from doctest import DocTestSuite from test import test_support -import threading +threading = test_support.import_module('threading') import weakref import gc Index: Lib/test/test_multiprocessing.py =================================================================== --- Lib/test/test_multiprocessing.py (révision 78770) +++ Lib/test/test_multiprocessing.py (copie de travail) @@ -5,7 +5,6 @@ # import unittest -import threading import Queue import time import sys @@ -19,9 +18,8 @@ import logging from test import test_support from StringIO import StringIO - - _multiprocessing = test_support.import_module('_multiprocessing') +import threading # Work around broken sem_open implementations test_support.import_module('multiprocessing.synchronize') Index: Lib/test/test_threading.py =================================================================== --- Lib/test/test_threading.py (révision 78770) +++ Lib/test/test_threading.py (copie de travail) @@ -5,8 +5,8 @@ import random import re import sys -import threading -import thread +thread = test.test_support.import_module('thread') +threading = test.test_support.import_module('threading') import time import unittest import weakref Index: Lib/test/test_support.py =================================================================== --- Lib/test/test_support.py (révision 78770) +++ Lib/test/test_support.py (copie de travail) @@ -17,6 +17,10 @@ import importlib import UserDict import re +try: + import thread +except ImportError: + thread = None __all__ = ["Error", "TestFailed", "ResourceDenied", "import_module", "verbose", "use_resources", "max_memuse", "record_original_stdout", @@ -42,7 +46,7 @@ """Test skipped because it requested a disallowed resource. This is raised when a test calls requires() for a resource that - has not be enabled. It is used to distinguish between expected + has not been enabled. It is used to distinguish between expected and unexpected skips. """ @@ -1048,11 +1052,14 @@ # at the end of a test run. def threading_setup(): - import thread - return thread._count(), + if thread: + return thread._count(), + else: + return 1, def threading_cleanup(nb_threads): - import thread + if not thread: + return import time _MAX_COUNT = 10 @@ -1064,6 +1071,13 @@ # XXX print a warning in case of failure? def reap_threads(func): + """Use this function when threads are being used. This will + ensure that the threads are cleaned up even when the test fails. + If threading is unavailable this function does nothing. + """ + if not thread: + return func + @functools.wraps(func) def decorator(*args): key = threading_setup()