mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
#8046: add context manager protocol support to mmap objects. Also add closed property.
This commit is contained in:
parent
120d633871
commit
0bccc185b4
4 changed files with 73 additions and 4 deletions
|
@ -586,6 +586,20 @@ class MmapTests(unittest.TestCase):
|
|||
pass
|
||||
m.close()
|
||||
|
||||
def test_context_manager(self):
|
||||
with mmap.mmap(-1, 10) as m:
|
||||
self.assertFalse(m.closed)
|
||||
self.assertTrue(m.closed)
|
||||
|
||||
def test_context_manager_exception(self):
|
||||
# Test that the IOError gets passed through
|
||||
with self.assertRaises(Exception) as exc:
|
||||
with mmap.mmap(-1, 10) as m:
|
||||
raise IOError
|
||||
self.assertIsInstance(exc.exception, IOError,
|
||||
"wrong exception raised in context manager")
|
||||
self.assertTrue(m.closed, "context manager failed")
|
||||
|
||||
|
||||
def test_main():
|
||||
run_unittest(MmapTests)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue