Index: Lib/test/test_mmap.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_mmap.py,v retrieving revision 1.30 diff -c -r1.30 test_mmap.py *** Lib/test/test_mmap.py 13 Jan 2003 21:38:45 -0000 1.30 --- Lib/test/test_mmap.py 10 Apr 2003 18:03:22 -0000 *************** *** 1,9 **** from test.test_support import verify, vereq, TESTFN import mmap ! import os, re PAGESIZE = mmap.PAGESIZE def test_both(): "Test mmap module on Unix systems and Windows" --- 1,54 ---- from test.test_support import verify, vereq, TESTFN import mmap ! import os, re, sys PAGESIZE = mmap.PAGESIZE + def make_mmap_file(f, halfsize): + # Write 2 pages worth of data to the file + f.write('\0'* halfsize) + f.write('foo') + f.write('\0'* (halfsize-3) ) + f.flush() + return mmap.mmap(f.fileno(), 2 * PAGESIZE) + + def test_offset(): + f = open(TESTFN, 'w+') + + try: # unlink TESTFN no matter what + halfsize = PAGESIZE + if sys.platform.startswith('win'): + # halfsize must be a multiple of the allocation granularity (64k) + halfsize = 64 * 1024 * 1024 + m = make_mmap_file(f, halfsize) + m.close() + f.close() + + mapsize = halfsize * 2 + # Try invalid offset + f = open(TESTFN, "r+b") + for offset in [-2, -1, None]: + try: + m = mmap.mmap(f.fileno(), mapsize, offset=offset) + except (ValueError, TypeError): + pass + else: + verify(0, "Invalid offset should raise ValueError.") + f.close() + + # Try valid offset, hopefully 8192 works on all OSes + f = open(TESTFN, "r+b") + m = mmap.mmap(f.fileno(), mapsize - halfsize, offset=halfsize) + verify(m[0:3] == 'foo', "Invalid data found using offset.") + f.close() + + finally: + f.close() + try: + os.unlink(TESTFN) + except OSError: + pass + def test_both(): "Test mmap module on Unix systems and Windows" *************** *** 13,24 **** 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') ! f.write('\0'* (PAGESIZE-3) ) ! f.flush() ! m = mmap.mmap(f.fileno(), 2 * PAGESIZE) f.close() # Simple sanity checks --- 58,64 ---- f = open(TESTFN, 'w+') try: # unlink TESTFN no matter what ! m = make_mmap_file(f, PAGESIZE) f.close() # Simple sanity checks *************** *** 311,317 **** finally: os.unlink(TESTFN) - print ' Test passed' ! test_both() --- 351,361 ---- finally: os.unlink(TESTFN) print ' Test passed' ! def test_main(): ! test_offset() ! test_both() ! ! if __name__ == '__main__': ! test_main()