o
    5hH                     @  sH  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v Zd
d ZdddgdZdedZejdd Zdd Ze e!eg dZ"ddgddgfddgg dfdddgdgfdg d d!gfd"d#gg fd$d%gd&gfd'g d(d)gfd*d+d,gd-gfd.g d/g fd0g d1d2d3gfd4d5d6gg d7fd8g d9d:gfd;d<gg d=fgZ#d>e$d?< 	 ej%&d@dA e#D Z'ej(e'dBdCdD Z)ej%&dEdA e#D Z*ej(e*dBdFdG Z+dHdI Z,dJdK Z-G dLdM dMZ.G dNdO dOe.Z/G dPdQ dQe.Z0dS )Rz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   >lib/python3.10/site-packages/setuptools/tests/test_manifest.pymake_local_path   s   r   appz0.0)nameversionZpackagesz&from setuptools import setup

setup(**z)
c               	   c  sR    t jt j} }t t t _t _zd V  W | |t _t _d S | |t _t _w 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   touch6   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__.pyfooZbarZfoobarfoo/bar)zfoo/bar/bazz	./foo/barr$   z*.txtzfoo.txtzbar.txtzfoo/foo.txtz	dir/*.txt)z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/**/bar)zfoo/bing/barzfoo/bing/bang/barr%   zfoo/abarzfoo/**zfoo/bar/bing.pyzfoo/xz/foo/xz**)xzabc/xyzz@nythingzpre[one]post)ZpreopostZprenpostZpreepostZprepostZ
preonepostzhello[!one]worldZhelloxworldZhelloyworld)ZhellooworldZ
helloworldZhellooneworldz
[]one].txt)zo.txtz].txtze.txtzone].txtzfoo[!]one]barZfooybar)z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matchesZ
mismatchesr   r   r   	<genexpr>   
    
r0   )paramsc                 C     t t| jS r   mapr   ZparamZrequestr   r   r   pattern_match      r7   c                 c  s&    | ]\}}}t t||V  qd S r   r(   r,   r   r   r   r0      r1   c                 C  r3   r   r4   r6   r   r   r   pattern_mismatch   r8   r9   c                 C  s   | \}}t ||sJ d S r   r   match)r7   r.   targetr   r   r   test_translated_pattern_match      r=   c                 C  s   | \}}t ||rJ d S r   r:   )r9   r.   r<   r   r   r    test_translated_pattern_mismatch   r>   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   )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   rE   rD   shutilrmtreerB   rF   r   r   r   teardown_method   s   zTempDirTestCase.teardown_methodN)__name__
__module____qualname__rI   rL   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|| q;tj|d}t| d	D ]}t
tj|| qUd 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)superrI   r   r   pathjoinrB   writeSETUP_PYr   r    mkdir)rG   rH   ffnameZtest_pkgrZ   	__class__r   r   rI      s    


zTestManifestTest.setup_methodc                 C  sR   t j| jd}t|ddd}|t| W d   dS 1 s"w   Y  dS )zWrite a MANIFEST.in.r"   rQ   rR   rS   N)r   r\   r]   rB   r   r^   r   )rG   contentsZmanifestra   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)rG   Zdistcmdr   r   r   	get_files   s   zTestManifestTest.get_filesc                 C  s   t tdg |  ksJ dS )z=Check a missing MANIFEST.in includes only the standard files.r"   N)default_filesrj   rm   rG   r   r   r   test_no_manifest   s   z!TestManifestTest.test_no_manifestc                 C  s   |  d t|  ksJ dS )z<Check an empty MANIFEST.in includes only the standard files. N)rf   rn   rm   ro   r   r   r   test_empty_files   s   
z!TestManifestTest.test_empty_filesc                 C  s.   |  d ttddgB }||  ksJ dS )z,Include extra rst files in the project root.zinclude *.rstrV   rU   N)rf   rn   rj   rm   )rG   rk   r   r   r   test_include   s   
zTestManifestTest.test_includec                 C  s4   t }| d tt|dgB }||  ksJ dS )z0Include everything in app/ except the text fileszE
            include app/*
            exclude app/*.txt
            	app/c.rstNr   rf   rn   rj   rm   rG   mlrk   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s'J 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.mapNru   rv   r   r   r   test_include_multiple   s   
z&TestManifestTest.test_include_multiplec                 C  F   t }| d tt|d|d|d|dgB }||  ks!J dS )(Include the whole app/static/ directory.zgraft app/staticr{   r|   r}   r~   Nru   rv   r   r   r   
test_graft     
zTestManifestTest.test_graftc                 C  r   )r   zgraft */staticr{   r|   r}   r~   Nru   rv   r   r   r   test_graft_glob_syntax  r   z'TestManifestTest.test_graft_glob_syntaxc                 C  s:   t }| d tt|d|dgB }||  ksJ dS )z'Exclude all *.map files in the project.zK
            graft app/static
            global-exclude *.map
            r{   r}   Nru   rv   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 J dS )z;Include all *.rst, *.js, and *.css files in the whole tree.z9
            global-include *.rst *.js *.css
            rU   rV   rt   r{   r}   Nru   rv   r   r   r   test_global_include1  s   z$TestManifestTest.test_global_includec                 C  s@   t }| d tt|d|d|dgB }||  ksJ dS )z@Include all files in app/, except for the whole app/static/ dir.z@
            graft app
            prune app/static
            ry   rz   rt   Nru   rv   r   r   r   test_graft_pruneB  s   z!TestManifestTest.test_graft_prune)rM   rN   rO   rI   rf   rm   rp   rr   rs   rx   r   r   r   r   r   r   __classcell__r   r   rc   r   rP      s    'rP   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	distutilsrq   r   )r   exc_infologgingZ	LogRecordrecordsappend)Z_loggerlevelmsgargsexcZreccaplogr   r   _logY  s   z2TestFileListTest._compat_record_logs.<locals>._logr   N)setattrr   ZLog)rG   Zmonkeypatchr   r   r   r   r   _compat_record_logsU  s   z$TestFileListTest._compat_record_logsc                   s    fdd|j D S )Nc                   s   g | ]	}|j  v r|qS r   )Zlevelno)r-   rlevelsr   r   
<listcomp>a  s    z0TestFileListTest.get_records.<locals>.<listcomp>)r   )rG   r   r   r   r   r   get_records`  s   zTestFileListTest.get_recordsc                 C  s"   |  |tjg ksJ |  d S r   )r   r   WARNclearrG   r   r   r   r   assertNoWarningsc  s   z!TestFileListTest.assertNoWarningsc                 C  s>   t r|jstd d S t| |tjdksJ |  d S )Nz'caplog checks may not work well in PyPyr   )	IS_PYPYr   pytestZxfaillenr   r   r   r   r   r   r   r   assertWarningsg  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]   rB   splitmakedirsr    )rG   rk   filedirname	_basenamer   r   r   
make_filesn  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 ]
}|s;q6|| q6ddd|d|d|d|d|d|dg	}|  |j|kscJ 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sortrk   )rG   	file_listrw   ZMANIFEST_INlineZwantedr   r   r   test_process_template_lineu  sL   z+TestFileListTest.test_process_template_linec                 C  sh   t  }|dr
J t  }ddg|_|dsJ t  }ddg|_|d |  |jdgks2J d S )N*.pya.pyzb.pyrX   )r   Zexclude_patternrk   r   rG   r   r   r   r   test_exclude_pattern  s   


z%TestFileListTest.test_exclude_patternc                 C  s|   t  }| g  |drJ t  }| ddg |ds J t  }| ddg |d |  |jddgks<J d S )Nr   r   rY   *)r   r   Zinclude_patternr   rk   r   r   r   r   test_include_pattern  s   

z%TestFileListTest.test_include_patternc              	   C  sH   t  }dD ]}tt || W d    n1 sw   Y  qd S )N)	ZincludeZexcludezglobal-includezglobal-excludezrecursive-includezrecursive-excludeZgraftZpruneZblarg)r   r   Zraisesr	   r   )rG   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s&J | 	| |d |  |jdgks<J | 
| d S )Nr   rY   d/c.pyzinclude *.pyzinclude *.rb	set_levelr   DEBUGr   r   r   r   r   rk   r   r   rG   r   rw   r   r   r   r   rs     s   


zTestFileListTest.test_includec                 C  s   | tj t}t }dd|dg|_|d |  |jd|dgks'J | | |d |  |jd|dgks@J | 	| d S )Nr   rY   r   zexclude *.pyzexclude *.rb
r   r   r   r   r   rk   r   r   r   r   r   r   r   r   rx     s   


zTestFileListTest.test_excludec                 C  s   | tj t}t }| dd|dg |d |  |jd|dgks)J | 	| |d |  |jd|dgksBJ | 
| d S )Nr   rY   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s$J | | |d |  |jdgks:J | 	| d S )Nr   rY   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s0J | 	| |d |  |j|d|dgksKJ | 
| 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,     


z'TestFileListTest.test_recursive_includec                 C  s   | tj t}t }d|d|d|dg|_|d |  |jd|dgks,J | | |d |  |jd|dgksEJ | 	| d S )Nr   r   r   r   zrecursive-exclude d *.pyzrecursive-exclude e *.pyr   r   r   r   r   test_recursive_exclude=     


z'TestFileListTest.test_recursive_excludec                 C  s   | tj t}t }| d|d|d|dg |d |  |j|d|dgks0J | 	| |d |  |j|d|dgksKJ | 
| d S )Nr   r   r   f/f.pyzgraft dzgraft er   r   r   r   r   r   N  r   zTestFileListTest.test_graftc                 C  s   | tj t}t }d|d|d|dg|_|d |  |jd|dgks,J | | |d |  |jd|dgksEJ | 	| d S )Nr   r   r   r   zprune dzprune er   r   r   r   r   
test_prune_  r   zTestFileListTest.test_pruneN)rM   rN   rO   __doc__r   fixturer   getenvr   r   r   r   r   r   r   r   r   rs   rx   r   r   r   r   r   r   r   r   r   r   r   O  s(    

?r   )1r   Z
__future__r   
contextlibr   r*   r   r   rJ   r   rA   r   Zsetuptools.command.egg_infor   r   r   Zsetuptools.distr   Zsetuptools.tests.textwrapr   r   r   Zdistutils.errorsr	   builtin_module_namesr   r   rg   r_   contextmanagerr   r    	frozensetr5   rn   r'   __annotations__chainfrom_iterableZmatch_paramsr   r7   Zmismatch_paramsr9   r=   r?   r@   rP   r   r   r   r   r   <module>   s    

	
.



 %