Commit 05c7f27d authored by Kevin Modzelewski's avatar Kevin Modzelewski

mmap test fixes

parent 5576cae7
...@@ -119,7 +119,10 @@ class MmapTests(unittest.TestCase): ...@@ -119,7 +119,10 @@ class MmapTests(unittest.TestCase):
def test_access_parameter(self): def test_access_parameter(self):
# Test for "access" keyword parameter # Test for "access" keyword parameter
mapsize = 10 mapsize = 10
open(TESTFN, "wb").write("a"*mapsize) # Pyston change: use a with statement to not rely on the destructor being called:
# open(TESTFN, "wb").write("a"*mapsize)
with open(TESTFN, "wb") as f:
f.write("a"*mapsize)
f = open(TESTFN, "rb") f = open(TESTFN, "rb")
m = mmap.mmap(f.fileno(), mapsize, access=mmap.ACCESS_READ) m = mmap.mmap(f.fileno(), mapsize, access=mmap.ACCESS_READ)
self.assertEqual(m[:], 'a'*mapsize, "Readonly memory map data incorrect.") self.assertEqual(m[:], 'a'*mapsize, "Readonly memory map data incorrect.")
...@@ -538,7 +541,10 @@ class MmapTests(unittest.TestCase): ...@@ -538,7 +541,10 @@ class MmapTests(unittest.TestCase):
@unittest.skipUnless(hasattr(mmap, 'PROT_READ'), "needs mmap.PROT_READ") @unittest.skipUnless(hasattr(mmap, 'PROT_READ'), "needs mmap.PROT_READ")
def test_prot_readonly(self): def test_prot_readonly(self):
mapsize = 10 mapsize = 10
open(TESTFN, "wb").write("a"*mapsize) # Pyston change: use a with statement to not rely on the destructor being called:
# open(TESTFN, "wb").write("a"*mapsize)
with open(TESTFN, "wb") as f:
f.write("a"*mapsize)
f = open(TESTFN, "rb") f = open(TESTFN, "rb")
m = mmap.mmap(f.fileno(), mapsize, prot=mmap.PROT_READ) m = mmap.mmap(f.fileno(), mapsize, prot=mmap.PROT_READ)
self.assertRaises(TypeError, m.write, "foo") self.assertRaises(TypeError, m.write, "foo")
...@@ -550,7 +556,10 @@ class MmapTests(unittest.TestCase): ...@@ -550,7 +556,10 @@ class MmapTests(unittest.TestCase):
def test_io_methods(self): def test_io_methods(self):
data = "0123456789" data = "0123456789"
open(TESTFN, "wb").write("x"*len(data)) # Pyston change: use a with statement to not rely on the destructor being called:
# open(TESTFN, "wb").write("x"*len(data))
with open(TESTFN, "wb") as f:
f.write("x"*len(data))
f = open(TESTFN, "r+b") f = open(TESTFN, "r+b")
m = mmap.mmap(f.fileno(), len(data)) m = mmap.mmap(f.fileno(), len(data))
f.close() f.close()
...@@ -617,7 +626,10 @@ class MmapTests(unittest.TestCase): ...@@ -617,7 +626,10 @@ class MmapTests(unittest.TestCase):
m.close() m.close()
# Should not crash (Issue 5385) # Should not crash (Issue 5385)
open(TESTFN, "wb").write("x"*10) # Pyston change: use a with statement to not rely on the destructor being called:
# open(TESTFN, "wb").write("x"*10)
with open(TESTFN, "wb") as f:
f.write("x"*10)
f = open(TESTFN, "r+b") f = open(TESTFN, "r+b")
m = mmap.mmap(f.fileno(), 0) m = mmap.mmap(f.fileno(), 0)
f.close() f.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment