'Test creating the HDUList structure in memory from a string containing
an entire FITS file.  This is similar to test_hdu_fromstring but for an
entire multi-extension FITS file at once.'

@ignore_warnings()
def test_hdul_fromstring(self):

    def test_fromstring(filename):
        with fits.open(filename) as hdul:
            orig_info = hdul.info(output=False)
            with open(filename, 'rb') as f:
                dat = f.read()
            hdul2 = fits.HDUList.fromstring(dat)
            assert (orig_info == hdul2.info(output=False))
            for idx in range(len(hdul)):
                assert (hdul[idx].header == hdul2[idx].header)
                if ((hdul[idx].data is None) or (hdul2[idx].data is None)):
                    assert (hdul[idx].data == hdul2[idx].data)
                elif (hdul[idx].data.dtype.fields and hdul2[idx].data.dtype.fields):
                    for n in hdul[idx].data.names:
                        c1 = hdul[idx].data[n]
                        c2 = hdul2[idx].data[n]
                        assert (c1 == c2).all()
                elif (any(((dim == 0) for dim in hdul[idx].data.shape)) or any(((dim == 0) for dim in hdul2[idx].data.shape))):
                    return (hdul[idx].data.shape == hdul2[idx].data.shape)
                else:
                    np.testing.assert_array_equal(hdul[idx].data, hdul2[idx].data)
    for filename in glob.glob(os.path.join(self.data_dir, '*.fits')):
        if ((sys.platform == 'win32') and (filename == 'zerowidth.fits')):
            continue
        test_fromstring(filename)
    pytest.raises(TypeError, fits.HDUList.fromstring, ['a', 'b', 'c'])
