'Test basic functionality of tables with columns containing
pseudo-unsigned integers.  See
https://github.com/astropy/astropy/pull/906'

@pytest.mark.parametrize('utype', ('u2', 'u4', 'u8'))
def test_uint_columns(self, utype):

    bits = (8 * int(utype[1]))
    if ((platform.architecture()[0] == '64bit') or (bits != 64)):
        bzero = self.utype_map[utype]((2 ** (bits - 1)))
        one = self.utype_map[utype](1)
        u0 = np.arange((bits + 1), dtype=self.utype_map[utype])
        u = ((2 ** u0) - one)
        if (bits == 64):
            u[63] = (bzero - one)
            u[64] = ((u[63] + u[63]) + one)
        uu = (u - bzero).view(self.itype_map[utype])
        col = fits.Column(name=utype, array=u, format=self.format_map[utype], bzero=bzero)
        table = fits.BinTableHDU.from_columns([col])
        assert (table.data[utype] == u).all()
        assert (table.data.base.base[utype] == uu).all()
        hdu0 = fits.PrimaryHDU()
        hdulist = fits.HDUList([hdu0, table])
        with ignore_warnings():
            hdulist.writeto(self.temp('tempfile.fits'), overwrite=True)
        del hdulist
        with fits.open(self.temp('tempfile.fits'), uint=True) as hdulist2:
            hdudata = hdulist2[1].data
            assert (hdudata[utype] == u).all()
            assert (hdudata[utype].dtype == self.utype_map[utype])
            assert (hdudata.base[utype] == uu).all()
        v = u.view(dtype=[(utype, self.utype_map[utype])])
        with ignore_warnings():
            fits.writeto(self.temp('tempfile2.fits'), v, overwrite=True)
        with fits.open(self.temp('tempfile2.fits'), uint=True) as hdulist3:
            hdudata3 = hdulist3[1].data
            assert (hdudata3.base[utype] == table.data.base.base[utype]).all()
            assert (hdudata3[utype] == table.data[utype]).all()
            assert (hdudata3[utype] == u).all()
