'Regression test for
https://github.com/spacetelescope/PyFITS/issues/23'

def test_compression_update_header(self):

    self.copy_file('comp.fits')
    with fits.open(self.temp('comp.fits'), mode='update') as hdul:
        assert isinstance(hdul[1], fits.CompImageHDU)
        hdul[1].header['test1'] = 'test'
        hdul[1]._header['test2'] = 'test2'
    with fits.open(self.temp('comp.fits')) as hdul:
        assert ('test1' in hdul[1].header)
        assert (hdul[1].header['test1'] == 'test')
        assert ('test2' in hdul[1].header)
        assert (hdul[1].header['test2'] == 'test2')
    with fits.open(self.temp('comp.fits'), mode='update') as hdul:
        hdr = hdul[1].header
        hdr[hdr.index('TEST1')] = 'foo'
    with fits.open(self.temp('comp.fits')) as hdul:
        assert (hdul[1].header['TEST1'] == 'foo')
    with fits.open(self.temp('comp.fits'), mode='update') as hdul:
        hdul[1].header['TEST*'] = 'qux'
    with fits.open(self.temp('comp.fits')) as hdul:
        assert (list(hdul[1].header['TEST*'].values()) == ['qux', 'qux'])
    with fits.open(self.temp('comp.fits'), mode='update') as hdul:
        hdr = hdul[1].header
        idx = hdr.index('TEST1')
        hdr[idx:(idx + 2)] = 'bar'
    with fits.open(self.temp('comp.fits')) as hdul:
        assert (list(hdul[1].header['TEST*'].values()) == ['bar', 'bar'])
    with fits.open(self.temp('comp.fits'), mode='update') as hdul:
        hdul[1].header[('COMMENT', 1)] = 'I    am    fire.    I    am    death!'
    with fits.open(self.temp('comp.fits')) as hdul:
        assert (hdul[1].header['COMMENT'][1] == 'I    am    fire.    I    am    death!')
        assert (hdul[1]._header['COMMENT'][1] == 'I    am    fire.    I    am    death!')
    with fits.open(self.temp('comp.fits'), mode='update') as hdul:
        hdr = hdul[1].header
        del hdr['COMMENT']
        idx = hdr.index('TEST1')
        del hdr[idx:(idx + 2)]
    with fits.open(self.temp('comp.fits')) as hdul:
        assert ('COMMENT' not in hdul[1].header)
        assert ('COMMENT' not in hdul[1]._header)
        assert ('TEST1' not in hdul[1].header)
        assert ('TEST1' not in hdul[1]._header)
        assert ('TEST2' not in hdul[1].header)
        assert ('TEST2' not in hdul[1]._header)
