mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
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 changed files with 105 additions and 94 deletions
|
@ -1,4 +1,4 @@
|
||||||
from test_support import verify
|
from test_support import verify, TESTFN, unlink
|
||||||
import mmap
|
import mmap
|
||||||
import os, re, sys
|
import os, re, sys
|
||||||
|
|
||||||
|
@ -7,9 +7,10 @@ PAGESIZE = mmap.PAGESIZE
|
||||||
def test_both():
|
def test_both():
|
||||||
"Test mmap module on Unix systems and Windows"
|
"Test mmap module on Unix systems and Windows"
|
||||||
|
|
||||||
# Create an mmap'ed file
|
# Create a file to be mmap'ed.
|
||||||
f = open('foo', 'w+')
|
f = open(TESTFN, 'w+')
|
||||||
|
|
||||||
|
try: # unlink TESTFN no matter what
|
||||||
# Write 2 pages worth of data to the file
|
# Write 2 pages worth of data to the file
|
||||||
f.write('\0'* PAGESIZE)
|
f.write('\0'* PAGESIZE)
|
||||||
f.write('foo')
|
f.write('foo')
|
||||||
|
@ -118,7 +119,17 @@ def test_both():
|
||||||
verify(0, 'Could seek beyond the new size')
|
verify(0, 'Could seek beyond the new size')
|
||||||
|
|
||||||
m.close()
|
m.close()
|
||||||
os.unlink("foo")
|
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
f.close()
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
unlink(TESTFN)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
print ' Test passed'
|
print ' Test passed'
|
||||||
|
|
||||||
test_both()
|
test_both()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue