'Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/148, part
2.  This ensures that if a file contains a checksum, the checksum is
updated when changes are saved to the file, even if the file was opened
with the default of checksum=False.
An existing checksum and/or datasum are only stripped if the file is
opened with checksum=\'remove\'.'

def test_open_update_mode_update_checksum(self):

    self.copy_file('checksum.fits')
    with fits.open(self.temp('checksum.fits')) as hdul:
        header = hdul[1].header.copy()
        data = hdul[1].data.copy()
    with fits.open(self.temp('checksum.fits'), mode='update') as hdul:
        hdul[1].header['FOO'] = 'BAR'
        hdul[1].data[0]['TIME'] = 42
    with fits.open(self.temp('checksum.fits')) as hdul:
        header2 = hdul[1].header
        data2 = hdul[1].data
        assert (header2[:(-3)] == header[:(-2)])
        assert ('CHECKSUM' in header2)
        assert ('DATASUM' in header2)
        assert (header2['FOO'] == 'BAR')
        assert (data2['TIME'][1:] == data['TIME'][1:]).all()
        assert (data2['TIME'][0] == 42)
    with fits.open(self.temp('checksum.fits'), mode='update', checksum='remove') as hdul:
        pass
    with fits.open(self.temp('checksum.fits')) as hdul:
        header2 = hdul[1].header
        data2 = hdul[1].data
        assert (header2[:(-1)] == header[:(-2)])
        assert ('CHECKSUM' not in header2)
        assert ('DATASUM' not in header2)
        assert (header2['FOO'] == 'BAR')
        assert (data2['TIME'][1:] == data['TIME'][1:]).all()
        assert (data2['TIME'][0] == 42)
