o
    LK&hH                     @  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)DistutilsTemplateError__pypy__c                 C  s   |  dtjS )z"Converts '/' in a string to os.sep/)replaceossep)s r   Q/var/www/html/venv/lib/python3.10/site-packages/setuptools/tests/test_manifest.pymake_local_path   s   r   appz0.0)nameversion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)
old_stdout
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foobar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)preopostprenpostpreepostprepost
preonepostzhello[!one]worldhelloxworldhelloyworld)hellooworld
helloworldhellooneworldz
[]one].txt)zo.txtz].txtze.txtzone].txtzfoo[!]one]barfooybar)zfoo]barfooobar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>   
    
rD   )paramsc                 C     t t| jS r   mapr   paramrequestr   r   r   pattern_match      rM   c                 c  s&    | ]\}}}t t||V  qd S r   r;   r?   r   r   r   rD      rE   c                 C  rG   r   rH   rK   r   r   r   pattern_mismatch   rN   rO   c                 C  s   | \}}t ||sJ d S r   r   match)rM   rA   targetr   r   r   test_translated_pattern_match      rS   c                 C  s   | \}}t ||rJ d S r   rP   )rO   rA   rR   r   r   r    test_translated_pattern_mismatch   rT   rU   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   r\   r[   shutilrmtreerY   r]   r   r   r   teardown_method   s   zTempDirTestCase.teardown_methodN)__name__
__module____qualname__r`   rc   r   r   r   r   rV      s    rV   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)superr`   r!   r   pathjoinrY   writeSETUP_PYr"   r$   mkdir)r^   r_   ffnametest_pkgrq   	__class__r   r   r`      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&   rh   ri   rj   N)r   rs   rt   rY   r!   ru   r   )r^   contentsmanifestrx   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)r^   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_filesr   r   r^   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)r   r   r   r   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 *.rstrm   rl   N)r   r   r   r   )r^   r   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   r   r   r   r   r^   mlr   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.mapNr   r   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   Nr   r   r   r   r   
test_graft     
zTestManifestTest.test_graftc                 C  r   )r   zgraft */staticr   r   r   r   Nr   r   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   Nr   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 J dS )z;Include all *.rst, *.js, and *.css files in the whole tree.z9
            global-include *.rst *.js *.css
            rl   rm   r   r   r   Nr   r   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
            r   r   r   Nr   r   r   r   r   test_graft_pruneB  s   z!TestManifestTest.test_graft_prune)rd   re   rf   r`   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   r{   r   rg      s    'rg   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)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	distutilsr   r   )r   exc_infologging	LogRecordrecordsappend)_loggerlevelmsgargsexcreccaplogr   r   _logY  s   z2TestFileListTest._compat_record_logs.<locals>._logr   N)setattrr   Log)r^   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   )levelno)r@   rlevelsr   r   
<listcomp>a  s    z0TestFileListTest.get_records.<locals>.<listcomp>)r   )r^   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r^   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   pytest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   rs   rt   rY   splitmakedirsr$   )r^   r   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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.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sortr   )r^   	file_listr   MANIFEST_INline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.pyro   )r   exclude_patternr   r   r^   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   rp   *)r   r   include_patternr   r   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)	includeexcludezglobal-includezglobal-excludezrecursive-includezrecursive-excludegraftpruneblarg)r   r   raisesr	   r   )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s&J | 	| |d |  |jdgks<J | 
| d S )Nr   rp   d/c.pyzinclude *.pyzinclude *.rb	set_levelr   DEBUGr   r   r   r   r   r   r   r   r^   r   r   r   r   r   r   r     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   rp   r   zexclude *.pyzexclude *.rb
r   r   r   r   r   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s)J | 	| |d |  |jd|dgksBJ | 
| d S )Nr   rp   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   rp   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)rd   re   rf   __doc__r   fixturer   getenvr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   O  s(    

?r   )1r   
__future__r   
contextlibr   r=   r   r   ra   r   rW   r   setuptools.command.egg_infor   r   r   setuptools.distr   setuptools.tests.textwrapr   r   r   distutils.errorsr	   builtin_module_namesr   r   r   rv   contextmanagerr   r$   	frozensetrI   r   r:   __annotations__chainfrom_iterablematch_paramsr   rM   mismatch_paramsrO   rS   rU   rV   rg   r   r   r   r   r   <module>   s    

	
.



 %