'Tests that when using writeto with checksum=True, a checksum and
datasum are added to HDUs that did not previously have one.
Regression test for https://github.com/spacetelescope/PyFITS/issues/8'

def test_hdu_writeto_existing(self):

    with fits.open(self.data('tb.fits')) as hdul:
        hdul.writeto(self.temp('test.fits'), checksum=True)
    with fits.open(self.temp('test.fits')) as hdul:
        assert ('CHECKSUM' in hdul[0].header)
        assert (hdul[0].header['CHECKSUM'] == '7UgqATfo7TfoATfo')
        assert ('DATASUM' in hdul[0].header)
        assert (hdul[0].header['DATASUM'] == '0')
        assert ('CHECKSUM' in hdul[1].header)
        assert (hdul[1].header['CHECKSUM'] == '99daD8bX98baA8bU')
        assert ('DATASUM' in hdul[1].header)
        assert (hdul[1].header['DATASUM'] == '1829680925')
