a
    BCCfP                     @   s  d dl mZ d dlZd dlZd dlmZmZmZm	Z	 d dl
Z
d dlmZ d dlmZ eeedZdd Zd	d
 ZeeZG dd dZG dd dZG dd deZG dd dZG dd dZG dd dZG dd dZG dd dZG dd dZdd Z dd  Z!d!d" Z"dS )#    )pathN)assert_equalassert_array_equalassert_suppress_warnings)readsav)_idldatac                 C   sJ   t | | t|tr(t t| t| nt t| jjt|jj dS )z*Assert whether value AND type are the sameN)r   
isinstancestrtypenpZasarraydtypeab r   S/var/www/html/django/DPS/env/lib/python3.9/site-packages/scipy/io/tests/test_idl.pyassert_identical   s    

r   c                 C   s    t | | t| jj|jj dS )z+Assert whether values AND type are the sameN)r   r   r   r   r   r   r   r   assert_array_identical   s    
r   c                   @   s   e Zd Zdd ZdS )	TestIdictc                 C   sr   dt di}t|}tttd|dd}t|t| td|v  t	|d t d t	|d t 
d d S )Nr   i  scalar_byte.savF)Zidictverbosei8u   )r   int16idr   r   join	DATA_PATHr   r   r   uint8)selfZcustom_dictZoriginal_idsr   r   r   
test_idict$   s    zTestIdict.test_idictN)__name__
__module____qualname__r"   r   r   r   r   r   "   s   r   c                   @   s   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	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS ) TestScalarsc                 C   s*   t ttddd}t|jtd d S )Nr   Fr   r   r   r   r   r   r   r   r   r   r    r!   r   r   r   	test_byte2   s    zTestScalars.test_bytec                 C   s*   t ttddd}t|jtd d S )Nzscalar_int16.savFr'   i`)r   r   r   r   r   Zi16sr   r   r)   r   r   r   
test_int166   s    zTestScalars.test_int16c                 C   s*   t ttddd}t|jtd d S )Nzscalar_int32.savFr'   i.i)r   r   r   r   r   Zi32sr   int32r)   r   r   r   
test_int32:   s    zTestScalars.test_int32c                 C   s*   t ttddd}t|jtd d S )Nzscalar_float32.savFr'   )r   r   r   r   r   f32r   float32r)   r   r   r   test_float32>   s    zTestScalars.test_float32c                 C   s*   t ttddd}t|jtd d S )Nzscalar_float64.savFr'   gCmC)r   r   r   r   r   Zf64r   float64r)   r   r   r   test_float64B   s    zTestScalars.test_float64c                 C   s*   t ttddd}t|jtd d S )Nzscalar_complex32.savFr'   y  )jB̕h~=r)r   r   r   r   r   Zc32r   	complex64r)   r   r   r   test_complex32F   s    zTestScalars.test_complex32c                 C   s.   t ttddd}d}t|jt| d S )Nzscalar_string.savFr'   z.The quick brown fox jumps over the lazy python)r   r   r   r   r   r!   r   bytes_)r    r!   msgr   r   r   
test_bytesJ   s    zTestScalars.test_bytesc                 C   s   d S Nr   r    r   r   r   test_structureO   s    zTestScalars.test_structurec                 C   s*   t ttddd}t|jtd d S )Nzscalar_complex64.savFr'   *3Wo)r   r   r   r   r   c64r   
complex128r)   r   r   r   test_complex64R   s
    zTestScalars.test_complex64c                 C   s   d S r9   r   r:   r   r   r   test_heap_pointerY   s    zTestScalars.test_heap_pointerc                 C   s   d S r9   r   r:   r   r   r   test_object_reference\   s    z!TestScalars.test_object_referencec                 C   s*   t ttddd}t|jtd d S )Nzscalar_uint16.savFr'   i  )r   r   r   r   r   Zi16ur   Zuint16r)   r   r   r   test_uint16_   s    zTestScalars.test_uint16c                 C   s*   t ttddd}t|jtd d S )Nzscalar_uint32.savFr'   l    )r   r   r   r   r   Zi32ur   Zuint32r)   r   r   r   test_uint32c   s    zTestScalars.test_uint32c                 C   s*   t ttddd}t|jtd d S )Nzscalar_int64.savFr'   l'{ )r   r   r   r   r   Zi64sr   Zint64r)   r   r   r   
test_int64g   s    zTestScalars.test_int64c                 C   s*   t ttddd}t|jtd d S )Nzscalar_uint64.savFr'   l   ( )r   r   r   r   r   Zi64ur   Zuint64r)   r   r   r   test_uint64k   s    zTestScalars.test_uint64N)r#   r$   r%   r*   r+   r-   r1   r3   r5   r8   r;   r?   r@   rA   rB   rC   rD   rE   r   r   r   r   r&   /   s   r&   c                   @   s   e Zd Zdd ZdS )TestCompressedc                 C   s   t ttddd}t|jtd t|jt	d t|j
td t|jjd t|jjd tjg d	tjd
 t|jjd tjg dtj	d
 t|jjd ttdtdg t|jjd tjg dtd
 d S )Nzvarious_compressed.savFr'   r   r.   r<         rH         r         rI   r         @g      @g      @g      @      ?       @      @       @s   cheeses   bacon   spam)r   r   r   r   r   r   r   r   r/   r0   r=   r>   r   array5dshapearraysr   arrayr   r   cr4   dobjectr)   r   r   r   test_compresseds   s     ""zTestCompressed.test_compressedN)r#   r$   r%   r]   r   r   r   r   rF   p   s   rF   c                   @   sL   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	dd Z
dS )TestArrayDimensionsc                 C   s&   t ttddd}t|jjd d S )Nzarray_float32_1d.savFr'   {   )r   r   r   r   r   array1drW   r)   r   r   r   test_1d   s    zTestArrayDimensions.test_1dc                 C   s&   t ttddd}t|jjd d S )Nzarray_float32_2d.savFr'         )r   r   r   r   r   array2drW   r)   r   r   r   test_2d   s    zTestArrayDimensions.test_2dc                 C   s&   t ttddd}t|jjd d S )Nzarray_float32_3d.savFr'      rd   re   )r   r   r   r   r   array3drW   r)   r   r   r   test_3d   s    zTestArrayDimensions.test_3dc                 C   s&   t ttddd}t|jjd d S )Nzarray_float32_4d.savFr'   rH   rK         )r   r   r   r   r   array4drW   r)   r   r   r   test_4d   s    zTestArrayDimensions.test_4dc                 C   s&   t ttddd}t|jjd d S )Nzarray_float32_5d.savFr'   rG   )r   r   r   r   r   rV   rW   r)   r   r   r   test_5d   s    zTestArrayDimensions.test_5dc                 C   s&   t ttddd}t|jjd d S )Nzarray_float32_6d.savFr'   rI   rJ   rH   rK   rI   rH   )r   r   r   r   r   array6drW   r)   r   r   r   test_6d   s    zTestArrayDimensions.test_6dc                 C   s&   t ttddd}t|jjd d S )Nzarray_float32_7d.savFr'   rN   rM   rN   rI   rH   rI   rN   )r   r   r   r   r   array7drW   r)   r   r   r   test_7d   s    zTestArrayDimensions.test_7dc                 C   s&   t ttddd}t|jjd d S )Nzarray_float32_8d.savFr'   rH   rI   rN   rM   rN   rI   rK   rH   )r   r   r   r   r   array8drW   r)   r   r   r   test_8d   s    zTestArrayDimensions.test_8dNr#   r$   r%   rb   rg   rk   rp   rq   rt   rw   rz   r   r   r   r   r^      s   r^   c                   @   sL   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	dd Z
dS )TestStructuresc                 C   s   t ttddd}t|jjtt	d t|jj
ttd t|jjttd t|jjttd t|jjtjdgtd	 t|jjttd
 d S )Nzstruct_scalars.savFr'   rM   rN         @rQ   rU   rO               @)r   r   r   r   r   Zscalarsr   r   rY   r   r   r,   rZ   r0   r[   r2   er\   fr4   r)   r   r   r   test_scalars   s    zTestStructures.test_scalarsc                 C   s   t ttddd}t|jjtt	dd t|jj
ttdd t|jjttdd t|jjttdd t|jjtd	dt t|jjttd
d d S )Nzstruct_scalars_replicated.savFr'   rM   rK   rN   r}   rQ   rU   r~   )r   r   r   r   r   scalars_repr   r   repeatr   r   r,   rZ   r0   r[   r2   r   astyper\   r   r4   r)   r   r   r   test_scalars_replicated   s    z&TestStructures.test_scalars_replicatedc                 C   s   t ttddd}t|jjtt	dd
ddd t|jjttdd
ddd t|jjttd	d
ddd t|jjttd
d
ddd t|jjtdd
dddt t|jjttdd
ddd d S )Nz struct_scalars_replicated_3d.savFr'   rM      rH   rI   rN   r}   rQ   rU   r~   )r   r   r   r   r   r   r   r   r   r   reshaper   r,   rZ   r0   r[   r2   r   r   r\   r   r4   r)   r   r   r   test_scalars_replicated_3d   s"    &&z)TestStructures.test_scalars_replicated_3dc                 C   s   t ttddd}t|jjd tjg dtj	d t|jj
d tjg dtjd t|jjd ttdtd	g t|jjd tjg d
td d S )Nzstruct_arrays.savFr'   r   rL   rO   rP   rR   rS   rT   )r   r   r   r   r   rX   r   r   rY   r   r   r0   rZ   r4   r[   r\   r)   r   r   r   test_arrays   s    "zTestStructures.test_arraysc              	   C   sJ  t ttddd}t|jjjjt	j
u  t|jjjjt	j
u  t|jjjjt	j
u  t|jjjjt	j
u  t|jjjd t|jjjd t|jjjd t|jjjd tdD ]}t|jj| t	jg dt	jd t|jj| t	jg dt	jd t|jj| t	t	d	t	d
g t|jj| t	jg dtd qd S )Nzstruct_arrays_replicated.savFr'   rK   rK   rL   rO   rP   rR   rS   rT   r   r   r   r   r   
arrays_repr   r   r   r   object_r   rZ   r[   r   rW   ranger   rY   r   r0   r4   r\   r    r!   ir   r   r   test_arrays_replicated   s4    
z%TestStructures.test_arrays_replicatedc                 C   s~  t ttddd}t|jjjjt	j
u  t|jjjjt	j
u  t|jjjjt	j
u  t|jjjjt	j
u  t|jjjd t|jjjd t|jjjd t|jjjd tdD ]}tdD ]}tdD ]}t|jj|||f t	jg dt	jd	 t|jj|||f t	jg d
t	jd	 t|jj|||f t	t	dt	dg t|jj|||f t	jg dtd	 qqqd S )Nzstruct_arrays_replicated_3d.savFr'   rH   rI   rN   rH   rI   rN   rL   rO   rP   rR   rS   rT   r   )r    r!   r   jkr   r   r   test_arrays_replicated_3d   s@    

z(TestStructures.test_arrays_replicated_3dc                 C   s   t ttddd}t|jjtjdgtj	d t|jj
tjdgtj	d t|jjtjdgtj	d t|jjtjdgtj	d d S )Nzstruct_inherit.savFr'   r   rO   rH   )r   r   r   r   r   Zfcxr   rY   r   yrrZ   r)   r   r   r   test_inheritance  s
    zTestStructures.test_inheritancec                 C   sl   t  0}|td tttddd}W d    n1 s<0    Y  t|jj	d t
jddgt
jd d S )	Nz.Not able to verify number of bytes from headerzstruct_arrays_byte_idl80.savFr'   r   7   B   rO   )r   filterUserWarningr   r   r   r   r   r   r   r   rY   r   )r    supr!   r   r   r   test_arrays_corrupt_idl80  s    $z(TestStructures.test_arrays_corrupt_idl80N)r#   r$   r%   r   r   r   r   r   r   r   r   r   r   r   r   r|      s   	

 r|   c                   @   s   e Zd Zdd ZdS )TestPointersc                 C   sL   t ttddd}t|jtd t|jtd t	|j|ju  d S )Nzscalar_heap_pointer.savFr'   r<   )
r   r   r   r   r   Zc64_pointer1r   r>   Zc64_pointer2r   r)   r   r   r   test_pointers&  s    zTestPointers.test_pointersN)r#   r$   r%   r   r   r   r   r   r   #  s   r   c                   @   sL   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	dd Z
dS )TestPointerArrayc                 C   sb   t ttddd}t|jjd tt	|jt
dk tt	t|jt|jd k d S )Nzarray_float32_pointer_1d.savFr'   r_   rQ   r   )r   r   r   r   r   ra   rW   r   r   allr0   vect_idr   r)   r   r   r   rb   6  s    zTestPointerArray.test_1dc                 C   sb   t ttddd}t|jjd tt	|jt
dk tt	t|jt|jd k d S )Nzarray_float32_pointer_2d.savFr'   rc   rQ   )r   r   )r   r   r   r   r   rf   rW   r   r   r   r0   r   r   r)   r   r   r   rg   <  s    zTestPointerArray.test_2dc                 C   sb   t ttddd}t|jjd tt	|jt
dk tt	t|jt|jd k d S )Nzarray_float32_pointer_3d.savFr'   rh   rQ   r   r   r   )r   r   r   r   r   rj   rW   r   r   r   r0   r   r   r)   r   r   r   rk   B  s    zTestPointerArray.test_3dc                 C   sb   t ttddd}t|jjd tt	|jt
dk tt	t|jt|jd k d S )Nzarray_float32_pointer_4d.savFr'   rl   rQ   )r   r   r   r   )r   r   r   r   r   ro   rW   r   r   r   r0   r   r   r)   r   r   r   rp   H  s    zTestPointerArray.test_4dc                 C   sb   t ttddd}t|jjd tt	|jt
dk tt	t|jt|jd k d S )Nzarray_float32_pointer_5d.savFr'   rG   rQ   )r   r   r   r   r   )r   r   r   r   r   rV   rW   r   r   r   r0   r   r   r)   r   r   r   rq   N  s    zTestPointerArray.test_5dc                 C   sb   t ttddd}t|jjd tt	|jt
dk tt	t|jt|jd k d S )Nzarray_float32_pointer_6d.savFr'   rr   rQ   )r   r   r   r   r   r   )r   r   r   r   r   rs   rW   r   r   r   r0   r   r   r)   r   r   r   rt   T  s    zTestPointerArray.test_6dc                 C   sb   t ttddd}t|jjd tt	|jt
dk tt	t|jt|jd k d S )Nzarray_float32_pointer_7d.savFr'   ru   rQ   )r   r   r   r   r   r   r   )r   r   r   r   r   rv   rW   r   r   r   r0   r   r   r)   r   r   r   rw   Z  s    zTestPointerArray.test_7dc                 C   sb   t ttddd}t|jjd tt	|jt
dk tt	t|jt|jd k d S )Nzarray_float32_pointer_8d.savFr'   rx   rQ   )r   r   r   r   r   r   r   r   )r   r   r   r   r   ry   rW   r   r   r   r0   r   r   r)   r   r   r   rz   `  s    zTestPointerArray.test_8dNr{   r   r   r   r   r   3  s   r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestPointerStructuresc                 C   s|   t ttddd}t|jjtjt	dtj
d t|jjtjt	dtj
d tt|jjd t|jjd k d S )Nzstruct_pointers.savFr'   rQ   rO   r   )r   r   r   r   r   Zpointersgr   rY   r0   r   hr   r   r)   r   r   r   r   j  s      z"TestPointerStructures.test_scalarsc                 C   s   t ttddd}t|jjtt	dd
tj t|jjtt	dd
tj ttt|jjt|jjk d S )Nzstruct_pointers_replicated.savFr'   rQ   rK   )r   r   r   r   r   pointers_repr   r   r   r0   r   r   r   r   r   r   r)   r   r   r   test_pointers_replicatedp  s    z.TestPointerStructures.test_pointers_replicatedc                 C   sz   t ttddd}ttdddddtj	}t
|jj| t
|jj| ttt|jjt|jjk d S )	Nz!struct_pointers_replicated_3d.savFr'   rQ   r   rH   rI   rN   )r   r   r   r   r   r   r0   r   r   r   r   r   r   r   r   r   r   )r    r!   Zs_expectr   r   r   test_pointers_replicated_3dy  s    $z1TestPointerStructures.test_pointers_replicated_3dc                 C   s   t ttddd}t|jjd tt	dd
tj t|jjd tt	dd
tj ttt|jjd t|jjd d k ttt|jjd t|jjd d k tt|jjd d t|jjd d k d S )Nzstruct_pointer_arrays.savFr'   r   rQ   rN   rI   )r   r   r   r   r   rX   r   r   r   r0   r   r   r   r   r   r   r   r)   r   r   r   r     s    ..z!TestPointerStructures.test_arraysc                 C   s  t ttddd}t|jjjjt	j
u  t|jjjjt	j
u  t|jjjd t|jjjd tdD ]}t|jj| t	t	ddt	j
 t|jj| t	t	ddt	j
 tt	t|jj| t|jjd	 d	 k tt	t|jj| t|jjd	 d	 k qhd S )
Nz$struct_pointer_arrays_replicated.savFr'   r   rK   rQ   rN   rI   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   rW   r   r   r   r0   r   r   r   r   r   r   r   r   r     s     .z,TestPointerStructures.test_arrays_replicatedc           
   
   C   sh  t td}t|dd}t|jjjjt	j
u  t|jjjjt	j
u  t|jjjd t|jjjd tdD ]}tdD ]}tdD ]}t|jj|||f t	t	ddt	j
 t|jj|||f t	t	ddt	j
 t|jj|||f }t|jjd	 d
 }t	||ks"J t|jj|||f }t|jjd	 d
 }	t	||	ksJ qqxqld S )Nz'struct_pointer_arrays_replicated_3d.savFr'   r   rH   rI   rN   rQ   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   rW   r   r   r   r0   r   r   r   r   )
r    pthr!   r   r   r   Zg0g1Zh0Zh1r   r   r   r     s*    z/TestPointerStructures.test_arrays_replicated_3dN)	r#   r$   r%   r   r   r   r   r   r   r   r   r   r   r   g  s   	
r   c                   @   s   e Zd ZdZdd ZdS )TestTagsz4Test that sav files with description tag read at allc                 C   s*   t ttddd}t|jtd d S )Nzscalar_byte_descr.savFr'   r   r(   r)   r   r   r   test_description  s    zTestTags.test_descriptionN)r#   r$   r%   __doc__r   r   r   r   r   r     s   r   c                  C   s6   t ttddd} t| jd  t| jtd d S )Nznull_pointer.savFr'   rK   )	r   r   r   r   r   pointcheckr   r   )r!   r   r   r   test_null_pointer  s    r   c                  C   s   t jdd.} t d tttddd}W d    n1 s@0    Y  tt| dk tt	| d j
d	k t|d
 td d g d S )NT)recordalwayszinvalid_pointer.savFr'   rM   r   zNVariable referenced by pointer not found in heap: variable will be set to Noner   )warningscatch_warningssimplefilterr   r   r   r   r   lenr   messager   r   rY   )wr!   r   r   r   test_invalid_pointer  s    
2r   c                  C   s   t ddi} | d dksJ | jdks,J tt | d  W d    n1 sT0    Y  tjtdd | j W d    n1 s0    Y  d S )NonerM   twozhas no attribute)match)r   ZAttrDictr   pytestZraisesKeyErrorAttributeErrorr   )r[   r   r   r   test_attrdict  s    &r   )#osr   r   numpyr   Znumpy.testingr   r   r   r   r   Zscipy.ior   r   r   dirname__file__r   r   r   Z	vectorizer   r   r   r&   rF   r^   r|   r   r   r   r   r   r   r   r   r   r   r   <module>   s,   	
A$z4S