]> granicus.if.org Git - python/commitdiff
Merge: #11277: Fix tests - crash will not trigger if the file is closed and reopened.
authorNadeem Vawda <nadeem.vawda@gmail.com>
Sat, 7 May 2011 12:16:50 +0000 (14:16 +0200)
committerNadeem Vawda <nadeem.vawda@gmail.com>
Sat, 7 May 2011 12:16:50 +0000 (14:16 +0200)
1  2 
Lib/test/test_mmap.py

index be588cfb99bf32c25dfd62dd3ced0a5729d512ae,0a177c66a2bde19bc529606209356e94088379af..850768f069a9fda0653f393131269bc461ae1ee2
@@@ -667,25 -658,30 +667,24 @@@ class LargeMmapTests(unittest.TestCase)
          if sys.platform[:3] == 'win' or sys.platform == 'darwin':
              requires('largefile',
                  'test requires %s bytes and a long time to run' % str(0x180000000))
-         with open(TESTFN, 'wb') as f:
-             try:
-                 f.seek(num_zeroes)
-                 f.write(tail)
-                 f.flush()
-             except (IOError, OverflowError):
-                 raise unittest.SkipTest("filesystem does not have largefile support")
+         f = open(TESTFN, 'w+b')
+         try:
+             f.seek(num_zeroes)
+             f.write(tail)
+             f.flush()
+         except (IOError, OverflowError):
+             raise unittest.SkipTest("filesystem does not have largefile support")
+         return f
  
      def test_large_offset(self):
-         self._create_test_file(0x14FFFFFFF, b" ")
-         with open(TESTFN, 'rb') as f:
+         with self._make_test_file(0x14FFFFFFF, b" ") as f:
 -            m = mmap.mmap(f.fileno(), 0, offset=0x140000000, access=mmap.ACCESS_READ)
 -            try:
 +            with mmap.mmap(f.fileno(), 0, offset=0x140000000, access=mmap.ACCESS_READ) as m:
                  self.assertEqual(m[0xFFFFFFF], 32)
 -            finally:
 -                m.close()
  
      def test_large_filesize(self):
-         self._create_test_file(0x17FFFFFFF, b" ")
-         with open(TESTFN, 'rb') as f:
+         with self._make_test_file(0x17FFFFFFF, b" ") as f:
 -            m = mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ)
 -            try:
 +            with mmap.mmap(f.fileno(), 0x10000, access=mmap.ACCESS_READ) as m:
                  self.assertEqual(m.size(), 0x180000000)
 -            finally:
 -                m.close()
  
      # Issue 11277: mmap() with large (~4GB) sparse files crashes on OS X.
  
          tail = b'  DEARdear  '
          start = boundary - len(tail) // 2
          end = start + len(tail)
-         self._create_test_file(start, tail)
-         with open(TESTFN, 'rb') as f:
+         with self._make_test_file(start, tail) as f:
 -            m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
 -            try:
 +            with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as m:
                  self.assertEqual(m[start:end], tail)
 -            finally:
 -                m.close()
  
      @unittest.skipUnless(sys.maxsize > _4G, "test cannot run on 32-bit systems")
      def test_around_2GB(self):