diff --git a/Lib/test/test_normalization.py b/Lib/test/test_normalization.py --- a/Lib/test/test_normalization.py +++ b/Lib/test/test_normalization.py @@ -45,6 +45,7 @@ check=check_version) except (IOError, HTTPException): self.skipTest("Could not retrieve " + TESTDATAURL) + self.addCleanup(testdata.close) for line in testdata: if '#' in line: line = line.split('#')[0] diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py --- a/Lib/test/test_timeout.py +++ b/Lib/test/test_timeout.py @@ -99,12 +99,14 @@ fuzz = 2.0 def setUp(self): - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock_stream = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.sock_dgram = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.addr_remote = ('www.python.org.', 80) self.localhost = '127.0.0.1' def tearDown(self): - self.sock.close() + self.sock_stream.close() + self.sock_dgram.close() def testConnectTimeout(self): # Choose a private address that is unlikely to exist to prevent @@ -116,10 +118,10 @@ # Test connect() timeout _timeout = 0.001 - self.sock.settimeout(_timeout) + self.sock_stream.settimeout(_timeout) _t1 = time.time() - self.assertRaises(socket.error, self.sock.connect, addr) + self.assertRaises(socket.error, self.sock_stream.connect, addr) _t2 = time.time() _delta = abs(_t1 - _t2) @@ -132,11 +134,11 @@ _timeout = 0.02 with support.transient_internet(self.addr_remote[0]): - self.sock.connect(self.addr_remote) - self.sock.settimeout(_timeout) + self.sock_stream.connect(self.addr_remote) + self.sock_stream.settimeout(_timeout) _t1 = time.time() - self.assertRaises(socket.timeout, self.sock.recv, 1024) + self.assertRaises(socket.timeout, self.sock_stream.recv, 1024) _t2 = time.time() _delta = abs(_t1 - _t2) @@ -147,13 +149,13 @@ def testAcceptTimeout(self): # Test accept() timeout _timeout = 2 - self.sock.settimeout(_timeout) + self.sock_stream.settimeout(_timeout) # Prevent "Address already in use" socket exceptions - support.bind_port(self.sock, self.localhost) - self.sock.listen(5) + support.bind_port(self.sock_stream, self.localhost) + self.sock_stream.listen(5) _t1 = time.time() - self.assertRaises(socket.error, self.sock.accept) + self.assertRaises(socket.error, self.sock_stream.accept) _t2 = time.time() _delta = abs(_t1 - _t2) @@ -164,13 +166,12 @@ def testRecvfromTimeout(self): # Test recvfrom() timeout _timeout = 2 - self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - self.sock.settimeout(_timeout) + self.sock_dgram.settimeout(_timeout) # Prevent "Address already in use" socket exceptions - support.bind_port(self.sock, self.localhost) + support.bind_port(self.sock_dgram, self.localhost) _t1 = time.time() - self.assertRaises(socket.error, self.sock.recvfrom, 8192) + self.assertRaises(socket.error, self.sock_dgram.recvfrom, 8192) _t2 = time.time() _delta = abs(_t1 - _t2) diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -637,6 +637,8 @@ #due to thread scheduling) self.assertGreaterEqual(len(self.RequestHandler.myRequests[-1]), 2) + p("close")() + #test special attribute access on the serverproxy, through the __call__ #function. class KeepaliveServerTestCase2(BaseKeepaliveServerTestCase): @@ -660,6 +662,8 @@ self.assertGreaterEqual(len(self.RequestHandler.myRequests[-1]), 2) self.assertGreaterEqual(len(self.RequestHandler.myRequests[-2]), 2) + p("close")() + def test_transport(self): p = xmlrpclib.ServerProxy(URL) #do some requests with close. @@ -667,6 +671,7 @@ p("transport").close() #same as above, really. self.assertEqual(p.pow(6,8), 6**8) self.assertEqual(len(self.RequestHandler.myRequests), 2) + p("close")() #A test case that verifies that gzip encoding works in both directions #(for a request and the response) @@ -709,6 +714,7 @@ self.assertEqual(p.pow(6,8), 6**8) b = self.RequestHandler.content_length self.assertTrue(a>b) + p("close")() def test_bad_gzip_request(self): t = self.Transport() @@ -719,6 +725,7 @@ re.compile(r"\b400\b")) with cm: p.pow(6, 8) + p("close")() def test_gsip_response(self): t = self.Transport() @@ -732,6 +739,7 @@ b = t.response_length self.requestHandler.encode_threshold = old self.assertTrue(a>b) + p("close")() #Test special attributes of the ServerProxy object class ServerProxyTestCase(unittest.TestCase): diff --git a/Lib/tkinter/test/test_tkinter/test_loadtk.py b/Lib/tkinter/test/test_tkinter/test_loadtk.py --- a/Lib/tkinter/test/test_tkinter/test_loadtk.py +++ b/Lib/tkinter/test/test_tkinter/test_loadtk.py @@ -31,7 +31,8 @@ # doesn't actually carry through to the process level # because they don't support unsetenv # If that's the case, abort. - display = os.popen('echo $DISPLAY').read().strip() + with os.popen('echo $DISPLAY') as pipe: + display = pipe.read().strip() if display: return