'Test writing to a bz2.BZ2File file like object'

def test_writeto_bzip2_fileobj(self):

    fileobj = bz2.BZ2File(self.temp('test.fits.bz2'), 'w')
    h = fits.PrimaryHDU()
    try:
        h.writeto(fileobj)
    finally:
        fileobj.close()
    with fits.open(self.temp('test.fits.bz2')) as hdul:
        assert (hdul[0].header == h.header)
