summaryrefslogtreecommitdiff
path: root/Lib/test/test_mmap.py
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2012-09-10 00:22:39 +0200
committerJesus Cea <jcea@jcea.es>2012-09-10 00:22:39 +0200
commit8b54d6d73312186b4736cdf69a4e2e46ba15784c (patch)
tree82b6af0a0544635996bf5c899c6d58036816b1a8 /Lib/test/test_mmap.py
parent10fc104fede2449468fb9488bb44a9663382b3a8 (diff)
downloadcpython-git-8b54d6d73312186b4736cdf69a4e2e46ba15784c.tar.gz
Closes #15676: mmap: add empty file check prior to offset check
Diffstat (limited to 'Lib/test/test_mmap.py')
-rw-r--r--Lib/test/test_mmap.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 2c2863ebbe..31b369517c 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -466,6 +466,22 @@ class MmapTests(unittest.TestCase):
f.flush ()
return mmap.mmap (f.fileno(), 0)
+ def test_empty_file (self):
+ f = open (TESTFN, 'w+b')
+ f.close()
+ f = open(TESTFN, "rb")
+ try:
+ m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
+ m.close()
+ f.close()
+ self.fail("should not have been able to mmap empty file")
+ except ValueError as e:
+ f.close()
+ self.assertEqual(e.message, "cannot mmap an empty file")
+ except:
+ f.close()
+ self.fail("unexpected exception: " + str(e))
+
def test_offset (self):
f = open (TESTFN, 'w+b')