o
    !g*                     @   s   d Z ddlZddlZddlZddlmZmZ ddlmZ ddl	m
Z
mZmZ ddlZddlZddlmZ dZd	d
 ZG dd dZG dd dZdS )zTests for distutils.filelist.    N)debugfilelist)DistutilsTemplateError)FileList
glob_to_retranslate_pattern   )py39zinclude ok
include xo
exclude xo
include foo.tmp
include buildout.cfg
global-include *.x
global-include *.txt
global-exclude *.tmp
recursive-include f *.oo
recursive-exclude global *.x
graft dir
prune dir3
c                 C   s   |  dtjS )z"Converts '/' in a string to os.sep/)replaceossep)s r   h/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/_distutils/tests/test_filelist.pymake_local_path   s   r   c                   @   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d Z
dd Zdd Zdd ZdS )TestFileListc                 C   s$   dd |j D }|rJ |  d S )Nc                 S      g | ]
}|j tjkr|qS r   levelnologgingWARNING.0recr   r   r   
<listcomp>&       z1TestFileList.assertNoWarnings.<locals>.<listcomp>recordsclearselfcaplogwarningsr   r   r   assertNoWarnings%      zTestFileList.assertNoWarningsc                 C   s$   dd |j D }|sJ |  d S )Nc                 S   r   r   r   r   r   r   r   r   +   r   z/TestFileList.assertWarnings.<locals>.<listcomp>r   r    r   r   r   assertWarnings*   r%   zTestFileList.assertWarningsc                 C   sJ   t j}t jdkrtt j}dD ]\}}|d|i }t||ks"J qd S )N\))zfoo*z(?s:foo[^%(sep)s]*)\Z)zfoo?z(?s:foo[^%(sep)s])\Z)zfoo??z(?s:foo[^%(sep)s][^%(sep)s])\Z)zfoo\\*z(?s:foo\\\\[^%(sep)s]*)\Z)zfoo\\\*z(?s:foo\\\\\\[^%(sep)s]*)\Z)zfoo????z2(?s:foo[^%(sep)s][^%(sep)s][^%(sep)s][^%(sep)s])\Z)zfoo\\??z"(?s:foo\\\\[^%(sep)s][^%(sep)s])\Zr   )r   r   reescaper   )r!   r   globregexr   r   r   test_glob_to_re/   s   
zTestFileList.test_glob_to_rec                 C   s   t  }t}ddddd|d|d|d|d	|d
|d|d|d|d|dg|_tdD ]}| dkr9q0|| q0ddd|d|d|d|d|d|dg	}|j|ks]J d S )Nzfoo.tmpokxozfour.txtzbuildout.cfgz.hg/last-message.txtzglobal/one.txtzglobal/two.txtzglobal/files.xzglobal/here.tmpzf/o/f.oozdir/graft-onezdir/dir2/graft2zdir3/okzdir3/sub/ok.txt
 )r   r   allfilesMANIFEST_INsplitstripprocess_template_linefiles)r!   	file_listmlplinewantedr   r   r   test_process_template_lineB   sB   z'TestFileList.test_process_template_linec                 C   sP   t  }|d | jdksJ |tdd |d | jdks&J d S )Nxxxr0   DEBUGTzxxx
)r   debug_print
readouterroutsetattrr   )r!   capsysmonkeypatchr7   r   r   r   test_debug_printo   s   

zTestFileList.test_debug_printc                 C   s*   t  }g d}|| |j|ksJ d S )N)abc)r   set_allfilesr1   )r!   r7   r6   r   r   r   test_set_allfilesx   s   
zTestFileList.test_set_allfilesc                 C   s6   t  }g d|_|  |  |jg dksJ d S )N)rE   rF   rE   grG   rJ   )rE   rF   rG   rJ   )r   r6   sortremove_duplicatesr!   r7   r   r   r   test_remove_duplicates~   s
   
z#TestFileList.test_remove_duplicatesc                 C   sl   t tdddddsJ td}t|ddd|ksJ t tddddds(J tddddds4J d S )NrE   TF)anchoris_regexsearch*.pyzfilelist.py)hasattrr   r(   compilerQ   )r!   r+   r   r   r   test_translate_pattern   s   
z#TestFileList.test_translate_patternc                 C   s`   t  }|dr
J t  }ddg|_|dsJ t  }ddg|_|d |jdgks.J d S )NrR   a.pyzb.pyza.txt)r   exclude_patternr6   rM   r   r   r   test_exclude_pattern   s   


z!TestFileList.test_exclude_patternc                 C   s   t  }|g  |drJ t  }|ddg |ds J t  }|jd u s*J |ddg |d |jddgks?J d S )NrR   rV   b.txt*)r   rH   include_patternr1   rM   r   r   r   test_include_pattern   s   

z!TestFileList.test_include_patternc              	   C   s  t }t }dD ]}tt || W d    n1 sw   Y  qt }|dd|dg |d |jdgks>J | | |d |jdgksPJ | 	| t }dd|dg|_|d |jd|dgkspJ | | |d |jd|dgksJ | 	| t }|dd|dg |d	 |jd|dgksJ | | |d
 |jd|dgksJ | 	| t }dd|dg|_|d |jdgksJ | | |d |jdgksJ | 	| t }|d|d|d|dg |d |j|d|dgksJ | | |d |j|d|dgks-J | 	| t }d|d|d|dg|_|d |jd|dgksSJ | | |d |jd|dgksiJ | 	| t }|d|d|d|dg |d |j|d|dgksJ | | |d |j|d|dgksJ | 	| t }d|d|d|dg|_|d |jd|dgksJ | | |d |jd|dgksJ | 	| d S )N)	includeexcludezglobal-includezglobal-excludezrecursive-includezrecursive-excludegraftpruneblargrV   rY   zd/c.pyzinclude *.pyzinclude *.rbzexclude *.pyzexclude *.rbzglobal-include *.pyzglobal-include *.rbzglobal-exclude *.pyzglobal-exclude *.rbzd/b.pyzd/c.txtzd/d/e.pyzrecursive-include d *.pyzrecursive-include e *.pyzrecursive-exclude d *.pyzrecursive-exclude e *.pyzf/f.pyzgraft dzgraft ezprune dzprune e)
r   r   pytestraisesr   r5   rH   r6   r$   r&   )r!   r"   r8   r7   actionr   r   r   test_process_template   s   






























z"TestFileList.test_process_templateN)__name__
__module____qualname__r$   r&   r,   r;   rD   rI   rN   rU   rX   r\   re   r   r   r   r   r   $   s    -	r   c                   @   s8   e Zd Zejdd Zdd Zdd Zejdd Zd	S )
TestFindAllc                 C   s    t dd t g ksJ d S )Nfoobar)r   symlinkr   findall)r!   temp_cwdr   r   r   test_missing_symlink,  s   z TestFindAll.test_missing_symlinkc                 C   sV   t jddiddid tjdd}tjdd}||g}tt |ks)J dS )z
        When findall is called with no parameters or with
        '.' as the parameter, the dot should be omitted from
        the results.
        	file1.txtr0   z	file2.txt)rj   rk   rj   rk   N)jaracopathbuildr   joinsortedr   rm   )r!   rn   file1file2expectedr   r   r   test_basic_discovery1  s
   z TestFindAll.test_basic_discoveryc                 C   s6   t jddi| t|d g}t||ksJ dS )zj
        When findall is called with another path, the full
        path name should be returned.
        rp   r0   N)rq   rr   rs   strr   rm   )r!   tmp_pathrx   r   r   r   test_non_local_discovery=  s   z$TestFindAll.test_non_local_discoveryc                 C   s:   t jt jddd| t|}t|dksJ d S )N.r0   )zlink-to-parentsomefiler   )rq   rr   rs   Symlinkr   rm   len)r!   r{   r6   r   r   r   test_symlink_loopF  s   

zTestFindAll.test_symlink_loopN)	rf   rg   rh   	os_helperskip_unless_symlinkro   ry   r|   r   r   r   r   r   ri   +  s    
	ri   )__doc__r   r   r(   	distutilsr   r   distutils.errorsr   distutils.filelistr   r   r   jaraco.pathrq   rb   compatr	   r   r2   r   r   ri   r   r   r   r   <module>   s       	