a
    ߙfb(                     @   s   d dl Z d dlZ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mZ d dlmZ erld dlmZ ddlmZ G d	d
 d
eZG dd deZdd ZdS )    N)assert_equal)util)ignore_sigint_rstrip_inplace)HAS_PIL)Image   )FitsTestCasec                   @   s(   e Zd Zejddd Zdd ZdS )	TestUtilszsys.platform.startswith('win')c                 C   s   t dd }tt| d S )Nc                  S   sx   t t4} t }t|tj t|tj W d    n1 sD0    Y  t| dks^J t	| d j
dkstJ d S )N   r   z1KeyboardInterrupt ignored until test is complete!)pytestZwarnsUserWarningosgetpidkillsignalSIGINTlenstrmessage)wpid r   >lib/python3.9/site-packages/astropy/io/fits/tests/test_util.pytest   s    ,z*TestUtils.test_ignore_sigint.<locals>.test)r   r   raisesKeyboardInterrupt)selfr   r   r   r   test_ignore_sigint   s    

zTestUtils.test_ignore_sigintc                    sL  t dt jfdt jfg  j} fdd|D }t ||ddgd}|jdksVJ t ||ddgd}|jdkszJ t ||ddgd}|jd	ksJ t dt jfdt jfd
t jfg  j} fdd|D }t ||g dd}|jdksJ t ||g dd}|jdks"J t ||g dd}|jdksHJ dS )z
        Tests a few corner-cases for numpy dtype creation.

        These originally were the reason for having a realign_dtype hack.
        abc                    s   g | ]} j | d  qS r   fields.0nameZdtr   r   
<listcomp>.       z0TestUtils.test_realign_dtype.<locals>.<listcomp>r   )namesformatsZoffsets   r      cc                    s   g | ]} j | d  qS r!   r"   r$   r'   r   r   r(   =   r)   )r   r   r      )r   r   r   )r   r         N)npdtypeZint32Zint16r*   itemsizeZfloat64Zint8)r   r*   r+   Zdt2r   r'   r   test_realign_dtype%   s<    "zTestUtils.test_realign_dtypeN)__name__
__module____qualname__r   markskipifr   r5   r   r   r   r   r
      s   

r
   c                   @   sL   e Zd ZdZdd Zejddd Zdd Z	d	d
 Z
dd Zdd ZdS )TestUtilModez
    The high-level tests are partially covered by
    test_core.TestConvenienceFunctions.test_fileobj_mode_guessing
    but added some low-level tests as well.
    c                 C   s   t dd u sJ d S )Nz	tmp1.fits)r   fileobj_mode)r   r   r   r   test_mode_stringsP   s    zTestUtilMode.test_mode_stringsznot HAS_PILc                 C   sx   t jdddt j}t|}|| d t	| d"}t
|dksVJ W d    n1 sj0    Y  d S )Nr      )r-   r-      ztest_simple.jpgrb)r2   ZrandomZrandintZastypeZuint8r   Z	fromarrayZsavetempopenr   r<   )r   Zimgresultfileobjr   r   r   test_mode_pil_imageU   s
    
z TestUtilMode.test_mode_pil_imagec              	   C   sl   g d}|D ]Z\}}}|  d| d}t||"}t||ksHJ W d    q1 s\0    Y  qd S )N))r   r   abr   rF   rF   )r   r   wbr   rH   rH   )r   xxb)r   rr@   r   r@   r@   r   z.gz)rA   gzipZGzipFiler   r<   r   Znum_mode_resmodenummoderesfilenamerD   r   r   r   test_mode_gzip_   s
    zTestUtilMode.test_mode_gzipc              	   C   sn   g d}|D ]\\}}}|  d| d}t||dd"}t||ksJJ W d    q1 s^0    Y  qd S )N)rG   rI   )r   rK   rK   rM   Ztest1.datr   )	bufferingrA   rB   r   r<   rO   r   r   r   test_mode_normal_bufferingp   s
    z'TestUtilMode.test_mode_normal_bufferingc              	   C   sj   g d}|D ]X\}}}|  d| d}t||"}t||ksFJ W d    q1 sZ0    Y  qd S )N)r   r   r   rG   )r   r   r   rI   )r   rJ   rJ   )r   rL   rL   rM   Ztest2rU   rW   rO   r   r   r   test_mode_normal_no_buffering}   s
    z*TestUtilMode.test_mode_normal_no_bufferingc              	   C   sb   dD ]X\}}}|  d| d}t||"}t||ks>J W d    q1 sR0    Y  qd S )N)rY   )r   a+r[   rG   )r   za+bab+)r   r\   r\   Ztest3rU   rW   )r   rP   rQ   rR   rS   rD   r   r   r   test_mode_normalization   s    z$TestUtilMode.test_mode_normalizationN)r6   r7   r8   __doc__r=   r   r9   r:   rE   rT   rX   rZ   r]   r   r   r   r   r;   I   s   

	r;   c                  C   s\  t g d} tt}t|  W d    n1 s60    Y  |jjd dksTJ t jg ddd} t|  t| t jg ddd t jg ddd} t|  t| t jg ddd t jd	d
gddggdd} t|  t| t jdd
gddggdd t 	dd
d} t|  t| d t 	dd
dd dd dd df } t|  t| d d S )N)r   r   r?   r   z/This function can only be used on string arrays)a  b c c   ZS6)r3   )r   r`    c cZU6r_   r`   ra   z a r   rb   z az a a    )r   r?   r,   z a ai  )
   rd   rd   r   r?   r,   )r2   Zarrayr   r   	TypeErrorr   valueargsr   repeatZreshape)sexcr   r   r   test_rstrip_inplace   s&    & 
(rk   )r   r   rN   r   Znumpyr2   Znumpy.testingr   Zastropy.io.fitsr   Zastropy.io.fits.utilr   r   Z"astropy.utils.compat.optional_depsr   ZPILr    r	   r
   r;   rk   r   r   r   r   <module>   s   4R