'Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/142
Tests a case where the comment of a card ends with END, and is followed
by several blank cards.'

def test_end_in_comment(self):

    data = np.arange(100).reshape((10, 10))
    hdu = fits.PrimaryHDU(data=data)
    hdu.header['TESTKW'] = ('Test    val', 'This    is    the    END')
    hdu.header.append()
    hdu.header.append()
    hdu.writeto(self.temp('test.fits'))
    with fits.open(self.temp('test.fits'), memmap=False) as hdul:
        assert ('TESTKW' in hdul[0].header)
        assert (hdul[0].header == hdu.header)
        assert (hdul[0].data == data).all()
    while (len(hdu.header) < 36):
        hdu.header.append()
    with ignore_warnings():
        hdu.writeto(self.temp('test.fits'), overwrite=True)
    with fits.open(self.temp('test.fits')) as hdul:
        assert ('TESTKW' in hdul[0].header)
        assert (hdul[0].header == hdu.header)
        assert (hdul[0].data == data).all()
    hdu.header.totextfile(self.temp('test.hdr'))
    header2 = fits.Header.fromtextfile(self.temp('test.hdr'))
    assert (hdu.header == header2)
