o
    '[hs                     @   sh   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                   @   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-testTEST_TMP)prefixdirsrccache)
r   setUptempfilemkdtempospathisdirtemp_dirsrc_dir	cache_dir)self r   S/var/www/vscode/pina/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   	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_cachesBuildDependencies	_dep_tree	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unlinkassertNotEquallistdifflibunified_diffsplit)	r   content1content2a_pyxa_cfa_contents1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
 W d    n1 sYw   Y  t | | j|| jd t|}| }W d    n1 s~w   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encoder3   r2   r0   )r   r;   r<   r=   a_cachegzipfiler@   r   r   r   test_cycache_uses_cacheD   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existsr3   )r   r;   r<   a_ha_api_hr=   expectedoutputr   r   r   test_multi_file_outputT   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'   rB   F)r   cplusr)   z
options.c*Tr*   )r   rT   show_version)r   r   r   r   r1   r.   r/   r#   r   r0   r   r3   )r   hash_pyxhash_cr=   r   r   r   test_options_invalidationd   s    


z%TestCyCache.test_options_invalidationN)
__name__
__module____qualname__r	   r   r#   rA   rL   rS   rX   r   r   r   r   r      s    $r   )r6   r   rG   r   sysr
   unittestCython.Build.Dependenciesr   Cython.UtilsCython.TestUtilsr   r   r   r   r   r   <module>   s    