a
    6RhH                     @  sF  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   T/opt/python-3.9.24/usr/lib/python3.9/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 _n| | t _t _0 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   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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matches
mismatchesr   r   r   	<genexpr>   s   r3   )paramsc                 C  s   t t| jS r   mapr   paramrequestr   r   r   pattern_match   s    r:   c                 c  s$   | ]\}}}t t||V  qd S r   r*   r.   r   r   r   r3      s   c                 C  s   t t| jS r   r5   r8   r   r   r   pattern_mismatch   s    r;   c                 C  s   | \}}t ||sJ d S r   r   match)r:   r0   targetr   r   r   test_translated_pattern_match   s    r?   c                 C  s   | \}}t ||rJ d S r   r<   )r;   r0   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   rG   rF   shutilrmtreerD   rH   r   r   r   teardown_method   s    zTempDirTestCase.teardown_methodN)__name__
__module____qualname__rK   rN   r   r   r   r   rA      s   rA   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)superrK   r   r   pathjoinrD   writeSETUP_PYr   r!   mkdir)rI   rJ   ffnameZtest_pkgr\   	__class__r   r   rK      s    


zTestManifestTest.setup_methodc                 C  sP   t j| jd}t|ddd}|t| W d   n1 sB0    Y  dS )zWrite a MANIFEST.in.r#   rS   rT   rU   N)r   r^   r_   rD   r   r`   r   )rI   contentsmanifestrc   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)rI   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_filesrn   rs   rI   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)ri   rt   rs   ru   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 *.rstrX   rW   N)ri   rt   rn   rs   )rI   rp   r   r   r   test_include   s    
zTestManifestTest.test_includec                 C  s4   t }| d tt|dgB }||  ks0J dS )z0Include everything in app/ except the text fileszE
            include app/*
            exclude app/*.txt
            	app/c.rstNr   ri   rt   rn   rs   rI   mlrp   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sNJ 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  sF   t }| d tt|d|d|d|dgB }||  ksBJ dS )(Include the whole app/static/ directory.zgraft app/staticr   r   r   r   Nr{   r|   r   r   r   
test_graft  s    
zTestManifestTest.test_graftc                 C  sF   t }| d tt|d|d|d|dgB }||  ksBJ dS )r   zgraft */staticr   r   r   r   Nr{   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s6J 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
            rW   rX   rz   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   rz   Nr{   r|   r   r   r   test_graft_pruneB  s    z!TestManifestTest.test_graft_prune)rO   rP   rQ   rK   ri   rs   rv   rx   ry   r~   r   r   r   r   r   r   __classcell__r   r   re   r   rR      s   'rR   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	distutilsrw   r   )r   exc_infologging	LogRecordrecordsappend)Z_loggerlevelmsgargsexcZreccaplogr   r   _logY  s    z2TestFileListTest._compat_record_logs.<locals>._logr   N)setattrr   Log)rI   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   )levelno)r/   rlevelsr   r   
<listcomp>a      z0TestFileListTest.get_records.<locals>.<listcomp>)r   )rI   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rI   r   r   r   r   assertNoWarningsc  s    z!TestFileListTest.assertNoWarningsc                 C  s<   t r|jstd n"t| |tjdks0J |  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_   rD   splitmakedirsr!   )rI   rp   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 ]}|svql|| qlddd|d|d|d|d|d|dg	}|  |j|ksJ 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sortrp   )rI   	file_listr}   Z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s2J t  }ddg|_|d |  |jdgksdJ d S )N*.pya.pyzb.pyrZ   )r   Zexclude_patternrp   r   rI   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sxJ d S )Nr   r   r[   *)r   r   Zinclude_patternr   rp   r   r   r   r   test_include_pattern  s    

z%TestFileListTest.test_include_patternc              	   C  sH   t  }dD ]8}tt || W d    q
1 s80    Y  q
d S )N)	includeexcludezglobal-includezglobal-excludezrecursive-includezrecursive-excludeZgraftZpruneZblarg)r   r   Zraisesr	   r   )rI   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sLJ | 	| |d |  |jdgksxJ | 
| d S )Nr   r[   d/c.pyzinclude *.pyzinclude *.rb	set_levelr   DEBUGr   r   r   r   r   rp   r   r   rI   r   r}   r   r   r   r   ry     s    


zTestFileListTest.test_includec                 C  s   | tj t}t }dd|dg|_|d |  |jd|dgksNJ | | |d |  |jd|dgksJ | 	| d S )Nr   r[   r   zexclude *.pyzexclude *.rb
r   r   r   r   r   rp   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sRJ | 	| |d |  |jd|dgksJ | 
| d S )Nr   r[   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sHJ | | |d |  |jdgkstJ | 	| d S )Nr   r[   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`J | 	| |d |  |j|d|dgksJ | 
| 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sXJ | | |d |  |jd|dgksJ | 	| 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`J | 	| |d |  |j|d|dgksJ | 
| d S )Nr   r   r   f/f.pyzgraft dzgraft er   r   r   r   r   r   N  s    


zTestFileListTest.test_graftc                 C  s   | tj t}t }d|d|d|dg|_|d |  |jd|dgksXJ | | |d |  |jd|dgksJ | 	| d S )Nr   r   r   r   zprune dzprune er   r   r   r   r   
test_prune_  s    


zTestFileListTest.test_pruneN)rO   rP   rQ   __doc__r   fixturer   getenvr   r   r   r   r   r   r   r   r   ry   r~   r   r   r   r   r   r   r   r   r   r   r   O  s&   

?r   )1r   
__future__r   
contextlibr   r,   r   r   rL   r   rB   r   Zsetuptools.command.egg_infor   r   r   Zsetuptools.distr   Zsetuptools.tests.textwrapr   r   r   distutils.errorsr	   builtin_module_namesr   r   rj   ra   contextmanagerr   r!   	frozensetr6   rt   r)   __annotations__chainfrom_iterableZmatch_paramsr   r:   Zmismatch_paramsr;   r?   r@   rA   rR   r   r   r   r   r   <module>   s   

	
3



 %