Skip to content

Commit 7e1bdfa

Browse files
committed
Add more cleanups to test_mmap
1 parent 937fcd9 commit 7e1bdfa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

graalpython/lib-python/3/test/test_mmap.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def test_basic(self):
5353
f.write(b'\0'* (PAGESIZE-3) )
5454
f.flush()
5555
m = mmap.mmap(f.fileno(), 2 * PAGESIZE)
56+
# GraalPy change: add cleanup
57+
self.addCleanup(m.close)
5658
finally:
5759
f.close()
5860

@@ -142,6 +144,8 @@ def test_access_parameter(self):
142144
fp.write(b"a"*mapsize)
143145
with open(TESTFN, "rb") as f:
144146
m = mmap.mmap(f.fileno(), mapsize, access=mmap.ACCESS_READ)
147+
# GraalPy change: add cleanup
148+
self.addCleanup(m.close)
145149
self.assertEqual(m[:], b'a'*mapsize, "Readonly memory map data incorrect.")
146150

147151
# Ensuring that readonly mmap can't be slice assigned
@@ -295,6 +299,8 @@ def test_find_end(self):
295299
f.write(data)
296300
f.flush()
297301
m = mmap.mmap(f.fileno(), n)
302+
# GraalPy change: add cleanup
303+
self.addCleanup(m.close)
298304

299305
self.assertEqual(m.find(b'one'), 0)
300306
self.assertEqual(m.find(b'ones'), 8)
@@ -334,6 +340,8 @@ def test_rfind(self):
334340
f.write(data)
335341
f.flush()
336342
m = mmap.mmap(f.fileno(), n)
343+
# GraalPy change: add cleanup
344+
self.addCleanup(m.close)
337345

338346
self.assertEqual(m.rfind(b'one'), 8)
339347
self.assertEqual(m.rfind(b'one '), 0)
@@ -595,6 +603,8 @@ def test_prot_readonly(self):
595603
fp.write(b"a"*mapsize)
596604
with open(TESTFN, "rb") as f:
597605
m = mmap.mmap(f.fileno(), mapsize, prot=mmap.PROT_READ)
606+
# GraalPy change: add cleanup
607+
self.addCleanup(m.close)
598608
self.assertRaises(TypeError, m.write, "foo")
599609

600610
def test_error(self):
@@ -883,7 +893,11 @@ def test_resize_fails_if_mapping_held_elsewhere(self):
883893
f.truncate(start_size)
884894
try:
885895
m1 = mmap.mmap(f.fileno(), start_size)
896+
# GraalPy change: add cleanup
897+
self.addCleanup(m1.close)
886898
m2 = mmap.mmap(f.fileno(), start_size)
899+
# GraalPy change: add cleanup
900+
self.addCleanup(m2.close)
887901
with self.assertRaises(OSError):
888902
m1.resize(reduced_size)
889903
with self.assertRaises(OSError):

0 commit comments

Comments
 (0)