a
    ߙfb&                     @   sP   d dl Z d dlZd dlZd dlmZ d dlmZ ddlm	Z	 G dd de	Z
dS )    N)assert_array_equal)fits   )FitsTestCasec                   @   sP   e Zd Zedd Zejdg ddd Zejddd	d
 Z	dd Z
dS )TestUintFunctionsc                 C   s@   d| _ tjtjtjd| _tjtjtjd| _	dddd| _
d S )Nu2u4u8IJK)Zutypesnpuint16Zuint32Zuint64	utype_mapint16Zint32int64	itype_map
format_map)cls r   >lib/python3.9/site-packages/astropy/io/fits/tests/test_uint.pysetup_class   s    zTestUintFunctions.setup_class)utype
compressed))r   F)r	   F)r
   F)r   T)r	   Tc              
   C   s  dt |d  }t d dks*|dkr|rNttjg dtjd}d}nttjg dtjd}d}|j	d|d	d
d|d  d |j
| ddd tj| ddd.}|| jj| j| ksJ || jtjd| d d| d d| d ddddg| j| dk s J |
| d tj| ddd}|| j}|| j}	||	k slJ |s|| jd d }
|
jjd| ksJ |
|d d k sJ W d    n1 s0    Y  W d    n1 s0    Y  d S )N   r   r   64bit@   )r   r         dtypeintd r!   )bzerotempfile.fitsTZ	overwriteuintr"   ztempfile1.fits)r   r,   )r%   platformarchitecturer   ZCompImageHDUr   arrayr   
PrimaryHDUZscalewritetotempopendatar$   r   allZsectionname)selfr   r   bitsZhduZ
hdu_numberZhdulZhdul1Zd1Zd2Zsecr   r   r   	test_uint   s:     

zTestUintFunctions.test_uintr   r   c                 C   s  dt |d  }t d dks*|dkr| j| d|d  }| j| d}tj|d | j| d}d| | }|dkr|| |d< |d |d  | |d< || | j| }tj	||| j
| |d	}tj|g}	|	j| |k sJ |	jjj| |k s
J t }
t|
|	g}|j| d
dd ~tj| d
ddb}|d j}|| |k slJ || j| j| ksJ |j| |k sJ W d   n1 s0    Y  |j|| j| fgd}tj| d|dd tj| dddn}|d j}|j| |	jjj| k s.J || |	j| k sJJ || |k s`J W d   n1 sv0    Y  dS )zTest basic functionality of tables with columns containing
        pseudo-unsigned integers.  See
        https://github.com/astropy/astropy/pull/906
        r   r   r   r   r   r!   r#   ?   )r6   r/   formatr(   r)   Tr*   r+   Nztempfile2.fits)r%   r-   r.   r   r   arangeZviewr   r   Columnr   BinTableHDUfrom_columnsr4   r5   baser0   ZHDUListr1   r2   r3   r$   )r7   r   r8   r(   ZoneZu0uuucoltableZhdu0hdulistZhdulist2ZhdudatavZhdulist3Zhdudata3r   r   r   test_uint_columns;   sD    

8
z#TestUintFunctions.test_uint_columnsc              
   C   sR  t jdt jd}tjtjddt jdt jddtjdddd|d	g}|| 	d
 t
| 	d
}|d j}W d   n1 s0    Y  t|d | |d dk}t|| d ||  || d j|| jksJ t
| 	d
}|d j}W d   n1 s0    Y  t|| d ||  || d j|| jksNJ dS )z
        Fix for https://github.com/astropy/astropy/issues/5490
        if data is sliced first, make sure the data is still converted as uint
        i   r#   ar   )r6   r;   r/   br   i   )r6   r;   Zbscaler(   r/   ztest_scaled_slicing.fitsNr   )r   r<   r   r   r>   r?   r=   r   r1   r2   r3   r4   r   r$   )r7   ZdatarefZtbhdurE   r4   Zselr   r   r   test_uint_sliceq   s(    (*z!TestUintFunctions.test_uint_sliceN)__name__
__module____qualname__classmethodr   pytestZmarkZparametrizer9   rG   rJ   r   r   r   r   r      s   

!
5r   )r-   rO   Znumpyr   Znumpy.testingr   Z
astropy.ior   r'   r   r   r   r   r   r   <module>   s   