Commit 3e511f89 authored by Berker Peksag's avatar Berker Peksag

Issue #25249: Remove unneeded mkstemp helper in test_subprocess

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.
parents a7d1d45b d63f262f
...@@ -37,16 +37,6 @@ else: ...@@ -37,16 +37,6 @@ else:
SETBINARY = '' 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): class BaseTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
# Try to minimize the number of children we have so this test # Try to minimize the number of children we have so this test
...@@ -1150,9 +1140,9 @@ class ProcessTestCase(BaseTestCase): ...@@ -1150,9 +1140,9 @@ class ProcessTestCase(BaseTestCase):
def test_handles_closed_on_exception(self): def test_handles_closed_on_exception(self):
# If CreateProcess exits with an error, ensure the # If CreateProcess exits with an error, ensure the
# duplicate output handles are released # duplicate output handles are released
ifhandle, ifname = mkstemp() ifhandle, ifname = tempfile.mkstemp()
ofhandle, ofname = mkstemp() ofhandle, ofname = tempfile.mkstemp()
efhandle, efname = mkstemp() efhandle, efname = tempfile.mkstemp()
try: try:
subprocess.Popen (["*"], stdin=ifhandle, stdout=ofhandle, subprocess.Popen (["*"], stdin=ifhandle, stdout=ofhandle,
stderr=efhandle) stderr=efhandle)
...@@ -1524,7 +1514,7 @@ class POSIXProcessTestCase(BaseTestCase): ...@@ -1524,7 +1514,7 @@ class POSIXProcessTestCase(BaseTestCase):
def test_args_string(self): def test_args_string(self):
# args is a string # args is a string
fd, fname = mkstemp() fd, fname = tempfile.mkstemp()
# reopen in text mode # reopen in text mode
with open(fd, "w", errors="surrogateescape") as fobj: with open(fd, "w", errors="surrogateescape") as fobj:
fobj.write("#!/bin/sh\n") fobj.write("#!/bin/sh\n")
...@@ -1569,7 +1559,7 @@ class POSIXProcessTestCase(BaseTestCase): ...@@ -1569,7 +1559,7 @@ class POSIXProcessTestCase(BaseTestCase):
def test_call_string(self): def test_call_string(self):
# call() function with string argument on UNIX # call() function with string argument on UNIX
fd, fname = mkstemp() fd, fname = tempfile.mkstemp()
# reopen in text mode # reopen in text mode
with open(fd, "w", errors="surrogateescape") as fobj: with open(fd, "w", errors="surrogateescape") as fobj:
fobj.write("#!/bin/sh\n") fobj.write("#!/bin/sh\n")
...@@ -1762,7 +1752,7 @@ class POSIXProcessTestCase(BaseTestCase): ...@@ -1762,7 +1752,7 @@ class POSIXProcessTestCase(BaseTestCase):
def test_remapping_std_fds(self): def test_remapping_std_fds(self):
# open up some temporary files # open up some temporary files
temps = [mkstemp() for i in range(3)] temps = [tempfile.mkstemp() for i in range(3)]
try: try:
temp_fds = [fd for fd, fname in temps] temp_fds = [fd for fd, fname in temps]
...@@ -1807,7 +1797,7 @@ class POSIXProcessTestCase(BaseTestCase): ...@@ -1807,7 +1797,7 @@ class POSIXProcessTestCase(BaseTestCase):
def check_swap_fds(self, stdin_no, stdout_no, stderr_no): def check_swap_fds(self, stdin_no, stdout_no, stderr_no):
# open up some temporary files # 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] temp_fds = [fd for fd, fname in temps]
try: try:
# unlink the files -- we won't need to reopen them # unlink the files -- we won't need to reopen them
...@@ -2534,7 +2524,7 @@ class CommandsWithSpaces (BaseTestCase): ...@@ -2534,7 +2524,7 @@ class CommandsWithSpaces (BaseTestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
f, fname = mkstemp(".py", "te st") f, fname = tempfile.mkstemp(".py", "te st")
self.fname = fname.lower () self.fname = fname.lower ()
os.write(f, b"import sys;" os.write(f, b"import sys;"
b"sys.stdout.write('%d %s' % (len(sys.argv), [a.lower () for a in sys.argv]))" b"sys.stdout.write('%d %s' % (len(sys.argv), [a.lower () for a in sys.argv]))"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment