summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bz2.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-01-10 16:22:51 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-01-10 16:22:51 (GMT)
commit308705e4fab1fe784218bde5cc8c8d2daddf6700 (patch)
treec179157d874086e0e6472b292287e1eb3e7806c0 /Lib/test/test_bz2.py
parentab868311a5282f188a8cf831b021938420fee5c4 (diff)
downloadcpython-308705e4fab1fe784218bde5cc8c8d2daddf6700.zip
cpython-308705e4fab1fe784218bde5cc8c8d2daddf6700.tar.gz
cpython-308705e4fab1fe784218bde5cc8c8d2daddf6700.tar.bz2
Merged revisions 68484-68485 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r68484 | antoine.pitrou | 2009-01-10 17:13:45 +0100 (sam., 10 janv. 2009) | 3 lines Issue #3860: GzipFile and BZ2File now support the context manager protocol. ........ r68485 | antoine.pitrou | 2009-01-10 17:15:24 +0100 (sam., 10 janv. 2009) | 1 line Add NEWS entry for r68484. ........
Diffstat (limited to 'Lib/test/test_bz2.py')
-rw-r--r--Lib/test/test_bz2.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py
index 366ab7a..18d84bb 100644
--- a/Lib/test/test_bz2.py
+++ b/Lib/test/test_bz2.py
@@ -258,6 +258,28 @@ class BZ2FileTest(BaseTest):
bz2f.close()
self.assertEqual(xlines, [b'Test'])
+ def testContextProtocol(self):
+ # BZ2File supports the context management protocol
+ f = None
+ with BZ2File(self.filename, "wb") as f:
+ f.write(b"xxx")
+ f = BZ2File(self.filename, "rb")
+ f.close()
+ try:
+ with f:
+ pass
+ except ValueError:
+ pass
+ else:
+ self.fail("__enter__ on a closed file didn't raise an exception")
+ try:
+ with BZ2File(self.filename, "wb") as f:
+ 1/0
+ except ZeroDivisionError:
+ pass
+ else:
+ self.fail("1/0 didn't raise an exception")
+
class BZ2CompressorTest(BaseTest):
def testCompress(self):