'Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/148
Test that saving an update where the header is shorter than the
original header doesn\'t leave a stump from the old header in the file.'

def test_update_with_truncated_header(self):

    data = np.arange(100)
    hdu = fits.PrimaryHDU(data=data)
    idx = 1
    while (len(hdu.header) < 34):
        hdu.header['TEST{}'.format(idx)] = idx
        idx += 1
    hdu.writeto(self.temp('temp.fits'), checksum=True)
    with fits.open(self.temp('temp.fits'), mode='update') as hdul:
        hdul[0].header['TEST1'] = 2
    with fits.open(self.temp('temp.fits')) as hdul:
        assert (hdul[0].data == data).all()
