'Regression test for https://github.com/astropy/astropy/issues/1597
Tests for pickling FITS_rec objects'

def test_pickle(self):

    with fits.open(self.data('tb.fits')) as btb:
        assert isinstance(btb[1].columns._arrays[0], Delayed)
        btb_pd = pickle.dumps(btb[1].data)
        btb_pl = pickle.loads(btb_pd)
        assert (not isinstance(btb[1].columns._arrays[0], Delayed))
        assert comparerecords(btb_pl, btb[1].data)
    with fits.open(self.data('ascii.fits')) as asc:
        asc_pd = pickle.dumps(asc[1].data)
        asc_pl = pickle.loads(asc_pd)
        assert comparerecords(asc_pl, asc[1].data)
    with fits.open(self.data('random_groups.fits')) as rgr:
        rgr_pd = pickle.dumps(rgr[0].data)
        rgr_pl = pickle.loads(rgr_pd)
        assert comparerecords(rgr_pl, rgr[0].data)
    with fits.open(self.data('zerowidth.fits')) as zwc:
        zwc_pd = pickle.dumps(zwc[2].data)
        zwc_pl = pickle.loads(zwc_pd)
        assert comparerecords(zwc_pl, zwc[2].data)
