o
    j                     @   sp   d dl Z d dlZd dlZd dlZd dlZ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 G dd deZdS )    N)
CythonTestc                   @   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d  Zd!d" Zd#d$ Zd%d& Zd'S )(TestCyCachec                 C   sR   t |  tjdtjdrdnd d| _tjd| jd| _tjd| jd| _	d S )Nzcycache-testZTEST_TMP)prefixdirsrccache)
r   setUptempfilemkdtempospathisdirtemp_dirsrc_dir	cache_dirself r   _/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/Cython/Build/Tests/TestCyCache.pyr      s   
zTestCyCache.setUpc                 C   s   t  tj| j|S N)globr   r   joinr   )r   Z	file_globr   r   r   cache_files   s   zTestCyCache.cache_filesc                 O   s,   t j  d t jj_t jjj|i | d S r   )CythonUtilsclear_function_cachesZBuildZDependenciesZ	_dep_treeZ	cythonizer   argskwargsr   r   r   fresh_cythonize   s   

zTestCyCache.fresh_cythonizec                 O   s"   t j  t jjj|i | d S r   )r   r   r   ZCompilerZMaincompiler   r   r   r   fresh_compile!   s   
zTestCyCache.fresh_compilec           
      C   s*  d}d}t j| jd}|d d d }t|d}|| W d    n1 s)w   Y  ||| jd ||| jd | dt| 	d	 t|}|
 }W d    n1 sZw   Y  t | t|d}|| W d    n1 syw   Y  ||| jd t|}|
 }W d    n1 sw   Y  t | | ||d
 | dt| 	d	 t|d}|| W d    n1 sw   Y  ||| jd | dt| 	d	 t|}|
 }	W d    n1 sw   Y  | j|	|dtt|	d|dd d d d S )Nz
value = 1
z
value = 2
a.pyx.cwr      za.c*zC file not changed!   

   )msg)r   r   r   r   openwriter   assertEquallenr   readunlinkZassertNotEquallistdifflibZunified_diffsplit)
r   compilation_methodZcontent1Zcontent2a_pyxa_cfZa_contents1Za_contents2
a_contentsr   r   r   _test_cycache_switch&   sP   









z TestCyCache._test_cycache_switchc                 C      |  | j d S r   )r:   r   r   r   r   r   test_cycache_switch_cythonizeP      z)TestCyCache.test_cycache_switch_cythonizec                 C   r;   r   )r:   r!   r   r   r   r   test_cycache_switch_compileS   r=   z'TestCyCache.test_cycache_switch_compilec                 C   s  t j| jd}|d d d }t|d}|d W d    n1 s%w   Y  ||| jd t j| jt | jd }t	|d}|d	 W d    n1 sUw   Y  t 
| ||| jd t|}| }W d    n1 syw   Y  | |d
d|d d   d S )Nr"   r#   r$   r%   passr&   r   wbs
   fake stuffz
fake stuffzUnexpected contents: %s...d   )r   r   r   r   r,   r-   r   listdirgzipGzipFiler1   r0   r.   )r   r5   r6   r7   r8   Za_cacheZgzipfiler9   r   r   r   _test_cycache_uses_cacheV   s$   


z$TestCyCache._test_cycache_uses_cachec                 C   r;   r   )rE   r   r   r   r   r   !test_cycache_uses_cache_cythonizek   r=   z-TestCyCache.test_cycache_uses_cache_cythonizec                 C   r;   r   )rE   r!   r   r   r   r   test_cycache_uses_cache_compilen   r=   z+TestCyCache.test_cycache_uses_cache_compilec                 C   s   t j| jd}|d d d }|d d d }t|d}|d W d    n1 s-w   Y  ||| jdd | t j|| t 	| t 	| ||| jdd | t j|| d S )	Nr"   r#   r$   z.htmlr%   r?   default)r   Zannotate
r   r   r   r   r,   r-   r   Z
assertTrueexistsr1   )r   r5   r6   r7   Za_htmlr8   r   r   r   _test_cycache_annotationq   s   

z$TestCyCache._test_cycache_annotationc                 C   r;   r   )rK   r   r   r   r   r   !test_cycache_annotation_cythonize   r=   z-TestCyCache.test_cycache_annotation_cythonizec                 C   r;   r   )rK   r!   r   r   r   r   test_cycache_annotation_compile   r=   z+TestCyCache.test_cycache_annotation_compilec           	      C   s   t j| jd}|d d d }|d d d }|d d d }t|d}|d W d    n1 s5w   Y  ||| jd |||g}|D ]}| t j|| t 	| qH||| jd |D ]}| t j|| qcd S )	Nr"   r#   r$   z.hz_api.hr%   z)cdef public api int foo(int x): return x
r&   rI   )	r   r5   r6   r7   Za_hZa_api_hr8   expectedoutputr   r   r   _test_multi_file_output   s    
z#TestCyCache._test_multi_file_outputc                 C   r;   r   )rP   r   r   r   r   r    test_multi_file_output_cythonize   r=   z,TestCyCache.test_multi_file_output_cythonizec                 C   r;   r   )rP   r!   r   r   r   r   test_multi_file_output_compile   r=   z*TestCyCache.test_multi_file_output_compilec                 C   sP  t j| jd}|d td  d }|d td  d }t|d}|d W d    n1 s3w   Y  ||| jdd | d	t| 	d
 t 
| ||| jdd | dt| 	d
 zt 
| W n tyx   t 
| Y nw ||| jddd | dt| 	d
 t 
| ||| jddd | dt| 	d
 d S )Nzoptions.pyxz.pyxr$   z.cppr%   r?   F)r   cplusr'   z
options.c*Tr(   )r   rS   Zshow_version)r   r   r   r   r/   r,   r-   r   r.   r   r1   FileNotFoundError)r   r5   Zhash_pyxZhash_cZhash_cppr8   r   r   r   _test_options_invalidation   s*   

z&TestCyCache._test_options_invalidationc                 C   r;   r   )rU   r   r   r   r   r   #test_options_invalidation_cythonize   r=   z/TestCyCache.test_options_invalidation_cythonizec                 C   r;   r   )rU   r!   r   r   r   r   !test_options_invalidation_compile   r=   z-TestCyCache.test_options_invalidation_compileN)__name__
__module____qualname__r   r   r   r!   r:   r<   r>   rE   rF   rG   rK   rL   rM   rP   rQ   rR   rU   rV   rW   r   r   r   r   r      s(    *r   )r3   r   rC   r   sysr	   ZunittestZCython.Build.Dependenciesr   ZCython.Compiler.MainZCython.UtilsZCython.TestUtilsr   r   r   r   r   r   <module>   s    