U
    e                     @   sp   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 d dlmZ	 ddl
mZ e jdd ZG dd	 d	ejZdS )
    N)open)join   )extended_iglobc              	   c   s*   t t| |ddd}|V  W 5 Q R X d S )Nwutf8)encoding)r   pjoin)dir_pathfilenamef r   G/tmp/pip-unpacked-wheel-7k3cqui1/Cython/Build/Tests/TestDependencies.pywritable_file   s    r   c                   @   sD   e Zd Zedd Zedd Zdd Zdd Zd	d
 Zdd Z	dS )TestGlobbingc                 C   s  t  | _tjd dk r(t  }| _nt | _| jj	}t 
| dD ]}||d fD ]}dD ]X}t||}t | t|d}|d W 5 Q R X t|d}|d	 W 5 Q R X q`t|d
}|d W 5 Q R X t|d}|d	 W 5 Q R X qXqHd S )Nr      Zabcdxxyzfile2_pyx.pyxz""" PYX """file2_py.pyz
""" PY """file1_pyx.pyxfile1_py.py)osgetcwd	_orig_dirsysversion_infotempfilemkdtemp_tmpdirTemporaryDirectorynamechdirr	   makedirsr   write)clsZ	temp_pathZdir1Zdir1xZdir2r
   r   r   r   r   
setUpClass   s&    




zTestGlobbing.setUpClassc                 C   s>   t | j tjd dk r0dd l}|| j n
| j  d S )Nr   r   )	r   r"   r   r   r   shutilrmtreer   cleanup)r%   r'   r   r   r   tearDownClass,   s
    zTestGlobbing.tearDownClassc                 C   s`   t |}t dd t|D }| || tjdkr\d|kr\t t|dd}| || d S )Nc                 s   s   | ]}| d tjV  qdS )/N)replacer   sep).0pathr   r   r   	<genexpr>8   s     z+TestGlobbing.files_equal.<locals>.<genexpr>\r+   )sortedr   ZassertListEqualr   r-   r,   )selfpatternZexpected_filesZmatched_filesr   r   r   files_equal5   s    zTestGlobbing.files_equalc                 C   s   t dddt dddg}| d| | dg  | d| | d| | d	|d d
  | d|d d
  | d|d
d   | d|d
d   d S )Nar   r   r   za/x/*z	a/x/*.c12za/x/*.{py,pyx,c12}za/x/*.{py,pyx}za/x/*.{pyx}   z	a/x/*.pyxz
a/x/*.{py}za/x/*.py)r	   r5   )r3   Zax_filesr   r   r   test_extended_iglob_simple@   s    z'TestGlobbing.test_extended_iglob_simplec              	      s  dD ]t  fdddD }|   d | |   d g  |   d | |   d | |   d	 |d d d
  |   d |d d d
  |   d |dd d
  |   d |dd d
  dD ] fdddD } d  d }|  |d | |  |d | |  |d |d d d
  |  |d |d d d
  |  |d |dd d
  |  |d |dd d
  qqd S )Nadc                    s"   g | ]}d D ]}t  ||qqS )r   r   r	   r.   dirnamer   )basedirr   r   
<listcomp>M   s    z@TestGlobbing.test_extended_iglob_simple_star.<locals>.<listcomp>r   z/*/*z/*/*.c12z/*/*.{py,pyx,c12}z/*/*.{py,pyx}z
/*/*.{pyx}r   z/*/*.pyxz	/*/*.{py}r7   z/*/*.pyzxy*c                    s.   g | ]&}d |fkrdD ]}t  ||qqS )*r:   r;   r<   r>   subdirr   r   r?   \   s
    r+   r@   z
*.{py,pyx}z*.{pyx}z*.pyxz*.{py}z*.py)r5   )r3   filesr/   r   rA   r   test_extended_iglob_simple_starK   s.    

z,TestGlobbing.test_extended_iglob_simple_starc                 C   s  t d}dd |D }dd |D | }| d| | d| | d| | d| | d	g  | d
g  | d| | d| | d| | d| | d| | d| | d| | d| | d| | d|d d d  | d|d d d  | d|d d d  | d|d d d  | d|d d d  | d|dd d  | d|dd d  | d|dd d  | d|dd d  d S )N.c                 S   s,   g | ]$}d D ]}dD ]}t |||qqqS )r   r:   r;   )r.   r>   r=   r   r   r   r   r?   l   s     z@TestGlobbing.test_extended_iglob_double_star.<locals>.<listcomp>c                 S   s    g | ]}d D ]}t ||qqS ))r   r   r;   )r.   r>   r   r   r   r   r?   r   s    z*/*/*z*/*/**/*z*/**/*.*z**/*.*z
*/**/*.c12z**/*.c12z*/*/*.{py,pyx,c12}z*/*/**/*.{py,pyx,c12}z*/**/*/*.{py,pyx,c12}z**/*/*/*.{py,pyx,c12}z**/*.{py,pyx,c12}z*/*/*.{py,pyx}z**/*/*/*.{py,pyx}z*/**/*/*.{py,pyx}z**/*.{py,pyx}z*/*/*.{pyx}r   z
**/*.{pyx}z*/**/*/*.pyxz	*/*/*.pyxz**/*.pyxz
*/*/*.{py}r7   z	**/*.{py}z*/*/*.pyz**/*.py)r   listdirr5   )r3   ZbasedirsrC   	all_filesr   r   r   test_extended_iglob_double_starj   sB    
z,TestGlobbing.test_extended_iglob_double_starN)
__name__
__module____qualname__classmethodr&   r*   r5   r8   rD   rH   r   r   r   r   r      s   

r   )
contextlibos.pathr   r   r   Zunittestior   r   r	   ZDependenciesr   contextmanagerr   ZTestCaser   r   r   r   r   <module>   s   
