]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #25249: Remove unneeded mkstemp helper in test_subprocess
authorBerker Peksag <berker.peksag@gmail.com>
Mon, 28 Sep 2015 12:37:57 +0000 (15:37 +0300)
committerBerker Peksag <berker.peksag@gmail.com>
Mon, 28 Sep 2015 12:37:57 +0000 (15:37 +0300)
The helper was added in 76641824cf05 11 years ago and it can be
removed now since all supported Python versions have tempfile.mkstemp().

Patch by Nir Soffer.

Lib/test/test_subprocess.py

index 0efcdbf25347fb1cdab5b05246bd2be6d23ea571..06de10851e83996ee32e7127271a17723593c9bd 100644 (file)
@@ -32,16 +32,6 @@ else:
     SETBINARY = ''
 
 
-try:
-    mkstemp = tempfile.mkstemp
-except AttributeError:
-    # tempfile.mkstemp is not available
-    def mkstemp():
-        """Replacement for mkstemp, calling mktemp."""
-        fname = tempfile.mktemp()
-        return os.open(fname, os.O_RDWR|os.O_CREAT), fname
-
-
 class BaseTestCase(unittest.TestCase):
     def setUp(self):
         # Try to minimize the number of children we have so this test
@@ -666,9 +656,9 @@ class ProcessTestCase(BaseTestCase):
     def test_handles_closed_on_exception(self):
         # If CreateProcess exits with an error, ensure the
         # duplicate output handles are released
-        ifhandle, ifname = mkstemp()
-        ofhandle, ofname = mkstemp()
-        efhandle, efname = mkstemp()
+        ifhandle, ifname = tempfile.mkstemp()
+        ofhandle, ofname = tempfile.mkstemp()
+        efhandle, efname = tempfile.mkstemp()
         try:
             subprocess.Popen (["*"], stdin=ifhandle, stdout=ofhandle,
               stderr=efhandle)
@@ -858,7 +848,7 @@ class POSIXProcessTestCase(BaseTestCase):
 
     def test_args_string(self):
         # args is a string
-        f, fname = mkstemp()
+        f, fname = tempfile.mkstemp()
         os.write(f, "#!/bin/sh\n")
         os.write(f, "exec '%s' -c 'import sys; sys.exit(47)'\n" %
                     sys.executable)
@@ -902,7 +892,7 @@ class POSIXProcessTestCase(BaseTestCase):
 
     def test_call_string(self):
         # call() function with string argument on UNIX
-        f, fname = mkstemp()
+        f, fname = tempfile.mkstemp()
         os.write(f, "#!/bin/sh\n")
         os.write(f, "exec '%s' -c 'import sys; sys.exit(47)'\n" %
                     sys.executable)
@@ -1058,7 +1048,7 @@ class POSIXProcessTestCase(BaseTestCase):
 
     def check_swap_fds(self, stdin_no, stdout_no, stderr_no):
         # open up some temporary files
-        temps = [mkstemp() for i in range(3)]
+        temps = [tempfile.mkstemp() for i in range(3)]
         temp_fds = [fd for fd, fname in temps]
         try:
             # unlink the files -- we won't need to reopen them
@@ -1379,7 +1369,7 @@ class CommandsWithSpaces (BaseTestCase):
 
     def setUp(self):
         super(CommandsWithSpaces, self).setUp()
-        f, fname = mkstemp(".py", "te st")
+        f, fname = tempfile.mkstemp(".py", "te st")
         self.fname = fname.lower ()
         os.write(f, b"import sys;"
                     b"sys.stdout.write('%d %s' % (len(sys.argv), [a.lower () for a in sys.argv]))"