Change test_mmap.py to use test_support.TESTFN instead of hardcoded "foo",

and wrap the body in try/finally to ensure TESTFN gets cleaned up no
matter what.
This commit is contained in:
Tim Peters 2001-05-10 20:03:04 +00:00
parent 8c3e91efaf
commit fd69208b78
1 changed files with 105 additions and 94 deletions

View File

@ -1,4 +1,4 @@
from test_support import verify
from test_support import verify, TESTFN, unlink
import mmap
import os, re, sys
@ -7,9 +7,10 @@ PAGESIZE = mmap.PAGESIZE
def test_both():
"Test mmap module on Unix systems and Windows"
# Create an mmap'ed file
f = open('foo', 'w+')
# Create a file to be mmap'ed.
f = open(TESTFN, 'w+')
try: # unlink TESTFN no matter what
# Write 2 pages worth of data to the file
f.write('\0'* PAGESIZE)
f.write('foo')
@ -118,7 +119,17 @@ def test_both():
verify(0, 'Could seek beyond the new size')
m.close()
os.unlink("foo")
finally:
try:
f.close()
except OSError:
pass
try:
unlink(TESTFN)
except OSError:
pass
print ' Test passed'
test_both()