U
    fII                     @  s^  U d Z ddlm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 ddlmZ ddlmZmZmZ ddlmZ ddlmZ ddlZd	ejkZd
d ZdddgdZde Zejdd Zdd Ze e!eddddddddgZ"ddgddgfddgd d!dgfd"d#d$gd%gfd&d'd(d)gd*gfd+d,gg fd-d.gd/gfd0d1d2dgd3gfd4d5d6gd7gfd8d9d:d;gg fd<d=d>d?gd@dAgfdBdCdDgdEdFdGgfdHdIdJdKgdLgfdMdNgdOdPdQgfgZ#dRe$dS< ej%&dTdU e#D Z'ej(e'dVdWdX Z)ej%&dYdU e#D Z*ej(e*dVdZd[ Z+d\d] Z,d^d_ Z-G d`da daZ.G dbdc dce.Z/G ddde dee.Z0dS )fzsdist tests    )annotationsN)log)DistutilsTemplateError)FileListegg_infotranslate_pattern)Distribution)DALSZ__pypy__c                 C  s   |  dtjS )z"Converts '/' in a string to os.sep/)replaceossep)s r   =lib/python3.8/site-packages/setuptools/tests/test_manifest.pymake_local_path   s    r   appz0.0)nameversionZpackagesz*from setuptools import setup

setup(**%r)
c               	   c  sD   t jt j } }t t  t _t _z
d V  W 5 | | t _t _X d S N)sysstdoutstderrioStringIO)Z
old_stdoutZ
old_stderrr   r   r   quiet/   s
    
r   c                 C  s   t | d  d S )Nwb)openclose)filenamer   r   r   touch9   s    r    
README.rstMANIFEST.insetup.pyzapp.egg-info/PKG-INFOzapp.egg-info/SOURCES.txtz!app.egg-info/dependency_links.txtzapp.egg-info/top_level.txtzapp/__init__.pyZfooZbarZfoobarzfoo/barzfoo/bar/bazz	./foo/barz*.txtzfoo.txtzbar.txtzfoo/foo.txtz	dir/*.txtzdir/foo.txtzdir/bar.txtzdir/.txtznotdir/foo.txtz*/*.pyzbin/start.pyzdocs/page-?.txtzdocs/page-9.txtzdocs/page-10.txtz
foo/**/barzfoo/bing/barzfoo/bing/bang/barzfoo/abarzfoo/**zfoo/bar/bing.pyzfoo/xz/foo/xz**xzabc/xyzz@nythingzpre[one]postZpreopostZprenpostZpreepostZprepostZ
preonepostzhello[!one]worldZhelloxworldZhelloyworldZhellooworldZ
helloworldZhellooneworldz
[]one].txtzo.txtz].txtze.txtzone].txtzfoo[!]one]barZfooybarzfoo]barZfooobarZfooebarz&list[tuple[str, list[str], list[str]]]translate_specsc                 c  s$   | ]\}}}t t||V  qd S r   zip	itertoolsrepeat.0patternZmatchesZ
mismatchesr   r   r   	<genexpr>   s   r-   )Zparamsc                 C  s   t t| jS r   mapr   ZparamZrequestr   r   r   pattern_match   s    r1   c                 c  s$   | ]\}}}t t||V  qd S r   r&   r*   r   r   r   r-      s   c                 C  s   t t| jS r   r.   r0   r   r   r   pattern_mismatch   s    r2   c                 C  s   | \}}t ||std S r   r   matchAssertionError)r1   r,   targetr   r   r   test_translated_pattern_match   s    r7   c                 C  s   | \}}t ||rtd S r   r3   )r2   r,   r6   r   r   r    test_translated_pattern_mismatch   s    r8   c                   @  s   e Zd Zdd Zdd ZdS )TempDirTestCasec                 C  s$   t  | _t | _t| j d S r   )tempfileZmkdtemptemp_dirr   getcwdold_cwdchdirselfmethodr   r   r   setup_method   s    

zTempDirTestCase.setup_methodc                 C  s   t | j t| j d S r   )r   r>   r=   shutilZrmtreer;   r?   r   r   r   teardown_method   s    zTempDirTestCase.teardown_methodN)__name__
__module____qualname__rB   rD   r   r   r   r   r9      s   r9   c                      s|   e Zd Z f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d Zdd Z  ZS )TestManifestTestc                   s   t  | ttj| jdddd}|t |	  dD ]}t
tj| j| q<tj| jd}t| dD ]}t
tj|| qttj|d}t| d	D ]}t
tj|| qd S )
Nr#   wutf-8encoding)r!   .hidden.rsttesting.rstLICENSEr   )z__init__.pya.txtb.txtzc.rststatic)zapp.jsz
app.js.mapzapp.csszapp.css.map)superrB   r   r   pathjoinr;   writeSETUP_PYr   r    mkdir)r@   rA   ffnameZtest_pkgrR   	__class__r   r   rB      s    


zTestManifestTest.setup_methodc              	   C  s<   t j| jd}t|ddd}|t| W 5 Q R X dS )zWrite a MANIFEST.in.r"   rI   rJ   rK   N)r   rT   rU   r;   r   rV   r	   )r@   contentsZmanifestrY   r   r   r   make_manifest   s    zTestManifestTest.make_manifestc                 C  s2   t t}d|_t|}|  |  t|jjS )z7Run egg_info and get all the files to include, as a setr#   )	r   SETUP_ATTRSscript_namer   Zensure_finalizedrunsetZfilelistfiles)r@   Zdistcmdr   r   r   	get_files   s    zTestManifestTest.get_filesc                 C  s   t tdg |  kstdS )z=Check a missing MANIFEST.in includes only the standard files.r"   N)default_filesrb   re   r5   r@   r   r   r   test_no_manifest   s    z!TestManifestTest.test_no_manifestc                 C  s   |  d t|  kstdS )z<Check an empty MANIFEST.in includes only the standard files. N)r^   rf   re   r5   rg   r   r   r   test_empty_files   s    
z!TestManifestTest.test_empty_filesc                 C  s.   |  d ttddgB }||  ks*tdS )z,Include extra rst files in the project root.zinclude *.rstrN   rM   N)r^   rf   rb   re   r5   )r@   rc   r   r   r   test_include   s    
zTestManifestTest.test_includec                 C  s4   t }| d tt|dgB }||  ks0tdS )z0Include everything in app/ except the text fileszE
            include app/*
            exclude app/*.txt
            	app/c.rstNr   r^   rf   rb   re   r5   r@   mlrc   r   r   r   test_exclude   s    zTestManifestTest.test_excludec              	   C  sR   t }| d tt|d|d|d|d|d|dgB }||  ksNtdS )	zInclude with multiple patterns.zinclude app/*.txt app/static/*	app/a.txt	app/b.txtapp/static/app.jsapp/static/app.js.mapapp/static/app.cssapp/static/app.css.mapNrm   rn   r   r   r   test_include_multiple  s    
z&TestManifestTest.test_include_multiplec                 C  sF   t }| d tt|d|d|d|dgB }||  ksBtdS )(Include the whole app/static/ directory.zgraft app/staticrs   rt   ru   rv   Nrm   rn   r   r   r   
test_graft  s    
zTestManifestTest.test_graftc                 C  sF   t }| d tt|d|d|d|dgB }||  ksBtdS )rx   zgraft */staticrs   rt   ru   rv   Nrm   rn   r   r   r   test_graft_glob_syntax  s    
z'TestManifestTest.test_graft_glob_syntaxc                 C  s:   t }| d tt|d|dgB }||  ks6tdS )z'Exclude all *.map files in the project.zK
            graft app/static
            global-exclude *.map
            rs   ru   Nrm   rn   r   r   r   test_graft_global_exclude(  s    z*TestManifestTest.test_graft_global_excludec                 C  sD   t }| d ttdd|d|d|dgB }||  ks@tdS )z;Include all *.rst, *.js, and *.css files in the whole tree.z9
            global-include *.rst *.js *.css
            rM   rN   rl   rs   ru   Nrm   rn   r   r   r   test_global_include4  s    z$TestManifestTest.test_global_includec                 C  s@   t }| d tt|d|d|dgB }||  ks<tdS )z@Include all files in app/, except for the whole app/static/ dir.z@
            graft app
            prune app/static
            rq   rr   rl   Nrm   rn   r   r   r   test_graft_pruneE  s    z!TestManifestTest.test_graft_prune)rE   rF   rG   rB   r^   re   rh   rj   rk   rp   rw   ry   rz   r{   r|   r}   __classcell__r   r   r[   r   rH      s   'rH   c                   @  s   e Zd ZdZejeddkd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d Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'S )(TestFileListTestz
    A copy of the relevant bits of distutils/tests/test_filelist.py,
    to ensure setuptools' version of FileList keeps parity with distutils.
    SETUPTOOLS_USE_DISTUTILSstdlib)Zautousec                   s     fdd}| tjd| dS )z Account for stdlib compatibilityc              	     s.   t  }td|dd|||} j| d S )N	distutilsri   r   )r   exc_infologgingZ	LogRecordrecordsappend)Z_loggerlevelmsgargsexcZreccaplogr   r   _log\  s    z2TestFileListTest._compat_record_logs.<locals>._logr   N)setattrr   ZLog)r@   Zmonkeypatchr   r   r   r   r   _compat_record_logsX  s    z$TestFileListTest._compat_record_logsc                   s    fdd|j D S )Nc                   s   g | ]}|j  kr|qS r   )Zlevelno)r+   rlevelsr   r   
<listcomp>d  s     
 z0TestFileListTest.get_records.<locals>.<listcomp>)r   )r@   r   r   r   r   r   get_recordsc  s    zTestFileListTest.get_recordsc                 C  s"   |  |tjg kst|  d S r   )r   r   WARNr5   clearr@   r   r   r   r   assertNoWarningsf  s    z!TestFileListTest.assertNoWarningsc                 C  s<   t r|jstd n"t| |tjdks0t|	  d S )Nz'caplog checks may not work well in PyPyr   )
IS_PYPYr   pytestZxfaillenr   r   r   r5   r   r   r   r   r   assertWarningsj  s    
zTestFileListTest.assertWarningsc                 C  sD   |D ]:}t j| j|}t j|\}}t j|dd t| qd S )NT)exist_ok)r   rT   rU   r;   splitmakedirsr    )r@   rc   filedirnamebasenamer   r   r   
make_filesq  s
    zTestFileListTest.make_filesc                 C  s   t  }t}| ddddd|d|d|d|d	|d
|d|d|d|d|dg td}|dD ]}|svql|| qlddd|d|d|d|d|d|dg	}|  |j|kstd S )Nzfoo.tmpokZ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.txta6          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
        
)	r   r   r   r	   r   process_template_linesortrc   r5   )r@   	file_listro   ZMANIFEST_INlineZwantedr   r   r   test_process_template_linex  sL    z+TestFileListTest.test_process_template_linec                 C  sh   t  }|drtt  }ddg|_|ds2tt  }ddg|_|d |  |jdgksdtd S )N*.pya.pyzb.pyrP   )r   Zexclude_patternr5   rc   r   r@   r   r   r   r   test_exclude_pattern  s    


z%TestFileListTest.test_exclude_patternc                 C  s|   t  }| g  |drtt  }| ddg |ds@tt  }| ddg |d |  |jddgksxtd S )Nr   r   rQ   *)r   r   Zinclude_patternr5   r   rc   r   r   r   r   test_include_pattern  s    

z%TestFileListTest.test_include_patternc              	   C  sb   t  }dD ]R}z|| W n2 tk
r0   Y q
 tk
rN   dsJtdY q
X ds
tdq
d S )N)	ZincludeZexcludezglobal-includezglobal-excludezrecursive-includezrecursive-excludeZgraftZpruneZblargFzIncorrect error thrownzShould have thrown an error)r   r   r   	Exceptionr5   )r@   r   actionr   r   r   "test_process_template_line_invalid  s    z3TestFileListTest.test_process_template_line_invalidc                 C  s   | tj t}t }| dd|dg |d |  |jdgksLt	| 
| |d |  |jdgksxt	| | d S )Nr   rQ   d/c.pyzinclude *.pyzinclude *.rb	set_levelr   DEBUGr   r   r   r   r   rc   r5   r   r   r@   r   ro   r   r   r   r   rk     s    


zTestFileListTest.test_includec                 C  s   | tj t}t }dd|dg|_|d |  |jd|dgksNt| 	| |d |  |jd|dgkst| 
| d S )Nr   rQ   r   zexclude *.pyzexclude *.rbr   r   r   r   r   rc   r   r   r5   r   r   r   r   r   r   rp     s    


zTestFileListTest.test_excludec                 C  s   | tj t}t }| dd|dg |d |  |jd|dgksRt	| 
| |d |  |jd|dgkst	| | d S )Nr   rQ   r   zglobal-include *.pyzglobal-include *.rbr   r   r   r   r   r|     s    


z$TestFileListTest.test_global_includec                 C  s   | tj t}t }dd|dg|_|d |  |jdgksHt| 	| |d |  |jdgkstt| 
| d S )Nr   rQ   r   zglobal-exclude *.pyzglobal-exclude *.rbr   r   r   r   r   test_global_exclude$  s    


z$TestFileListTest.test_global_excludec                 C  s   | tj t}t }| d|d|d|dg |d |  |j|d|dgks`t	| 
| |d |  |j|d|dgkst	| | d S )Nr   d/b.pyd/c.txtd/d/e.pyzrecursive-include d *.pyzrecursive-include e *.pyr   r   r   r   r   test_recursive_include5  s    


z'TestFileListTest.test_recursive_includec                 C  s   | tj t}t }d|d|d|dg|_|d |  |jd|dgksXt| 	| |d |  |jd|dgkst| 
| d S )Nr   r   r   r   zrecursive-exclude d *.pyzrecursive-exclude e *.pyr   r   r   r   r   test_recursive_excludeF  s    


z'TestFileListTest.test_recursive_excludec                 C  s   | tj t}t }| d|d|d|dg |d |  |j|d|dgks`t	| 
| |d |  |j|d|dgkst	| | d S )Nr   r   r   f/f.pyzgraft dzgraft er   r   r   r   r   ry   W  s    


zTestFileListTest.test_graftc                 C  s   | tj t}t }d|d|d|dg|_|d |  |jd|dgksXt| 	| |d |  |jd|dgkst| 
| d S )Nr   r   r   r   zprune dzprune er   r   r   r   r   
test_pruneh  s    


zTestFileListTest.test_pruneN)rE   rF   rG   __doc__r   fixturer   getenvr   r   r   r   r   r   r   r   r   rk   rp   r|   r   r   r   ry   r   r   r   r   r   r   R  s&   

?r   )1r   Z
__future__r   
contextlibr   rC   r   r:   r(   r   r   r   r   Zdistutils.errorsr   Zsetuptools.command.egg_infor   r   r   Zsetuptools.distr   Zsetuptools.tests.textwrapr	   r   builtin_module_namesr   r   r_   rW   contextmanagerr   r    	frozensetr/   rf   r%   __annotations__chainfrom_iterableZmatch_paramsr   r1   Zmismatch_paramsr2   r7   r8   r9   rH   r   r   r   r   r   <module>   s   


	
3



 %