summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_mmap.py
diff options
context:
space:
mode:
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2009-02-18 16:38:00 (GMT)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2009-02-18 16:38:00 (GMT)
commit0654ccd1d23986accb99c69e84369b99f9cdc8e2 (patch)
treecb8fb71b6573ef563641d0f27ce4de532edac144 /Lib/test/test_mmap.py
parent14d34a0e43ce1b4dba1da50376011cd7a18dba49 (diff)
downloadcpython-0654ccd1d23986accb99c69e84369b99f9cdc8e2.zip
cpython-0654ccd1d23986accb99c69e84369b99f9cdc8e2.tar.gz
cpython-0654ccd1d23986accb99c69e84369b99f9cdc8e2.tar.bz2
Merged revisions 69714,69718 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r69714 | hirokazu.yamamoto | 2009-02-17 19:12:10 +0900 | 1 line Issue #5292: Fixed mmap crash on its boundary access m[len(m)]. ........ r69718 | hirokazu.yamamoto | 2009-02-17 22:17:26 +0900 | 3 lines Issue #5282: Fixed mmap resize on 32bit windows and unix. When offset > 0, The file was resized to wrong size. ........
Diffstat (limited to 'Lib/test/test_mmap.py')
-rw-r--r--Lib/test/test_mmap.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 9fe044f..8b7e3e2 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -42,6 +42,10 @@ class MmapTests(unittest.TestCase):
self.assertEqual(m[0], 0)
self.assertEqual(m[0:3], b'\0\0\0')
+ # Shouldn't crash on boundary (Issue #5292)
+ self.assertRaises(IndexError, m.__getitem__, len(m))
+ self.assertRaises(IndexError, m.__setitem__, len(m), b'\0')
+
# Modify the file's content
m[0] = b'3'[0]
m[PAGESIZE +3: PAGESIZE +3+3] = b'bar'
@@ -412,6 +416,27 @@ class MmapTests(unittest.TestCase):
m = mmap.mmap(f.fileno(), mapsize - halfsize, offset=halfsize)
self.assertEqual(m[0:3], b'foo')
f.close()
+
+ # Try resizing map
+ try:
+ m.resize(512)
+ except SystemError:
+ pass
+ else:
+ # resize() is supported
+ self.assertEqual(len(m), 512)
+ # Check that we can no longer seek beyond the new size.
+ self.assertRaises(ValueError, m.seek, 513, 0)
+ # Check that the content is not changed
+ self.assertEqual(m[0:3], b'foo')
+
+ # Check that the underlying file is truncated too
+ f = open(TESTFN)
+ f.seek(0, 2)
+ self.assertEqual(f.tell(), halfsize + 512)
+ f.close()
+ self.assertEqual(m.size(), halfsize + 512)
+
m.close()
finally: