Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(264811)

Delta Between Two Patch Sets: Lib/test/test_mmap.py

Issue 26335: Make mmap.write return the number of bytes written like other write methods
Left Patch Set: Created 3 years, 6 months ago
Right Patch Set: Created 3 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Doc/library/mmap.rst ('k') | Modules/mmapmodule.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 from test.support import (TESTFN, run_unittest, import_module, unlink, 1 from test.support import (TESTFN, run_unittest, import_module, unlink,
2 requires, _2G, _4G, gc_collect, cpython_only) 2 requires, _2G, _4G, gc_collect, cpython_only)
3 import unittest 3 import unittest
4 import os 4 import os
5 import re 5 import re
6 import itertools 6 import itertools
7 import socket 7 import socket
8 import sys 8 import sys
9 import weakref 9 import weakref
10 10
(...skipping 14 matching lines...) Expand all
25 except OSError: 25 except OSError:
26 pass 26 pass
27 27
28 def test_basic(self): 28 def test_basic(self):
29 # Test mmap module on Unix systems and Windows 29 # Test mmap module on Unix systems and Windows
30 30
31 # Create a file to be mmap'ed. 31 # Create a file to be mmap'ed.
32 f = open(TESTFN, 'bw+') 32 f = open(TESTFN, 'bw+')
33 try: 33 try:
34 # Write 2 pages worth of data to the file 34 # Write 2 pages worth of data to the file
35 self.assertEqual(f.write(b'\0'* PAGESIZE), PAGESIZE) 35 f.write(b'\0'* PAGESIZE)
berkerpeksag 2016/02/23 00:57:52 I'd prefer to keep existed tests as they are and a
36 self.assertEqual(f.write(b'foo'), 3) 36 f.write(b'foo')
37 self.assertEqual(f.write(b'\0'* (PAGESIZE-3) ), PAGESIZE - 3) 37 f.write(b'\0'* (PAGESIZE-3) )
38 f.flush() 38 f.flush()
39 m = mmap.mmap(f.fileno(), 2 * PAGESIZE) 39 m = mmap.mmap(f.fileno(), 2 * PAGESIZE)
40 finally: 40 finally:
41 f.close() 41 f.close()
42 42
43 # Simple sanity checks 43 # Simple sanity checks
44 44
45 tp = str(type(m)) # SF bug 128713: segfaulted on Linux 45 tp = str(type(m)) # SF bug 128713: segfaulted on Linux
46 self.assertEqual(m.find(b'foo'), PAGESIZE) 46 self.assertEqual(m.find(b'foo'), PAGESIZE)
47 47
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 706
707 def test_weakref(self): 707 def test_weakref(self):
708 # Check mmap objects are weakrefable 708 # Check mmap objects are weakrefable
709 mm = mmap.mmap(-1, 16) 709 mm = mmap.mmap(-1, 16)
710 wr = weakref.ref(mm) 710 wr = weakref.ref(mm)
711 self.assertIs(wr(), mm) 711 self.assertIs(wr(), mm)
712 del mm 712 del mm
713 gc_collect() 713 gc_collect()
714 self.assertIs(wr(), None) 714 self.assertIs(wr(), None)
715 715
716 def test_write_returning_the_number_of_bytes_written(self):
717 mm = mmap.mmap(-1, 16)
718 self.assertEqual(mm.write(b"x"), 1)
719
716 class LargeMmapTests(unittest.TestCase): 720 class LargeMmapTests(unittest.TestCase):
717 721
718 def setUp(self): 722 def setUp(self):
719 unlink(TESTFN) 723 unlink(TESTFN)
720 724
721 def tearDown(self): 725 def tearDown(self):
722 unlink(TESTFN) 726 unlink(TESTFN)
723 727
724 def _make_test_file(self, num_zeroes, tail): 728 def _make_test_file(self, num_zeroes, tail):
725 if sys.platform[:3] == 'win' or sys.platform == 'darwin': 729 if sys.platform[:3] == 'win' or sys.platform == 'darwin':
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 @unittest.skipUnless(sys.maxsize > _4G, "test cannot run on 32-bit systems") 776 @unittest.skipUnless(sys.maxsize > _4G, "test cannot run on 32-bit systems")
773 def test_around_4GB(self): 777 def test_around_4GB(self):
774 self._test_around_boundary(_4G) 778 self._test_around_boundary(_4G)
775 779
776 780
777 def test_main(): 781 def test_main():
778 run_unittest(MmapTests, LargeMmapTests) 782 run_unittest(MmapTests, LargeMmapTests)
779 783
780 if __name__ == '__main__': 784 if __name__ == '__main__':
781 test_main() 785 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+