summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_mmap.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-08-01 14:50:00 (GMT)
committerGeorg Brandl <georg@python.org>2010-08-01 14:50:00 (GMT)
commit0bccc185b4d333a6c50c18c8d1d9916aca96a99c (patch)
tree799b6adc978bd4c2ee65aa296baedf71d32c1319 /Lib/test/test_mmap.py
parent120d633871a950d82194f2507c5ccaea284c69d6 (diff)
downloadcpython-0bccc185b4d333a6c50c18c8d1d9916aca96a99c.zip
cpython-0bccc185b4d333a6c50c18c8d1d9916aca96a99c.tar.gz
cpython-0bccc185b4d333a6c50c18c8d1d9916aca96a99c.tar.bz2
#8046: add context manager protocol support to mmap objects. Also add closed property.
Diffstat (limited to 'Lib/test/test_mmap.py')
-rw-r--r--Lib/test/test_mmap.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index c27b898..68af00e 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -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)