'Regression test for https://github.com/spacetelescope/PyFITS/issues/47'

def test_copy_vla(self):

    arr1 = [np.arange((n + 1)) for n in range(255)]
    arr2 = [np.arange(255, (256 + n)) for n in range(255)]
    c = fits.Column('test', format='J', array=np.arange(255))
    c1 = fits.Column('A', format='PJ', array=arr1)
    c2 = fits.Column('B', format='PJ', array=arr2)
    t1 = fits.BinTableHDU.from_columns([c, c1])
    t2 = fits.BinTableHDU.from_columns([c, c2])
    hdul = fits.HDUList([fits.PrimaryHDU(), t1, t2])
    hdul.writeto(self.temp('test.fits'), overwrite=True)
    with fits.open(self.temp('test.fits')) as h:
        assert (h[1].header['TFORM2'] == 'PJ(255)')
        assert (h[2].header['TFORM2'] == 'PJ(255)')
        assert comparerecords(h[1].data, t1.data)
        assert comparerecords(h[2].data, t2.data)
    with fits.open(self.temp('test.fits')) as h:
        new_hdu = fits.BinTableHDU(data=h[2].data, header=h[2].header)
        new_hdu.writeto(self.temp('test3.fits'))
    with fits.open(self.temp('test3.fits')) as h2:
        assert comparerecords(h2[1].data, t2.data)
    new_hdul = fits.HDUList([fits.PrimaryHDU()])
    new_hdul.writeto(self.temp('test2.fits'))
    with fits.open(self.temp('test2.fits'), mode='append') as new_hdul:
        for _ in range(2):
            with fits.open(self.temp('test.fits')) as h:
                new_hdul.append(h[2])
                new_hdul.flush()
    with fits.open(self.temp('test2.fits')) as new_hdul:
        for idx in range(1, 3):
            assert comparerecords(new_hdul[idx].data, t2.data)
