a
    ߙfb                     @   sp   d dl Z d dlZd dlmZ d dlmZ ddlmZ e	ej
jZe	ejZe	ejjZG dd deZdS )    N)fits)compress_hdu   )FitsTestCasec                   @   sF  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	e
jdddgdd Ze
jdg ddd Ze
jdddgdd Ze
jdg ddd Ze
jddgdd  Ze
jdg d!d"d# Ze
jd$d%d&gd'd( Ze
jdg d)d*d+ Ze
jdd,d-gd.d/ Ze
jdd0d1gd2d3 Zd4S )5TestCompressionFunctionc                 C   s8   t t tdd W d    n1 s*0    Y  d S )Nr      )pytestraises	TypeErrorr   )self r   Nlib/python3.9/site-packages/astropy/io/fits/tests/test_compression_failures.pytest_wrong_argument_number   s    z2TestCompressionFunction.test_wrong_argument_numberc                 C   sb   t td}d|jd< tt}t| W d    n1 sB0    Y  dt	|j
v s^J d S )N
   r   ZfunZCMPTYPEz"Unrecognized compression type: funr   CompImageHDUnpones_headerr   r	   
ValueErrorr   strvaluer   hduexcr   r   r   test_unknown_compression_type   s
    
&z5TestCompressionFunction.test_unknown_compression_typec                 C   sb   t td}d|jd< tt}t| W d    n1 sB0    Y  dt	|j
v s^J d S )Nr      ZBITPIXzInvalid value for BITPIX: 13r   r   r   r   r   test_zbitpix_unknown   s
    
&z,TestCompressionFunction.test_zbitpix_unknownc                 C   s^   t td}d |_tt}t| W d    n1 s>0    Y  dt	|j
v sZJ d S )Nr   z)CompImageHDU.data must be a numpy.ndarray)r   r   r   r   datar   r	   r
   r   r   r   r   r   r   r   test_data_none$   s
    &z&TestCompressionFunction.test_data_nonec                 C   s\   t td}|`tt}t| W d    n1 s<0    Y  dt	|j
v sXJ d S )Nr   r   )r   r   r   r   r   r   r	   AttributeErrorr   r   r   r   r   r   r   test_missing_internal_header+   s
    &z4TestCompressionFunction.test_missing_internal_headerc                 C   sp   t td}d|jd< tt}t| W d    n1 sB0    Y  dt	|j
v rhdt	|j
v slJ d S )Nr   ZTXTFORM1ZTFORM)r   r   r   r   r   r   r	   RuntimeErrorr   r   r   r   r   r   r   test_invalid_tform2   s
    
&z*TestCompressionFunction.test_invalid_tformc                 C   sT   t jtddd}d|jd< tt t| W d    n1 sF0    Y  d S )Nr   r   )Zquantize_methodaZZDITHER0	r   r   r   r   r   r   r	   r
   r   )r   r   r   r   r   test_invalid_zdither9   s    
z,TestCompressionFunction.test_invalid_zditherkwZNAXISr   c                 C   s`   t td}|j|= tt}t| W d    n1 s@0    Y  |t	|j
v s\J d S )Nr   )r   r   r   r   r   r   r	   KeyErrorr   r   r   r   r+   r   r   r   r   r   test_header_missing_keyword?   s
    &z3TestCompressionFunction.test_header_missing_keyword)r,   ZZVAL1ZZVAL2ZZBLANKZBLANKc                 C   sT   t td}td |j|< tt t	| W d    n1 sF0    Y  d S Nr   r   )
r   r   r   r   MAX_INTr   r   r	   OverflowErrorr   r   r+   r   r   r   r   test_header_value_int_overflowG   s    z6TestCompressionFunction.test_header_value_int_overflowZZTILE1ZZNAXIS1c                 C   sT   t td}td |j|< tt t	| W d    n1 sF0    Y  d S r0   )
r   r   r   r   MAX_LONGr   r   r	   r2   r   r3   r   r   r   test_header_value_long_overflowN   s    z7TestCompressionFunction.test_header_value_long_overflow)NAXIS1NAXIS2ZTNULL1PCOUNTZTHEAPc                 C   sT   t td}td |j|< tt t	| W d    n1 sF0    Y  d S r0   )
r   r   r   r   MAX_LONGLONGr   r   r	   r2   r   r3   r   r   r   #test_header_value_longlong_overflowU   s    z;TestCompressionFunction.test_header_value_longlong_overflowZZVAL3c                 C   sP   t td}d|j|< tt t| W d    n1 sB0    Y  d S )Nr   gu <7~)	r   r   r   r   r   r   r	   r2   r   r3   r   r   r    test_header_value_float_overflow\   s    
z8TestCompressionFunction.test_header_value_float_overflow)r7   r8   TFIELDSr9   c                 C   sh   t td}d|j|< tt}t| W d    n1 sB0    Y  | dt	|j
v sdJ d S )Nr   z should not be negative.r   r.   r   r   r   test_header_value_negativec   s
    
&z2TestCompressionFunction.test_header_value_negative)r+   limit)r,     )r=   rA   c                 C   sf   t td}|d |j|< tt}t| W d    n1 sF0    Y  |t	|j
v sbJ d S r0   r   )r   r+   r@   r   r   r   r   r   &test_header_value_exceeds_custom_limitk   s
    &z>TestCompressionFunction.test_header_value_exceeds_custom_limit)ZTTYPE1r%   r   ZZNAME1ZZQUANTIZc                 C   sP   t td}d|j|< tt t| W d    n1 sB0    Y  d S r0   r)   r3   r   r   r   test_header_value_no_stringv   s    
z3TestCompressionFunction.test_header_value_no_stringZTZERO1ZTSCAL1c                 C   sP   t td}d|j|< tt t| W d    n1 sB0    Y  d S )Nr   1r)   r3   r   r   r   test_header_value_no_double~   s    
z3TestCompressionFunction.test_header_value_no_doubleZZSCALEZZZEROc                 C   sV   t tjdtjd}d|j|< tt t	| W d    n1 sH0    Y  d S )Nr   )ZdtyperD   )
r   r   r   r   Zint32r   r   r	   r
   r   r3   r   r   r   %test_header_value_no_double_int_image   s    
z=TestCompressionFunction.test_header_value_no_double_int_imageN)__name__
__module____qualname__r   r   r    r"   r$   r'   r*   r   ZmarkZparametrizer/   r4   r6   r;   r<   r?   rB   rC   rE   rF   r   r   r   r   r      s@   








r   )r   Znumpyr   Z
astropy.ior   Zastropy.io.fits.compressionr    r   ZiinfoZintcmaxr1   intr5   Zlonglongr:   r   r   r   r   r   <module>   s   