Skip to content

Commit

Permalink
#521: assume python >= 2.6 and use tempfile.NamedTemporaryFile(..., d…
Browse files Browse the repository at this point in the history
…elete=False)
  • Loading branch information
giampaolo committed Nov 2, 2014
1 parent 076e5d1 commit 12be76f
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions test/test_psutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,15 @@ def pyrun(src):
"""
if PY3:
src = bytes(src, 'ascii')
# could have used NamedTemporaryFile(delete=False) but it's
# >= 2.6 only
fd, path = tempfile.mkstemp(prefix=TESTFILE_PREFIX)
_testfiles.append(path)
with open(path, 'wb') as f:
try:
f.write(src)
f.flush()
subp = get_test_subprocess([PYTHON, f.name], stdout=None,
stderr=None)
wait_for_pid(subp.pid)
return subp
finally:
os.close(fd)
with tempfile.NamedTemporaryFile(
prefix=TESTFILE_PREFIX, delete=False) as f:
_testfiles.append(f.name)
f.write(src)
f.flush()
subp = get_test_subprocess([PYTHON, f.name], stdout=None,
stderr=None)
wait_for_pid(subp.pid)
return subp


def warn(msg):
Expand Down

0 comments on commit 12be76f

Please sign in to comment.