o
    5‘ði*  ã                   @   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é   )Úpy39zÎinclude 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s…J ‚|  	|¡ tƒ }| dd|dƒg¡ | d	¡ |jd|dƒgks§J ‚|  |¡ | d
¡ |jd|dƒgks¼J ‚|  	|¡ tƒ }dd|dƒg|_| d¡ |jdgksÙJ ‚|  |¡ | d¡ |jdgksëJ ‚|  	|¡ 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�s“J ‚|  |¡ | d¡ |j|dƒ|dƒgk�s«J ‚|  	|¡ tƒ }d|dƒ|dƒ|dƒg|_| d¡ |jd|dƒgk�sÑJ ‚|  |¡ | d¡ |jd|dƒgk�sçJ ‚|  	|¡ 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       	