]> granicus.if.org Git - python/commitdiff
asyncio/tests: Fix some ResourceWarnings
authorYury Selivanov <yselivanov@sprymix.com>
Thu, 17 Dec 2015 00:51:09 +0000 (19:51 -0500)
committerYury Selivanov <yselivanov@sprymix.com>
Thu, 17 Dec 2015 00:51:09 +0000 (19:51 -0500)
Lib/test/test_asyncio/test_base_events.py
Lib/test/test_asyncio/test_streams.py

index a46ac166d1182a155c04f340d1c12a1f40731351..0166660858f6935caffcc3774559ba838e85f9c7 100644 (file)
@@ -127,23 +127,27 @@ class BaseEventTests(test_utils.TestCase):
 
     def test_check_resolved_address(self):
         sock = socket.socket(socket.AF_INET)
-        base_events._check_resolved_address(sock, ('1.2.3.4', 1))
+        with sock:
+            base_events._check_resolved_address(sock, ('1.2.3.4', 1))
 
         sock = socket.socket(socket.AF_INET6)
-        base_events._check_resolved_address(sock, ('::3', 1))
-        base_events._check_resolved_address(sock, ('::3%lo0', 1))
-        self.assertRaises(ValueError,
-                          base_events._check_resolved_address, sock, ('foo', 1))
+        with sock:
+            base_events._check_resolved_address(sock, ('::3', 1))
+            base_events._check_resolved_address(sock, ('::3%lo0', 1))
+            with self.assertRaises(ValueError):
+                base_events._check_resolved_address(sock, ('foo', 1))
 
     def test_check_resolved_sock_type(self):
         # Ensure we ignore extra flags in sock.type.
         if hasattr(socket, 'SOCK_NONBLOCK'):
             sock = socket.socket(type=socket.SOCK_STREAM | socket.SOCK_NONBLOCK)
-            base_events._check_resolved_address(sock, ('1.2.3.4', 1))
+            with sock:
+                base_events._check_resolved_address(sock, ('1.2.3.4', 1))
 
         if hasattr(socket, 'SOCK_CLOEXEC'):
             sock = socket.socket(type=socket.SOCK_STREAM | socket.SOCK_CLOEXEC)
-            base_events._check_resolved_address(sock, ('1.2.3.4', 1))
+            with sock:
+                base_events._check_resolved_address(sock, ('1.2.3.4', 1))
 
 
 class BaseEventLoopTests(test_utils.TestCase):
index 0a9762d1fda73190a8c6f68b881f6eb119d78005..3b115b14bec86edab94423af6bd9d21bedb61c20 100644 (file)
@@ -647,12 +647,13 @@ os.close(fd)
         def server():
             # Runs in a separate thread.
             sock = socket.socket()
-            sock.bind(('localhost', 0))
-            sock.listen(1)
-            addr = sock.getsockname()
-            q.put(addr)
-            clt, _ = sock.accept()
-            clt.close()
+            with sock:
+                sock.bind(('localhost', 0))
+                sock.listen(1)
+                addr = sock.getsockname()
+                q.put(addr)
+                clt, _ = sock.accept()
+                clt.close()
 
         @asyncio.coroutine
         def client(host, port):