]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Replaced this with the 2.3 test_mmap, which contains Windows-specific
authorTim Peters <tim.peters@gmail.com>
Tue, 24 Sep 2002 16:21:36 +0000 (16:21 +0000)
committerTim Peters <tim.peters@gmail.com>
Tue, 24 Sep 2002 16:21:36 +0000 (16:21 +0000)
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

index d208d44b4f95dd4d086d6abf5aab373c89967c39..417080f0055efe1ac05b9a264a0204571482ab4d 100644 (file)
@@ -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"