U
    uiH                     @  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ZddlmZmZmZ ddlmZ ddlmZ ddlmZ ddlm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)FileListegg_infotranslate_pattern)Distribution)DALS)log)DistutilsTemplateErrorZ__pypy__c                 C  s   |  dtjS )z"Converts '/' in a string to os.sep/)replaceossep)s r   B/tmp/pip-unpacked-wheel-9osl9suo/setuptools/tests/test_manifest.pymake_local_path   s    r   appz0.0)nameversion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foo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patternmatches
mismatchesr   r   r   	<genexpr>   s   r1   )paramsc                 C  s   t t| jS r   mapr   paramrequestr   r   r   pattern_match   s    r8   c                 c  s$   | ]\}}}t t||V  qd S r   r(   r,   r   r   r   r1      s   c                 C  s   t t| jS r   r3   r6   r   r   r   pattern_mismatch   s    r9   c                 C  s   | \}}t ||std S r   r   matchAssertionError)r8   r.   targetr   r   r   test_translated_pattern_match   s    r>   c                 C  s   | \}}t ||rtd S r   r:   )r9   r.   r=   r   r   r    test_translated_pattern_mismatch   s    r?   c                   @  s   e Zd Zdd Zdd ZdS )TempDirTestCasec                 C  s$   t  | _t | _t| j d S r   )tempfile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   rF   rE   shutilrmtreerC   rG   r   r   r   teardown_method   s    zTempDirTestCase.teardown_methodN)__name__
__module____qualname__rJ   rM   r   r   r   r   r@      s   r@   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)superrJ   r   r   pathjoinrC   writeSETUP_PYr   r!   mkdir)rH   rI   ffnameZtest_pkgr[   	__class__r   r   rJ      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#   rR   rS   rT   N)r   r]   r^   rC   r   r_   r   )rH   contentsmanifestrb   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   ensure_finalizedrunsetfilelistfiles)rH   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_filesrm   rr   r<   rH   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)rh   rs   rr   r<   rt   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 *.rstrW   rV   N)rh   rs   rm   rr   r<   )rH   ro   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   rh   rs   rm   rr   r<   rH   mlro   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.mapNrz   r{   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/staticr   r   r   r   Nrz   r{   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 )r   zgraft */staticr   r   r   r   Nrz   r{   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
            r   r   Nrz   r{   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
            rV   rW   ry   r   r   Nrz   r{   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
            r~   r   ry   Nrz   r{   r   r   r   test_graft_pruneE  s    z!TestManifestTest.test_graft_prune)rN   rO   rP   rJ   rh   rr   ru   rw   rx   r}   r   r   r   r   r   r   __classcell__r   r   rd   r   rQ      s   'rQ   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.
    Z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	distutilsrv   r   )r   exc_infologging	LogRecordrecordsappend)Z_loggerlevelmsgargsexcZreccaplogr   r   _log\  s    z2TestFileListTest._compat_record_logs.<locals>._logr   N)setattrr   Log)rH   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   )levelno)r-   rlevelsr   r   
<listcomp>d  s     
 z0TestFileListTest.get_records.<locals>.<listcomp>)r   )rH   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   WARNr<   clearrH   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   r<   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   r]   r^   rC   splitmakedirsr!   )rH   ro   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sortro   r<   )rH   	file_listr|   ZMANIFEST_INline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.pyrY   )r   Zexclude_patternr<   ro   r   rH   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   rZ   *)r   r   Zinclude_patternr<   r   ro   r   r   r   r   test_include_pattern  s    

z%TestFileListTest.test_include_patternc              
   C  s4   t  }dD ]$}tt || W 5 Q R X q
d S )N)	includeexcludezglobal-includezglobal-excludezrecursive-includezrecursive-excludeZgraftZpruneZblarg)r   r   Zraisesr	   r   )rH   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   rZ   d/c.pyzinclude *.pyzinclude *.rb	set_levelr   DEBUGr   r   r   r   r   ro   r<   r   r   rH   r   r|   r   r   r   r   rx     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   rZ   r   zexclude *.pyzexclude *.rbr   r   r   r   r   ro   r   r   r<   r   r   r   r   r   r   r}     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   rZ   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   rZ   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_include/  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_exclude@  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   r   Q  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_pruneb  s    


zTestFileListTest.test_pruneN)rN   rO   rP   __doc__r   fixturer   getenvr   r   r   r   r   r   r   r   r   rx   r}   r   r   r   r   r   r   r   r   r   r   r   R  s&   

?r   )1r   
__future__r   
contextlibr   r*   r   r   rK   r   rA   r   Zsetuptools.command.egg_infor   r   r   Zsetuptools.distr   Zsetuptools.tests.textwrapr   r   r   distutils.errorsr	   builtin_module_namesr   r   ri   r`   contextmanagerr   r!   	frozensetr4   rs   r'   __annotations__chainfrom_iterableZmatch_paramsr   r8   Zmismatch_paramsr9   r>   r?   r@   rQ   r   r   r   r   r   <module>   s   


	
3



 %