def testWriteMethodsOnReadOnlyFile(self):
    with BZ2File(self.filename, 'w') as bz2f:
        bz2f.write(b'abc')
    with BZ2File(self.filename, 'r') as bz2f:
        self.assertRaises(OSError, bz2f.write, b'a')
        self.assertRaises(OSError, bz2f.writelines, [b'a'])
def testWriteMethodsOnReadOnlyFile(self):
    with BZ2File(self.filename, 'w') as bz2f:
        bz2f.write(b'abc')
    with BZ2File(self.filename, 'r') as bz2f:
        self.assertRaises(OSError, bz2f.write, b'a')
        self.assertRaises(OSError, bz2f.writelines, [b'a'])