a
    ûb7  ã                   @   sX   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                   @   sD   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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   ún/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/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   )ÚCythonZUtilsZclear_function_cachesZBuildZDependenciesZ	_dep_treeZ	cythonize)r   ÚargsÚkwargsr   r   r   Úfresh_cythonize   s    

zTestCyCache.fresh_cythonizec                 C   sZ  d}d}t j | jd¡}|d d… d }t|dƒ |¡ | j|| jd | j|| jd |  dt	|  
d	¡ƒ¡ t|ƒ ¡ }t  |¡ t|dƒ |¡ | j|| jd t|ƒ ¡ }t  |¡ |  ||d
¡ |  dt	|  
d	¡ƒ¡ t|dƒ |¡ | j|| jd |  dt	|  
d	¡ƒ¡ t|ƒ ¡ }| 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   r   ÚassertEqualÚlenr   ÚreadÚunlinkZassertNotEqualÚlistÚdifflibZunified_diffÚsplit)r   Zcontent1Zcontent2Úa_pyxÚa_cZa_contents1Za_contents2Ú
a_contentsr   r   r   Útest_cycache_switch   s8    


ÿÿþzTestCyCache.test_cycache_switchc                 C   s¸   t j | jd¡}|d d… d }t|dƒ d¡ | j|| jd t j | jt  | j¡d ¡}t	 
|d¡ d	 d
¡¡ t  |¡ | j|| jd t|ƒ ¡ }|  |d	d|d d…  ¡ d S )Nr   r   r   r   Úpassr    r   Úwbz
fake stuffÚasciizUnexpected contents: %s...éd   )r   r   r   r   r&   r'   r   r   ÚlistdirÚgzipÚGzipFileÚencoder+   r*   r(   )r   r/   r0   Za_cacher1   r   r   r   Útest_cycache_uses_cache<   s    
ÿz#TestCyCache.test_cycache_uses_cachec                 C   sÄ   t j | jd¡}|d d… d }|d d… d }|d d… d }t|dƒ d¡ | j|| jd |||g}|D ]"}|  t j 	|¡|¡ t  
|¡ qn| j|| jd |D ]}|  t j 	|¡|¡ q¦d S )	Nr   r   r   z.hz_api.hr   z)cdef public api int foo(int x): return x
r    )r   r   r   r   r&   r'   r   r   Ú
assertTrueÚexistsr+   )r   r/   r0   Za_hZa_api_hÚexpectedÚoutputr   r   r   Útest_multi_file_outputI   s    
z"TestCyCache.test_multi_file_outputc                 C   sü   t j | jd¡}|d tdƒ … d }t|dƒ d¡ | j|| jdd |  	dt|  
d	¡ƒ¡ t  |¡ | j|| jd
d |  	dt|  
d	¡ƒ¡ t  |¡ | j|| jddd |  	dt|  
d	¡ƒ¡ t  |¡ | j|| jdd
d |  	dt|  
d	¡ƒ¡ d S )Nzoptions.pyxz.pyxr   r   r3   F)r   Úcplusr!   z
options.c*Tr"   )r   rA   Zshow_version)r   r   r   r   r)   r&   r'   r   r   r(   r   r+   )r   Zhash_pyxZhash_cr   r   r   Útest_options_invalidationX   s    


z%TestCyCache.test_options_invalidationN)
Ú__name__Ú
__module__Ú__qualname__r   r   r   r2   r;   r@   rB   r   r   r   r   r      s   r   )r-   r   r8   r   r	   ZCython.Build.Dependenciesr   ZCython.UtilsZCython.TestUtilsr   r   r   r   r   r   Ú<module>   s   