o
    LK&hz                     @   s   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Zd dlm	Z	m
Z
mZmZmZmZmZmZmZ dd ZG dd dejZej	jZG dd	 d	ZG d
d dZG dd dZG dd dZG dd dZG dd dZdS )    N)SpecifierSet)	Distribution
EntryPointRequirementVersionConflict
WorkingSetparse_requirementsparse_version	safe_namesafe_versionc                 C   s"   t | \}}t|d t||S )z$s -> (s0,s1), (s1,s2), (s2, s3), ...N)	itertoolsteenextzip)iterableab r   U/var/www/html/venv/lib/python3.10/site-packages/pkg_resources/tests/test_resources.pypairwise   s   

r   c                   @   s8   e Zd ZdZdddZdefddZdd	 Zd
d ZdS )MetadatazAMock object to return metadata as if from an on-disk distributionreturnNc                 G   s   t || _d S N)dictmetadata)selfpairsr   r   r   __init__#   s   zMetadata.__init__c                 C   s
   || j v S r   r   r   namer   r   r   has_metadata&      
zMetadata.has_metadatac                 C   s
   | j | S r   r   r   r   r   r   get_metadata)   r"   zMetadata.get_metadatac                 C   s   t | |S r   )pkg_resourcesyield_linesr#   r   r   r   r   get_metadata_lines,   s   zMetadata.get_metadata_lines)r   N)	__name__
__module____qualname____doc__r   boolr!   r#   r&   r   r   r   r   r       s    
r   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zd2ddZ	dd Z
ejjeed ddZdd Zedd Ze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ejjejd+d, d-korejjd.kd/dd0d1 Z d+S )3
TestDistroc                 C   s  t jg d d d}t|g ksJ |d g ksJ |td |td |td |d s3J t|dgks<J g d}dd	 |d D |ksMJ ||d d
  dd	 |d D ddgkseJ |td dd	 |d D g dks{J tg }td}td}td\}|||j	dksJ || |||j	dksJ tg }|| || t
t ||| W d    n1 sw   Y  tg }|| || || |||j	dksJ d S )N)platformpythonFooPkgFooPkg-1.3_1.eggzFooPkg-1.4-py2.4-win32.eggFooPkg-1.2-py2.4.eggfoopkg)1.41.3-11.2c                 S      g | ]}|j qS r   version.0distr   r   r   
<listcomp>D       z-TestDistro.testCollection.<locals>.<listcomp>   c                 S   r6   r   r7   r9   r   r   r   r<   H   r=   r3   r5   zFooPkg-1.9.eggc                 S   r6   r   r7   r9   r   r   r   r<   L   r=   )1.9r3   r5   zFooPkg>=1.3r?   )r$   Environmentlistadddist_from_fnremover   r   
best_matchr8   pytestraisesr   )r   adexpectedwsfoo12foo14reqr   r   r   testCollection4   s@   






zTestDistro.testCollectionc                 C   s\   |j dksJ |jdksJ |jdksJ |jdksJ |jdks#J |jtdks,J d S )Nr/   r2   z	1.3.post12.4win32r4   )project_namekeyr8   
py_versionr-   parsed_versionr	   r   dr   r   r   checkFooPkgg   s   zTestDistro.checkFooPkgc                 C   sV   t dddddd}| | t d}|jtjj dtjj ks"J |jd u s)J d S )N
/some/pathr/   r4   rO   rP   )rQ   r8   rS   r-   .)r   rW   rS   sysversion_infomajorminorr-   rU   r   r   r   testDistroBasicso   s   
 zTestDistro.testDistroBasicsc                 C   s(   t d}| | t d}| | d S )Nz FooPkg-1.3.post1-py2.4-win32.eggz%FooPkg-1.3.post1-py2.4-win32.egg-info)rC   rW   rU   r   r   r   testDistroParse}   s   
zTestDistro.testDistroParsec                 C   s$   t ddddtdd}| | d S )NrX   r/   rO   rP   )zPKG-INFOz%Metadata-Version: 1.0
Version: 1.3-1
)rQ   rS   r-   r   )r   r   rW   rU   r   r   r   testDistroMetadata   s   zTestDistro.testDistroMetadatac                 C   s   t dtd|fdS )Nz/foodepends.txtr   )r   r   )r   txtr   r   r   distRequires   s   zTestDistro.distRequiresr   c                 C   s"   t ||t t|ksJ d S r   )rA   requiresr   )r   r;   rb   extrasr   r   r   checkRequires   s   "zTestDistro.checkRequiresc                 C   s    dD ]}|  | || qd S )N)Twisted>=1.5zTwisted>=1.5
ZConfig>=2.0)rf   rc   )r   vr   r   r   testDistroDependsSimple   s   z"TestDistro.testDistroDependsSimple__dir__z8object.__dir__ necessary for self.__dir__ implementationreasonc                 C   s   t  }t| d S r   )r$   r   dirrU   r   r   r   test_distribution_dir      z TestDistro.test_distribution_dirc                 C   sT   t  }| }d|vsJ d |j_| }t|t|d ks"J d|v s(J d S )N	test_attrr>   )r$   r   rj   	_providerrp   lenr   rV   beforeafterr   r   r   +test_distribution_dir_includes_provider_dir   s   z6TestDistro.test_distribution_dir_includes_provider_dirc                 C   sP   t  }| }d|vsJ d |j_| }t|t|ks J d|vs&J d S )N
_test_attr)r$   r   rj   rq   rw   rr   rs   r   r   r   =test_distribution_dir_ignores_provider_dir_leading_underscore   s   zHTestDistro.test_distribution_dir_ignores_provider_dir_leading_underscorec           	      C   s  t g }tg }t|g |g ksJ tt j |td| W d    n1 s.w   Y  t	j
dtdd}|| |t	
d tdD ]}t|td|}||gks`J tt|j| qMtt |td| W d    n1 sw   Y  tg }tt j |td| W d    n1 sw   Y  t	j
d	td
d}|| t|td|||gksJ tt}|td| W d    n1 sw   Y  d}|j |ksJ d S )NFoo/foo_dir/Foo-1.2.egg)ra   z[bar]
Baz>=2.0r   zFoo-0.9.egg   zFoo==0.9zFoo[bar]z/foo_dir/Baz-2.1.egg)ra   ry   zFoo==1.2
Foo!=1.2z-Foo 0.9 is installed but Foo==1.2 is required)r$   r@   r   rA   resolverF   rG   DistributionNotFoundr   r   from_filenamer   rB   rangemapr   valuereport)	r   rH   rJ   ry   itargetsBazvcmsgr   r   r   testResolve   sB   


 zTestDistro.testResolvec                 C   s6   t g }tg }|td|}t|g ksJ dS )z5Environment markers are evaluated at resolution time.zFoo;python_version<'2'N)r$   r@   r   r|   r   rA   )r   rH   rJ   resr   r   r   +test_environment_marker_evaluation_negative   s   
z6TestDistro.test_environment_marker_evaluation_negativec                 C   sL   t g }tg }td}|| |td|}t||gks$J d S )N/foo_dir/Foo-1.2.dist-infozFoo;python_version>='2')	r$   r@   r   r   r~   rB   r|   r   rA   )r   rH   rJ   ry   r   r   r   r   +test_environment_marker_evaluation_positive   s   


z6TestDistro.test_environment_marker_evaluation_positivec                 C   sh   t d\}t d\}t||ji}||sJ t d\}t d\}t||ji}||s2J dS )zy
        If one package foo requires bar without any extras,
        markers should pass for bar without extras.
        foozbar;python_version>='2'zfoo[]N)r   r$   
_ReqExtrasre   markers_pass)r   
parent_reqrM   
req_extrasr   r   r   )test_environment_marker_evaluation_called   s   



z4TestDistro.test_environment_marker_evaluation_calledc                 C      t g }tg }tjdtdd}|| t|t	d||gks&J td}|| t|t	d|}|||gksBJ dS )8Extras are also evaluated as markers at resolution time.r   )METADATAz5Provides-Extra: baz
Requires-Dist: quux; extra=='baz'r   ry   /foo_dir/quux-1.0.dist-infozFoo[baz]N
r$   r@   r   r   r~   r   rB   rA   r|   r   r   rH   rJ   ry   quuxr   r   r   r   "test_marker_evaluation_with_extras   s   



z-TestDistro.test_marker_evaluation_with_extrasc                 C   r   )r   r   )r   zIProvides-Extra: baz-lightyear
Requires-Dist: quux; extra=='baz-lightyear'r   ry   r   zFoo[baz-lightyear]Nr   r   r   r   r   ,test_marker_evaluation_with_extras_normlized  s   



z7TestDistro.test_marker_evaluation_with_extras_normlizedc                 C   s   t g }tg }tjdtdd}|| td}|| td}|| t|t	d|}t
||||gks@J d S )Nr   )r   zlProvides-Extra: baz
Requires-Dist: quux; extra=='baz'
Provides-Extra: bar
Requires-Dist: fred; extra=='bar'
r   r   z/foo_dir/fred-0.1.dist-infozFoo[baz,bar])r$   r@   r   r   r~   r   rB   rA   r|   r   sorted)r   rH   rJ   ry   r   fredr   r   r   r   +test_marker_evaluation_with_multiple_extras!  s   






z6TestDistro.test_marker_evaluation_with_multiple_extrasc           	      C   s   t g }tg }tjdtdd}tjdtdd}tjdtdd}td}||||fD ]}|| q/t|t	d	|}|||||gksKJ d S )
Nz/foo_dir/a-0.2.dist-info)r   zRequires-Dist: c[a]r   z/foo_dir/b-0.3.dist-info)r   zRequires-Dist: c[b]z/foo_dir/c-1.0.dist-info)r   z]Provides-Extra: a
Requires-Dist: b;extra=='a'
Provides-Extra: b
Requires-Dist: foo;extra=='b'z/foo_dir/foo-0.1.dist-infor   r   )	r   rH   rJ   r   r   cr   r;   r   r   r   r   'test_marker_evaluation_with_extras_loop6  s&   


z2TestDistro.test_marker_evaluation_with_extras_loopN   )r{      finalz/https://github.com/python/cpython/issues/103632c                 C   s   |  d}| |d | |d dg | |d dg | |d ddg | |d ddg ttj |d	g W d    d S 1 sMw   Y  d S )
Nz
            Twisted>=1.5
            [docgen]
            ZConfig>=2.0
            docutils>=0.3
            [fastcgi]
            fcgiapp>=0.1rg   z'Twisted>=1.5 ZConfig>=2.0 docutils>=0.3docgenzTwisted>=1.5 fcgiapp>=0.1fastcgiz4Twisted>=1.5 ZConfig>=2.0 docutils>=0.3 fcgiapp>=0.1z4Twisted>=1.5 fcgiapp>=0.1 ZConfig>=2.0 docutils>=0.3r   )rc   rf   splitrF   rG   r$   UnknownExtrard   rU   r   r   r   testDistroDependsOptionsQ  s*   	"z#TestDistro.testDistroDependsOptions)r   )!r'   r(   r)   rN   rW   r^   r_   r`   rc   rf   ri   rF   markskipifhasattrobjectneeds_object_dirrn   rv   rx   r   r   r   r   r   r   r   r   xfailrZ   r[   releaselevelr   r   r   r   r   r,   3   s>    3



	
	*r,   c                   @   s   e Zd Zdd Zdd ZdS )TestWorkingSetc                 C   sv   t g }td}|| ttd}tt}|	| W d    n1 s)w   Y  d}|j
 |ks9J d S )Nrz   zFoo<1.2z,Foo 1.2 is installed but Foo<1.2 is required)r   r   r~   rB   r   r   rF   rG   r   findr   r   )r   rJ   ry   rM   r   r   r   r   r   test_find_conflictings  s   

z$TestWorkingSet.test_find_conflictingc                 C   s   t g }td}tjd|d}|| td}tjd|d}|| td}|| td}|| tt}|t	d W d	   n1 sOw   Y  d
}|t
tdg7 }|j |kshJ d	S )z
        A ContextualVersionConflict should be raised when a requirement
        conflicts with a prior requirement for a different package.
        )ra   zBaz==1.0z/foo_dir/Foo-1.0.eggr   )ra   zBaz==2.0z/foo_dir/Bar-1.0.eggz/foo_dir/Baz-1.0.eggz/foo_dir/Baz-2.0.eggzFoo
Bar
Nz1Baz 1.0 is installed but Baz==2.0 is required by Bar)r   r   r   r~   rB   rF   rG   r   r|   r   reprsetr   r   )r   rJ   mdry   r   r   r   r   r   r   r   !test_resolve_conflicts_with_prior  s"   





z0TestWorkingSet.test_resolve_conflicts_with_priorN)r'   r(   r)   r   r   r   r   r   r   r   r  s    r   c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	Zej	
d
edd Zdd Zdd ZeedddgedddgddgedddgddZdZdd  Zd!d" Zd#d$ Zd%S )&TestEntryPointsc                 C   s`   |j dksJ |jdksJ |jdksJ |jdksJ | tu s$J d}t||ks.J d S )Nr   "pkg_resources.tests.test_resources)r   )x<foo = pkg_resources.tests.test_resources:TestEntryPoints [x])r    module_nameattrsre   loadr   str)r   epexpectr   r   r   assertfields  s   zTestEntryPoints.assertfieldsc                 C   s   t jdtdd| _d S )Nr1   )zrequires.txtz[x]r   )r   r~   r   r;   )r   methodr   r   r   setup_method  s   zTestEntryPoints.setup_methodc                 C   s$   t dddgdg| j}| | d S )Nr   r   r   r   )r   r;   r   r   r   r   r   r   
testBasics  s   zTestEntryPoints.testBasicsc                 C   s   d}t || j}| | t d}|jdksJ |jdks!J |jdks(J |jdks/J t d}|jdks;J |jd	ksBJ |jd
ksIJ |jdksPJ d}t |}|jdks^J d S )Nr   zbar baz=  spammity[PING]zbar bazspammityr   )pingz fizzly =  wocka:foofizzlywocka)r   z0html+mako = mako.ext.pygmentplugin:MakoHtmlLexerz	html+mako)r   parser;   r   r    r   r   re   )r   sr   specr   r   r   	testParse  s    



zTestEntryPoints.testParse)r   zx=a:b:czq=x/nazfez=pish:tush-zzx=f[a]>2reject_specc                 C   s:   t t t| W d    d S 1 sw   Y  d S r   )rF   rG   
ValueErrorr   r   )r   r   r   r   r   test_reject_spec  s   "z TestEntryPoints.test_reject_specc                 C   s8   t j }djdi t }t|}|j|ksJ dS )z<
        Allow any printable character in the name.
        z{name} = module:attrNr   )string	printablestripformatlocalsr   r   r    )r   r    r   r   r   r   r   test_printable_name  s   

z#TestEntryPoints.test_printable_namec                 C   s   t |t | jksJ | j D ]8\}}||j|jksJ ||j|jks*J t||jt|jks9J t||jt|jksHJ qd S r   )	rr   submap_expectitemsgetr    r   r   r   re   )r   mrR   r   r   r   r   checkSubMap  s    zTestEntryPoints.checkSubMapfeature1
somemodulesomefunctionfeature2zanother.module	SomeClassextra1extra2feature3zthis.module	something)re   )r   r   r   z
            # define features for blah blah
            feature1 = somemodule:somefunction
            feature2 = another.module:SomeClass [extra1,extra2]
            feature3 = this.module [something]
    c                 C   s   |  td| j tt tdd W d    n1 s w   Y  tt tdddg W d    d S 1 s>w   Y  d S )Nxyzzx azfoo=barr   zfoo=baz)r   r   parse_group
submap_strrF   rG   r   r   r   r   r   testParseList  s   "zTestEntryPoints.testParseListc                 C   s   t d| ji}| |d  t| dgksJ t d| j }| |d  t| dgks4J tt t ddg W d    n1 sKw   Y  tt t | j W d    d S 1 sgw   Y  d S )Nr   z[xyz]
z[xyz])	r   	parse_mapr   r   rA   keysrF   rG   r   )r   r   r   r   r   testParseMap  s   "zTestEntryPoints.testParseMapc                 C   sP   t dddgdg}ttj |jdd W d    d S 1 s!w   Y  d S )Nr   r   r   r   F)require)r   rF   warnsr$   PkgResourcesDeprecationWarningr   r   r   r   r   testDeprecationWarnings  s   "z'TestEntryPoints.testDeprecationWarningsN)r'   r(   r)   r   r   r   r   reject_specsrF   r   parametrizer   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s*    	


r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestRequirementsc                 C   s   t d}t|dksJ t|dksJ |t dksJ |t dks%J |t dks-J |t dks5J |t dks=J |t dksEJ d S )NTwisted>=1.2z!Requirement.parse('Twisted>=1.2')ztwisTed>=1.2zTwisted>=2.0z	Zope>=1.2z	Zope>=3.0zTwisted[extras]>=1.2)r   r   r   r   )r   rr   r   r   r     s   
zTestRequirements.testBasicsc                 C   sX   t d}t d}||ksJ t|t|ksJ t|dks J t dt dks*J d S )NzTwisted==1.2c1,>=1.2zTwisted>=1.2,==1.2c1Twisted'Twisted @ https://localhost/twisted.zip)r   r   r   r1r2r   r   r   testOrdering  s   zTestRequirements.testOrderingc                 C   s   t d}td}td}td}td|v sJ td|vs#J d|v s)J d|vs/J ||vs5J ||vs;J ||v sAJ d S )Nr   r0   zTwisted-1.1.eggzTwisted-1.2.eggr5   1.1)r   r   r~   r	   )r   r   foo_disttwist11twist12r   r   r   testBasicContains#  s   


z"TestRequirements.testBasicContainsc                 C   s   t d}t d}||ksJ t|jtdksJ t|jtdks&J t|t|ks0J t|tdd tdtddgd fksEJ tt dtdd	t t d fksYJ d S )
NzTwisted[foo,bar]>=1.2zTwisted[bar,FOO]>=1.2)r   bartwistedz>=1.2r   r  r   zhttps://localhost/twisted.zip)r   r   r   re   hashr   	frozensetr   r   r   r   testOptionsAndHashing0  s0   


z&TestRequirements.testOptionsAndHashingc                 C   s   t d}t d}tj}|d|vsJ |d|vsJ |d|vs%J |d|v s-J |d|v s5J |d|v s=J |d|v sEJ d S )Nz
foo==0.3a2z
foo!=0.3a4zfoo-0.3a4.eggzfoo-0.3a1.eggzfoo-0.3a2.eggzfoo-0.3a3.eggzfoo-0.3a5.egg)r   r   r   r~   )r   r   r   rV   r   r   r   testVersionEqualityH  s   

z$TestRequirements.testVersionEqualityc                 C   sT   t djdks
J t djdksJ t djdksJ t djdks(J dS )zQ
        The setuptools project should implement the setuptools package.
        
setuptoolszsetuptools == 0.7zsetuptools == 0.7a1zsetuptools >= 0.7N)r   r   rQ   r   r   r   r   testSetuptoolsProjectNameV  s   z*TestRequirements.testSetuptoolsProjectNameN)	r'   r(   r)   r   r   r  r  r  r	  r   r   r   r   r     s    
r   c                	   @   s   e Z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ejdg ddd ZdZejdg deeee  dd Zdd ZdS )TestParsingc                 C   s   t tdg ks
J d S )N )rA   r   r   r   r   r   testEmptyParsec  s   zTestParsing.testEmptyParsec                 C   sV   g g fddgfg gg fdddgfddgddgffD ]\}}t t||ks(J qd S )Nr   z x
 yyzx

)rA   r$   r%   )r   inpoutr   r   r   testYieldingf  s   
zTestParsing.testYieldingc                 C   s   d}t t|d dgfdddgfddgfdg fd	d
gfgks!J tt t td W d    d S 1 s9w   Y  d S )Na   
                    x
                    [Y]
                    z

                    a
                    [b ]
                    # foo
                    c
                    [ d]
                    [q]
                    v
                    r   Yzr   r   r   rV   qrh   z[foo)rA   r$   split_sectionsrF   rG   r   )r   sampler   r   r   testSplittingp  s   

"zTestParsing.testSplittingc                 C   sT   t ddksJ t ddksJ t ddksJ t ddks J t ddks(J d S )	Nzadns-pythonz
WSGI Utilsz
WSGI-UtilszWSGI  UtilsMoney$$$MakerMoney-Makerpeak.webzpeak-web)r
   r   r   r   r   testSafeName  
   zTestParsing.testSafeNamec                 C   sT   t ddksJ t ddksJ t ddksJ t ddks J t d	d	ks(J d S )
Nz1.2-1z	1.2.post1z	1.2 alphaz	1.2.alphaz2.3.4 20050521z2.3.4.20050521r  r  r  )r   r   r   r   r   testSafeVersion  r  zTestParsing.testSafeVersionc                 C   sT  t tdtdgksJ t tdtdgksJ tdtdks%J tt td W d    n1 s:w   Y  tt td W d    n1 sTw   Y  tt td W d    n1 snw   Y  tt td W d    n1 sw   Y  tt td	 W d    d S 1 sw   Y  d S )
NzTwis-Ted>=1.2-1zTwisted >=1.2, \ # more
<2.0zTwisted>=1.2,<2.0zFooBar==1.99a3z>=2.3zx\zx==2 qz	X==1
Y==2#)rA   r   r   r   rF   rG   r   r   r   r   r   testSimpleRequirements  s,   



"z"TestParsing.testSimpleRequirementsc                 C   sd   t dt dksJ t dt dksJ t dt dks$J t dt dks0J d S )Nzfoobar;os_name=='a'zname==1.1;python_version=='2.7'zname==1.1;python_version=='3.6'zname==1.0;python_version=='2.7'zname==1.2;python_version=='2.7'z$name[foo]==1.0;python_version=='3.6'z(name[foo,bar]==1.0;python_version=='3.6')r   r   r   r   r   r   test_requirements_with_markers  s$   
z*TestParsing.test_requirements_with_markersc                 C   s   t d d S )Nzfoo==1.0+org1r   r   r   r   r   test_local_version  s   zTestParsing.test_local_versionc                 C   s   t d t d d S )Nzfoo>=1.0, <3zfoo >= 1.0, < 3r   r   r   r   r   %test_spaces_between_multiple_versions  ro   z1TestParsing.test_spaces_between_multiple_versions)lowerupper)
)z1.2-rc1z1.2rc1)0.40.4.0)z0.4.0.0r&  )z0.4.0-0z0.4-0)0post1z0.0post1)0pre10.0c1)z0.0.0preview10c1)r)  z0-rc1)z1.2a1z1.2.a.1)z1.2.az1.2ac                 C   s   t |t |ks
J d S r   r	   r   r#  r$  r   r   r   r    s   zTestParsing.testVersionEqualityz
        0.80.1-3 0.80.1-2 0.80.1-1 0.79.9999+0.80.0pre4-1
        0.79.9999+0.80.0pre2-3 0.79.9999+0.80.0pre2-2
        0.77.2-1 0.77.1-1 0.77.0-1
        ))2.12.1.1)2a12b0)r/  r-  )z2.3a1z2.3)2.1-1z2.1-2)r1  r.  )r-  z2.1post4)z2.1a0-20040501r-  )r   z02.1)z3.2z	3.2.post0)z3.2post1z3.2post2)r%  z4.0)z0.0.4r&  )r'  z0.4post1)z	2.1.0-rc1z2.1.0)z2.1devz2.1a0c                 C   s   t |t |k s
J d S r   r+  r,  r   r   r   testVersionOrdering  s   zTestParsing.testVersionOrderingc                 C   s    t tdt tdksJ dS )z
        Ensure that our versions stay hashable even though we've subclassed
        them and added some shim code to them.
        z1.0N)r  r	   r   r   r   r   testVersionHashable  s    zTestParsing.testVersionHashableN)r'   r(   r)   r  r  r  r  r  r  r  r!  r"  rF   r   r   r  torturerA   r   reversedr   r2  r3  r   r   r   r   r
  b  s0    


r
  c                   @   sb   e Zd ZdZejdd Zejdddd Zejj	e
 dkd	d
Zedd Zedd ZdS )TestNamespacesz8__import__('pkg_resources').declare_namespace(__name__)
c              	   c   sb    t tdst|V  dS t|d }tt|| zt||V  W t| dS t| w )z
        Where available, return the tempdir as a symlink,
        which as revealed in #231 is more fragile than
        a natural tempdir.
        symlinkNz-linked)r   osr   r7  typeunlink)r   tmpdir	link_namer   r   r   symlinked_tmpdir  s   

zTestNamespaces.symlinked_tmpdirT)autousec                 c   s\    t j }tjdd }|d}tjt| zdV  W |t _|t_dS |t _|t_w )z
        Patch sys.path to include the 'site-pkgs' dir. Also
        restore pkg_resources._namespace_packages to its
        former state.
        N	site-pkgs)r$   _namespace_packagescopyrZ   pathmkdirappendr   )r   r;  saved_ns_pkgssaved_sys_path	site_pkgsr   r   r   patched_path  s   


zTestNamespaces.patched_pathWindowsz#591rk   c           	      C   sR  |  }|}tjt|d  |d |d f}|D ]"}|d }|d }|  |d j| jdd |d j| jdd qtj	t
dd	 d
dl}W d   n1 sSw   Y  dtjv s_J tj	t
dd	 d
dl}W d   n1 suw   Y  dtjv sJ tjd dgksJ t|d d d t|d d d g}|jj|ksJ dS )a  
        Test nested namespace packages
        Create namespace packages in the following tree :
            site-packages-1/pkg1/pkg2
            site-packages-2/pkg1/pkg2
        Check both are in the _namespace_packages dict and that their __path__
        is correct
        
site-pkgs2r?  pkg1pkg2__init__.pyutf-8encodingpkg_resources.declare_namespacematchr   Nz	pkg1.pkg2)realpathrZ   rB  rD  r   
ensure_dir
write_textns_strrF   r   DeprecationWarningrK  r$   r@  	pkg1.pkg2rL  __path__)	r   r=  real_tmpdirr;  	site_dirssiterK  rL  rI   r   r   r   test_two_levels_deep  s.   


z#TestNamespaces.test_two_levels_deepc           
      C   s   |}|d |d |d f}d}t |dD ]1\}}|dkr$tjt| |d }|d }|  |d j| jd	d
 |d j|| d	d
 qtj	t
dd ddl}ddl}W d   n1 s`w   Y  dd |D }	|j|	kssJ |jjdks{J dS )aV  
        Test that if multiple versions of the same namespace package subpackage
        are on different sys.path entries, that only the one earliest on
        sys.path is imported, and that the namespace package's __path__ is in
        the correct order.

        Regression test for https://github.com/pypa/setuptools/issues/207
        r?  rJ  z
site-pkgs3z__version__ = %rr>   nspkgsubpkgrM  rN  rO  rQ  rR  r   Nc                 S   s   g | ]
}t | d  qS )r_  )r   rT  )r:   r]  r   r   r   r<   c  s    z2TestNamespaces.test_path_order.<locals>.<listcomp>)	enumeraterZ   rB  rD  r   rU  rV  rW  rF   r   rX  r_  nspkg.subpkgrZ  r`  __version__)
r   r=  r;  r\  vers_strnumberr]  r_  r`  rI   r   r   r   test_path_orderC  s*   
zTestNamespaces.test_path_orderN)r'   r(   r)   rW  rF   fixturer=  rH  r   r   r-   systemissue591r^  rf  r   r   r   r   r6    s    



#r6  )r   r8  r-   r   rZ   rF   packaging.specifiersr   r$   r   r   r   r   r   r   r	   r
   r   r   EmptyProviderr   r~   rC   r,   r   r   r   r
  r6  r   r   r   r   <module>   s*    ,  A*qU 