]> granicus.if.org Git - python/commitdiff
Use a file context manager for test_ioctl.
authorBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 23:54:28 +0000 (23:54 +0000)
committerBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 23:54:28 +0000 (23:54 +0000)
Lib/test/test_ioctl.py

index 6c7ab0c0341d94d8d6e08d0d1cf4a0f750b63271..817d62675e6faefee10f5feabab0dc553788fed0 100644 (file)
@@ -30,10 +30,10 @@ class IoctlTests(unittest.TestCase):
         # If this process has been put into the background, TIOCGPGRP returns
         # the session ID instead of the process group id.
         ids = (os.getpgrp(), os.getsid(0))
-        tty = open("/dev/tty", "r")
-        r = fcntl.ioctl(tty, termios.TIOCGPGRP, "    ")
-        rpgrp = struct.unpack("i", r)[0]
-        self.assertIn(rpgrp, ids)
+        with open("/dev/tty", "r") as tty:
+            r = fcntl.ioctl(tty, termios.TIOCGPGRP, "    ")
+            rpgrp = struct.unpack("i", r)[0]
+            self.assertIn(rpgrp, ids)
 
     def _check_ioctl_mutate_len(self, nbytes=None):
         buf = array.array('i')