Browse Source

[1828] Cleanup code by using with

Mukund Sivaraman 13 years ago
parent
commit
7d741f7ea2
1 changed files with 7 additions and 7 deletions
  1. 7 7
      src/lib/python/isc/bind10/tests/sockcreator_test.py

+ 7 - 7
src/lib/python/isc/bind10/tests/sockcreator_test.py

@@ -304,12 +304,14 @@ class WrapTests(unittest.TestCase):
         # Transfer the descriptor
         send_fd(t1.fileno(), p1.fileno())
         p1.close()
-        p1 = socket.fromfd(t2.read_fd(), socket.AF_UNIX, socket.SOCK_STREAM)
 
-        # Now, pass some data trough the socket
-        p1.send(b'A')
-        data = p2.recv(1)
-        self.assertEqual(b'A', data)
+        with socket.fromfd(t2.read_fd(), socket.AF_UNIX, socket.SOCK_STREAM) as p1:
+            # Now, pass some data trough the socket
+            p1.send(b'A')
+            data = p2.recv(1)
+            self.assertEqual(b'A', data)
+
+        p2.close()
 
         # Test the wrapping didn't hurt the socket's usual methods
         t1.send(b'B')
@@ -319,8 +321,6 @@ class WrapTests(unittest.TestCase):
         data = t1.recv(1)
         self.assertEqual(b'C', data)
 
-        p1.close()
-        p2.close()
         t1.close()
         t2.close()