diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-11 15:04:41 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-11 15:04:41 (GMT) |
commit | b28ed92dd0e46db1ba14d76375c7b0a7186249e3 (patch) | |
tree | 30146855fbb0a9717b85591143b3f0d60a5dfa5e /Lib/test/test_os.py | |
parent | 0d63f1228de60b9b4d0fcb765a18eabc41295127 (diff) | |
download | cpython-b28ed92dd0e46db1ba14d76375c7b0a7186249e3.zip cpython-b28ed92dd0e46db1ba14d76375c7b0a7186249e3.tar.gz cpython-b28ed92dd0e46db1ba14d76375c7b0a7186249e3.tar.bz2 |
Issue #21932: os.read() now uses a :c:func:`Py_ssize_t` type instead of
:c:type:`int` for the size to support reading more than 2 GB at once. On
Windows, the size is truncted to INT_MAX. As any call to os.read(), the OS
may read less bytes than the number of requested bytes.
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r-- | Lib/test/test_os.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index f559841..588df16 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -43,6 +43,10 @@ try: import _winapi except ImportError: _winapi = None +try: + from _testcapi import INT_MAX +except ImportError: + INT_MAX = 2 ** 31 - 1 from test.script_helper import assert_python_ok @@ -119,6 +123,21 @@ class FileTests(unittest.TestCase): self.assertEqual(type(s), bytes) self.assertEqual(s, b"spam") + def test_large_read(self): + with open(support.TESTFN, "wb") as fp: + fp.write(b'test') + self.addCleanup(support.unlink, support.TESTFN) + + # Issue #21932: Make sure that os.read() does not raise an + # OverflowError for size larger than INT_MAX + size = INT_MAX + 10 + with open(support.TESTFN, "rb") as fp: + data = os.read(fp.fileno(), size) + + # The test does not try to read more than 2 GB at once because the + # operating system is free to return less bytes than requested. + self.assertEqual(data, b'test') + def test_write(self): # os.write() accepts bytes- and buffer-like objects but not strings fd = os.open(support.TESTFN, os.O_CREAT | os.O_WRONLY) |