a
    ReL                     @   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   sL   t | | t|tu r*t t| t| nt t| jjt|jj dS )z*Assert whether value AND type are the sameN)r   typestrnpZasarraydtypeab r   K/var/www/sunrise/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_byte1   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_int165   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_int329   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_float64A   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_complex32E   s    zTestScalars.test_complex32c                 C   s*   t ttddd}t|jtd 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   r   r   
test_bytesI   s    zTestScalars.test_bytesc                 C   s   d S Nr   r   r   r   r   test_structureM   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_complex64P   s    zTestScalars.test_complex64c                 C   s   d S r7   r   r8   r   r   r   test_heap_pointerT   s    zTestScalars.test_heap_pointerc                 C   s   d S r7   r   r8   r   r   r   test_object_referenceW   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_uint16Z   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_uint32^   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   int64r(   r   r   r   
test_int64b   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_uint64f   s    zTestScalars.test_uint64N)r"   r#   r$   r)   r*   r,   r0   r2   r4   r6   r9   r=   r>   r?   r@   rA   rC   rD   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:         rG         r         rH   r         @g      @g      @g      @      ?       @      @       @s   cheeses   bacon   spam)r   r   r   r   r   r   r   r   r.   r/   r;   r<   r   array5dshapearraysr   arrayr   r   cr3   dobjectr(   r   r   r   test_compressedn   s    ""(zTestCompressed.test_compressedN)r"   r#   r$   r\   r   r   r   r   rE   k   s   rE   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   array1drV   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   array2drV   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&      rc   rd   )r   r   r   r   r   array3drV   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&   rG   rJ         )r   r   r   r   r   array4drV   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&   rF   )r   r   r   r   r   rU   rV   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&   rH   rI   rG   rJ   rH   rG   )r   r   r   r   r   array6drV   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&   rM   rL   rM   rH   rG   rH   rM   )r   r   r   r   r   array7drV   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&   rG   rH   rM   rL   rM   rH   rJ   rG   )r   r   r   r   r   array8drV   r(   r   r   r   test_8d   s    zTestArrayDimensions.test_8dNr"   r#   r$   ra   rf   rj   ro   rp   rs   rv   ry   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&   rL   rM         @rP   rT   rN               @)r   r   r   r   r   Zscalarsr   r   rX   r   r   r+   rY   r/   rZ   r1   er[   fr3   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&   rL   rJ   rM   r|   rP   rT   r}   )r   r   r   r   r   scalars_repr   r   repeatr   r   r+   rY   r/   rZ   r1   r~   astyper[   r   r3   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&   rL      rG   rH   rM   r|   rP   rT   r}   )r   r   r   r   r   r   r   r   r   r   reshaper   r+   rY   r/   rZ   r1   r~   r   r[   r   r3   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   rK   rN   rO   rQ   rR   rS   )r   r   r   r   r   rW   r   r   rX   r   r   r/   rY   r3   rZ   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&   rJ   rJ   rK   rN   rO   rQ   rR   rS   r   r   r   r   r   
arrays_repr   r   r
   r   object_r   rY   rZ   r   rV   ranger   rX   r   r/   r3   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&   rG   rH   rM   rG   rH   rM   rK   rN   rO   rQ   rR   rS   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   rN   rG   )r   r   r   r   r   Zfcxr   rX   r   yrrY   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   rN   )r   filterUserWarningr   r   r   r   r   r   r   r   rX   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^   rP   r   )r   r   r   r   r   r`   rV   r   r   allr/   vect_idr   r(   r   r   r   ra     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&   rb   rP   )r   r   )r   r   r   r   r   re   rV   r   r   r   r/   r   r   r(   r   r   r   rf   "  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&   rg   rP   r   r   r   )r   r   r   r   r   ri   rV   r   r   r   r/   r   r   r(   r   r   r   rj   (  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&   rk   rP   )r   r   r   r   )r   r   r   r   r   rn   rV   r   r   r   r/   r   r   r(   r   r   r   ro   .  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&   rF   rP   )r   r   r   r   r   )r   r   r   r   r   rU   rV   r   r   r   r/   r   r   r(   r   r   r   rp   4  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&   rq   rP   )r   r   r   r   r   r   )r   r   r   r   r   rr   rV   r   r   r   r/   r   r   r(   r   r   r   rs   :  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&   rt   rP   )r   r   r   r   r   r   r   )r   r   r   r   r   ru   rV   r   r   r   r/   r   r   r(   r   r   r   rv   @  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&   rw   rP   )r   r   r   r   r   r   r   r   )r   r   r   r   r   rx   rV   r   r   r   r/   r   r   r(   r   r   r   ry   F  s    zTestPointerArray.test_8dNrz   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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&   rP   rN   r   )r   r   r   r   r   Zpointersgr   rX   r/   r   hr   r   r(   r   r   r   r   P  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&   rP   rJ   )r   r   r   r   r   pointers_repr   r   r   r/   r   r   r   r   r   r   r(   r   r   r   test_pointers_replicatedV  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&   rP   r   rG   rH   rM   )r   r   r   r   r   r   r/   r   r   r   r   r   r   r   r   r   r   )r   r    Zs_expectr   r   r   test_pointers_replicated_3d\  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   rP   rM   rH   )r   r   r   r   r   rW   r   r   r   r/   r   r   r   r   r   r   r   r(   r   r   r   r   c  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   rJ   rP   rM   rH   r   )r   r   r   r   r   r   r   r   r
   r   r   r   r   rV   r   r   r   r/   r   r   r   r   r   r   r   r   r   k  s    ((.z,TestPointerStructures.test_arrays_replicatedc                 C   sV  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t	t|jj|||f t|jjd	 d
 k tt	t|jj|||f t|jjd	 d
 k qqxqld S )Nz'struct_pointer_arrays_replicated_3d.savFr&   r   rG   rH   rM   rP   r   r   )r   r   r   r   r   r   r   r   r
   r   r   r   r   rV   r   r   r   r/   r   r   r   r   )r   pthr    r   r   r   r   r   r   r   }  s"    4z/TestPointerStructures.test_arrays_replicated_3dN)	r"   r#   r$   r   r   r   r   r   r   r   r   r   r   r   M  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&   rJ   )	r   r   r   r   r   Z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&   rL   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   rX   )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onerL   twozhas no attribute)match)r   ZAttrDictr   pytestZraisesKeyErrorAttributeErrorr   )rZ   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%   rE   r]   r{   r   r   r   r   r   r   r   r   r   r   r   <module>   s,   	
=$p
4F