summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_largefile.py
diff options
context:
space:
mode:
authorStéphane Wirtel <stephane@wirtel.be>2018-10-17 23:52:21 (GMT)
committerVictor Stinner <vstinner@redhat.com>2018-10-17 23:52:21 (GMT)
commita5ebc205beea2bf1501e4ac33ed6e81732dd0604 (patch)
tree5536228313290dd17c74cbb870af15caf4e03293 /Lib/test/test_largefile.py
parent669fa8b6376ee8703ae4383536dfcc0e96e51b78 (diff)
downloadcpython-a5ebc205beea2bf1501e4ac33ed6e81732dd0604.zip
cpython-a5ebc205beea2bf1501e4ac33ed6e81732dd0604.tar.gz
cpython-a5ebc205beea2bf1501e4ac33ed6e81732dd0604.tar.bz2
[3.6] bpo-24658: Fix read/write greater than 2 GiB on macOS (GH-1705) (GH-9937)
On macOS, fix reading from and writing into a file with a size larger than 2 GiB. (cherry picked from commit 74a8b6ea7e0a8508b13a1c75ec9b91febd8b5557)
Diffstat (limited to 'Lib/test/test_largefile.py')
-rw-r--r--Lib/test/test_largefile.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py
index d07bb8e..fd2cc03 100644
--- a/Lib/test/test_largefile.py
+++ b/Lib/test/test_largefile.py
@@ -5,12 +5,12 @@ import os
import stat
import sys
import unittest
-from test.support import TESTFN, requires, unlink
+from test.support import TESTFN, requires, unlink, bigmemtest
import io # C implementation of io
import _pyio as pyio # Python implementation of io
-# size of file to create (>2GB; 2GB == 2147483648 bytes)
-size = 2500000000
+# size of file to create (>2 GiB; 2 GiB == 2,147,483,648 bytes)
+size = 2_500_000_000
class LargeFileTest:
"""Test that each file function works as expected for large
@@ -45,6 +45,15 @@ class LargeFileTest:
raise cls.failureException('File was not truncated by opening '
'with mode "wb"')
+ # _pyio.FileIO.readall() uses a temporary bytearray then casted to bytes,
+ # so memuse=2 is needed
+ @bigmemtest(size=size, memuse=2, dry_run=False)
+ def test_large_read(self, _size):
+ # bpo-24658: Test that a read greater than 2GB does not fail.
+ with self.open(TESTFN, "rb") as f:
+ self.assertEqual(len(f.read()), size + 1)
+ self.assertEqual(f.tell(), size + 1)
+
def test_osstat(self):
self.assertEqual(os.stat(TESTFN)[stat.ST_SIZE], size+1)