mirror of https://github.com/python/cpython
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:
parent
8c3e91efaf
commit
fd69208b78
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue