o
    e                     @   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   ND:\Projects\ConvertPro\env\Lib\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   s2  d}d}t j| jd}|d d d }t|d}|| W d    n1 s)w   Y  | j|| jd | j|| jd | dt	| 
d	 t|}| }W d    n1 s\w   Y  t | t|d}|| W d    n1 s{w   Y  | j|| jd t|}| }W d    n1 sw   Y  t | | ||d
 | dt	| 
d	 t|d}|| W d    n1 sw   Y  | j|| 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   r   assertEquallenr   readunlinkZassertNotEquallistdifflibZunified_diffsplit)	r   Z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   s   t j| jd}|d d d }t|d}|d W d    n1 s%w   Y  | j|| jd t j| jt | jd }t	
|dd	d
 t | | j|| jd t|}| }W d    n1 slw   Y  | |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   r1   Za_cacher2   r   r   r   test_cycache_uses_cacheB   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 W d    n1 s5w   Y  | j|| jd |||g}|D ]}| t j	|| t 
| qI| j|| jd |D ]}| t j	|| qed 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_hr1   expectedoutputr   r   r   test_multi_file_outputQ   s    
z"TestCyCache.test_multi_file_outputc                 C   s   t j| jd}|d td  d }t|d}|d W d    n1 s(w   Y  | 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   r4   F)r   cplusr!   z
options.c*Tr"   )r   rB   Zshow_version)r   r   r   r   r)   r&   r'   r   r   r(   r   r+   )r   Zhash_pyxZhash_cr1   r   r   r   test_options_invalidationa   s    


z%TestCyCache.test_options_invalidationN)
__name__
__module____qualname__r   r   r   r3   r<   rA   rC   r   r   r   r   r      s    $r   )r-   r   r9   r   r	   ZCython.Build.Dependenciesr   ZCython.UtilsZCython.TestUtilsr   r   r   r   r   r   <module>   s    