summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bz2.py
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2011-11-30 15:39:30 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2011-11-30 15:39:30 (GMT)
commit44ae4a2a22e00b1714d7fb6aff335d437cbb48bf (patch)
tree533ed9cf454e3951edcaf5c0814bf66ba2ed9127 /Lib/test/test_bz2.py
parent3ff069ebc6884c46c3f99ea61919f7728708c571 (diff)
downloadcpython-44ae4a2a22e00b1714d7fb6aff335d437cbb48bf.zip
cpython-44ae4a2a22e00b1714d7fb6aff335d437cbb48bf.tar.gz
cpython-44ae4a2a22e00b1714d7fb6aff335d437cbb48bf.tar.bz2
Make error handling in BZ2File.{readable,seekable,writable,fileno} consistent with TextIOWrapper.
Also, add tests for these methods.
Diffstat (limited to 'Lib/test/test_bz2.py')
-rw-r--r--Lib/test/test_bz2.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py
index c324fb1..bd40f83 100644
--- a/Lib/test/test_bz2.py
+++ b/Lib/test/test_bz2.py
@@ -348,8 +348,63 @@ class BZ2FileTest(BaseTest):
def testFileno(self):
self.createTempFile()
with open(self.filename, 'rb') as rawf:
- with BZ2File(fileobj=rawf) as bz2f:
+ bz2f = BZ2File(fileobj=rawf)
+ try:
self.assertEqual(bz2f.fileno(), rawf.fileno())
+ finally:
+ bz2f.close()
+ self.assertRaises(ValueError, bz2f.fileno)
+
+ def testSeekable(self):
+ bz2f = BZ2File(fileobj=BytesIO(self.DATA))
+ try:
+ self.assertTrue(bz2f.seekable())
+ bz2f.read()
+ self.assertTrue(bz2f.seekable())
+ finally:
+ bz2f.close()
+ self.assertRaises(ValueError, bz2f.seekable)
+
+ bz2f = BZ2File(fileobj=BytesIO(), mode="w")
+ try:
+ self.assertFalse(bz2f.seekable())
+ finally:
+ bz2f.close()
+ self.assertRaises(ValueError, bz2f.seekable)
+
+ def testReadable(self):
+ bz2f = BZ2File(fileobj=BytesIO(self.DATA))
+ try:
+ self.assertTrue(bz2f.readable())
+ bz2f.read()
+ self.assertTrue(bz2f.readable())
+ finally:
+ bz2f.close()
+ self.assertRaises(ValueError, bz2f.readable)
+
+ bz2f = BZ2File(fileobj=BytesIO(), mode="w")
+ try:
+ self.assertFalse(bz2f.readable())
+ finally:
+ bz2f.close()
+ self.assertRaises(ValueError, bz2f.readable)
+
+ def testWritable(self):
+ bz2f = BZ2File(fileobj=BytesIO(self.DATA))
+ try:
+ self.assertFalse(bz2f.writable())
+ bz2f.read()
+ self.assertFalse(bz2f.writable())
+ finally:
+ bz2f.close()
+ self.assertRaises(ValueError, bz2f.writable)
+
+ bz2f = BZ2File(fileobj=BytesIO(), mode="w")
+ try:
+ self.assertTrue(bz2f.writable())
+ finally:
+ bz2f.close()
+ self.assertRaises(ValueError, bz2f.writable)
def testOpenDel(self):
self.createTempFile()