Fix the @test_NNNN_tmp file terds being left in whatever your $PWD was

when test_subprocess was run.
This commit is contained in:
Gregory P. Smith 2011-03-15 02:04:11 -04:00
parent 42da663e6f
commit 81ce68597c
1 changed files with 5 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import errno
import tempfile import tempfile
import time import time
import re import re
import shutil
mswindows = (sys.platform == "win32") mswindows = (sys.platform == "win32")
@ -450,11 +451,12 @@ class ProcessTestCase(BaseTestCase):
else: else:
max_handles = 2050 # too much for (at least some) Windows setups max_handles = 2050 # too much for (at least some) Windows setups
handles = [] handles = []
tmpdir = tempfile.mkdtemp()
try: try:
for i in range(max_handles): for i in range(max_handles):
try: try:
handles.append(os.open(support.TESTFN, tmpfile = os.path.join(tmpdir, support.TESTFN)
os.O_WRONLY | os.O_CREAT)) handles.append(os.open(tmpfile, os.O_WRONLY|os.O_CREAT))
except OSError as e: except OSError as e:
if e.errno != errno.EMFILE: if e.errno != errno.EMFILE:
raise raise
@ -479,6 +481,7 @@ class ProcessTestCase(BaseTestCase):
finally: finally:
for h in handles: for h in handles:
os.close(h) os.close(h)
shutil.rmtree(tmpdir)
def test_list2cmdline(self): def test_list2cmdline(self):
self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']), self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']),