bpo-2122: Make mmap.flush() behave same on all platforms (GH-8692)

Previously, its behavior was platform-dependent and there was no error checking
under Windows.
This commit is contained in:
Berker Peksag 2018-08-22 21:21:05 +03:00 committed by GitHub
parent 28853a249b
commit e7d4b2f205
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 13 deletions

View file

@ -1,4 +1,4 @@
from test.support import (TESTFN, run_unittest, import_module, unlink,
from test.support import (TESTFN, import_module, unlink,
requires, _2G, _4G, gc_collect, cpython_only)
import unittest
import os
@ -741,6 +741,18 @@ class MmapTests(unittest.TestCase):
with self.assertRaises(TypeError):
m * 2
def test_flush_return_value(self):
# mm.flush() should return None on success, raise an
# exception on error under all platforms.
mm = mmap.mmap(-1, 16)
self.addCleanup(mm.close)
mm.write(b'python')
result = mm.flush()
self.assertIsNone(result)
if os.name != 'nt':
# 'offset' must be a multiple of mmap.PAGESIZE.
self.assertRaises(OSError, mm.flush, 1, len(b'python'))
class LargeMmapTests(unittest.TestCase):
@ -803,8 +815,5 @@ class LargeMmapTests(unittest.TestCase):
self._test_around_boundary(_4G)
def test_main():
run_unittest(MmapTests, LargeMmapTests)
if __name__ == '__main__':
test_main()
unittest.main()