summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTravis E. Oliphant <oliphant@enthought.com>2007-10-23 02:40:56 (GMT)
committerTravis E. Oliphant <oliphant@enthought.com>2007-10-23 02:40:56 (GMT)
commit8feafab3462500d33c0bc98787649db4502894f8 (patch)
tree23a06e5c80e6ec0879b8f795412d0d60481fa95b /Lib
parent5e81270b22ee6cfe6d7ead43ccbc258964cf14a7 (diff)
downloadcpython-8feafab3462500d33c0bc98787649db4502894f8.zip
cpython-8feafab3462500d33c0bc98787649db4502894f8.tar.gz
cpython-8feafab3462500d33c0bc98787649db4502894f8.tar.bz2
Add phuang patch from Issue 708374 which adds offset parameter to mmap module.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_mmap.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 769eaed..b4f85fc 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -340,6 +340,50 @@ class MmapTests(unittest.TestCase):
m[start:stop:step] = data
self.assertEquals(m[:], "".join(L))
+ def make_mmap_file (self, 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(), 0)
+
+ def test_offset (self):
+ f = open (TESTFN, 'w+b')
+
+ try: # unlink TESTFN no matter what
+ halfsize = mmap.ALLOCATIONGRANULARITY
+ m = self.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)
+ self.assertEqual(0, 1)
+ except (ValueError, TypeError, OverflowError):
+ pass
+ else:
+ self.assertEqual(0, 0)
+ 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)
+ self.assertEqual(m[0:3], 'foo')
+ f.close()
+ m.close()
+
+ finally:
+ f.close()
+ try:
+ os.unlink(TESTFN)
+ except OSError:
+ pass
+
def test_main():
run_unittest(MmapTests)