From fb54405c0f35e67545da94a25e35d5571c7c869c Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Tue, 24 Sep 2002 16:21:36 +0000 Subject: [PATCH] Replaced this with the 2.3 test_mmap, which contains Windows-specific fixes for the "try to resize it" test (Windows grows the underlying file then, and that screws up later tests that assume the underlying file has not changed size, as was true on the box (Linux) the person who changed this test in 2.2 to begin with tried it on). Without this change, test_mmap fails on Windows. Now it passes again. --- Lib/test/test_mmap.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index d208d44b4f95..417080f0055e 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -1,4 +1,4 @@ -from test_support import verify, vereq, TESTFN +from test.test_support import verify, vereq, TESTFN import mmap import os, re @@ -18,7 +18,6 @@ def test_both(): f.write('foo') f.write('\0'* (PAGESIZE-3) ) f.flush() - m = mmap.mmap(f.fileno(), 2 * PAGESIZE) f.close() @@ -103,7 +102,7 @@ def test_both(): # Try resizing map print ' Attempting resize()' try: - m.resize( 512 ) + m.resize(512) except SystemError: # resize() not supported # No messages are printed, since the output of this test suite @@ -197,14 +196,22 @@ def test_both(): m = mmap.mmap(f.fileno(), mapsize+1) except ValueError: # we do not expect a ValueError on Windows + # CAUTION: This also changes the size of the file on disk, and + # later tests assume that the length hasn't changed. We need to + # repair that. if sys.platform.startswith('win'): verify(0, "Opening mmap with size+1 should work on Windows.") else: # we expect a ValueError on Unix, but not on Windows if not sys.platform.startswith('win'): verify(0, "Opening mmap with size+1 should raise ValueError.") - del m - del f + m.close() + f.close() + if sys.platform.startswith('win'): + # Repair damage from the resizing test. + f = open(TESTFN, 'r+b') + f.truncate(mapsize) + f.close() print " Opening mmap with access=ACCESS_WRITE" f = open(TESTFN, "r+b") @@ -214,8 +221,12 @@ def test_both(): verify(m[:] == 'c'*mapsize, "Write-through memory map memory not updated properly.") m.flush() - del m, f - verify(open(TESTFN).read() == 'c'*mapsize, + m.close() + f.close() + f = open(TESTFN, 'rb') + stuff = f.read() + f.close() + verify(stuff == 'c'*mapsize, "Write-through memory map data file not updated properly.") print " Opening mmap with access=ACCESS_COPY" -- 2.47.3