summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2005-03-03 11:22:44 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2005-03-03 11:22:44 (GMT)
commit7fe60c0a0ae2fe4586491867c902bb13df403285 (patch)
treef014cc1f0b4dfb19588dc5144ff343f11e48c352 /Lib/test
parentdf37c8c1ad51b6f8527e2cd398788e49cd686654 (diff)
downloadcpython-7fe60c0a0ae2fe4586491867c902bb13df403285.zip
cpython-7fe60c0a0ae2fe4586491867c902bb13df403285.tar.gz
cpython-7fe60c0a0ae2fe4586491867c902bb13df403285.tar.bz2
Patches #749830, #1144555: allow UNIX mmap size to default to current
file size.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/output/test_mmap2
-rw-r--r--Lib/test/test_mmap.py36
2 files changed, 38 insertions, 0 deletions
diff --git a/Lib/test/output/test_mmap b/Lib/test/output/test_mmap
index 1706ad5..02b24bc 100644
--- a/Lib/test/output/test_mmap
+++ b/Lib/test/output/test_mmap
@@ -31,4 +31,6 @@ test_mmap
Modifying copy-on-write memory map.
Ensuring copy-on-write maps cannot be resized.
Ensuring invalid access parameter raises exception.
+ Ensuring that passing 0 as map length sets map size to current file size.
+ Ensuring that passing 0 as map length sets map size to current file size.
Test passed
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index a6796d5..d225173 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -311,7 +311,43 @@ def test_both():
finally:
os.unlink(TESTFN)
+ # test mapping of entire file by passing 0 for map length
+ if hasattr(os, "stat"):
+ print " Ensuring that passing 0 as map length sets map size to current file size."
+ f = open(TESTFN, "w+")
+ try:
+ f.write(2**16 * 'm') # Arbitrary character
+ f.close()
+
+ f = open(TESTFN, "rb+")
+ mf = mmap.mmap(f.fileno(), 0)
+ verify(len(mf) == 2**16, "Map size should equal file size.")
+ vereq(mf.read(2**16), 2**16 * "m")
+ mf.close()
+ f.close()
+
+ finally:
+ os.unlink(TESTFN)
+
+ # test mapping of entire file by passing 0 for map length
+ if hasattr(os, "stat"):
+ print " Ensuring that passing 0 as map length sets map size to current file size."
+ f = open(TESTFN, "w+")
+ try:
+ f.write(2**16 * 'm') # Arbitrary character
+ f.close()
+
+ f = open(TESTFN, "rb+")
+ mf = mmap.mmap(f.fileno(), 0)
+ verify(len(mf) == 2**16, "Map size should equal file size.")
+ vereq(mf.read(2**16), 2**16 * "m")
+ mf.close()
+ f.close()
+
+ finally:
+ os.unlink(TESTFN)
+
print ' Test passed'
test_both()