'Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/136
Open files with nulls for header block padding instead of spaces.'

def test_open_file_with_bad_header_padding(self):

    a = np.arange(100).reshape((10, 10))
    hdu = fits.PrimaryHDU(data=a)
    hdu.writeto(self.temp('temp.fits'))
    end_card_pos = str(hdu.header).index(('END' + ('    ' * 77)))
    padding_start = (end_card_pos + 80)
    padding_len = (2880 - padding_start)
    with open(self.temp('temp.fits'), 'r+b') as f:
        f.seek(padding_start)
        f.write(('\x00'.encode('ascii') * padding_len))
    with catch_warnings(AstropyUserWarning) as w:
        with fits.open(self.temp('temp.fits')) as hdul:
            assert (hdul[0].data == a).all()
    assert ('contains    null    bytes    instead    of    spaces' in str(w[0].message))
    assert (len(w) == 1)
    assert (len(hdul) == 1)
    assert (str(hdul[0].header) == str(hdu.header))
