U
    aÊ¹ju;  ã                   @  s’  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 d dlZd dlZd dlmZmZmZ d dlZd dlZG dd„ deƒZG dd„ dƒZG d	d
„ d
ƒZdd„ Zdd„ Zdd„ Zej dddefddefg¡ejjejdd… dk�oejj dkdd�dd„ ƒƒZ!ejjejdd… dk�oNejj dkdd�dd„ ƒZ"ej dd d!g¡d"d#„ ƒZ#d$d%„ Z$G d&d'„ d'ƒZ%dS )(é    )ÚannotationsN)Úmock)ÚDistInfoDistributionÚDistributionÚEggInfoDistributionc                   @  s   e Zd Zdd„ ZdS )Ú
EggRemoverc                 C  s0   | t jkrt j | ¡ tj | ¡r,t | ¡ d S ©N)ÚsysÚpathÚremoveÚosÚexists)Úself© r   úe/var/www/html/bwave/python/venv/lib/python3.8/site-packages/pkg_resources/tests/test_pkg_resources.pyÚ__call__   s    
zEggRemover.__call__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r      s   r   c                   @  sV   e Zd ZU g Zded< e dddddd¡Zed	d
„ ƒZedd„ ƒZ	dd„ Z
dd„ ZdS )ÚTestZipProviderzlist[EggRemover]Ú
finalizersiÝ  é   é   é   é   r   c                 C  s  t jddd�}t |d¡}t ¡ }d|_| j ¡ |_| 	|d¡ t ¡ }d|_| j ¡ |_| 	|d¡ t ¡ }d	|_| j ¡ |_| 	|d
¡ t ¡ }d|_| j ¡ |_| 	|d¡ | 
¡  | 
¡  tj |j¡ tj |jd¡}tj |¡ | j t|ƒ¡ | j t|jƒ¡ dS )z'create a zip egg and add it to sys.pathz.eggF)ÚsuffixÚdeleteÚwúmod.pyzx = 3
údata.datúhello, world!zsubdir/mod2.pyzx = 6
zsubdir/data2.datzgoodbye, world!ÚsubdirN)ÚtempfileÚNamedTemporaryFileÚzipfileÚZipFileÚZipInfoÚfilenameÚref_timeÚ	timetupleÚ	date_timeÚwritestrÚcloser	   r
   ÚappendÚnamer   Újoinr   r   )ÚclsÚeggZzip_eggZzip_infor!   r   r   r   Úsetup_class%   s2    zTestZipProvider.setup_classc                 C  s   | j D ]
}|ƒ  qd S r   )r   )r0   Ú	finalizerr   r   r   Úteardown_classC   s    
zTestZipProvider.teardown_classc                 C  sÚ   dd l }t |¡}dddg}t| d¡ƒ|ks2t‚ddg}t| d¡ƒ|ksPt‚t| d¡ƒ|ksft‚| d	¡g ksxt‚| d
¡g ksŠt‚dd l}t |¡}t| d¡ƒ|ks²t‚| d¡g ksÄt‚| d¡g ksÖt‚d S )Nr   r   r   r!   Ú z	data2.datzmod2.pyzsubdir/Znonexistentznonexistent/)ÚmodÚpkg_resourcesÚZipProviderÚsortedÚresource_listdirÚAssertionErrorÚmod2)r   r6   ÚzpZexpected_rootZexpected_subdirr<   Zzp2r   r   r   Útest_resource_listdirH   s    


z%TestZipProvider.test_resource_listdirc              	   C  sÂ   ddl }t ¡ }t |¡}| |d¡}tj t |¡j	¡}|| j
ksHt‚t|ddd�}| d¡ | ¡  | j
 ¡ }t |||f¡ | |d¡}t|dd��}| ¡ dks¬t‚W 5 Q R X | ¡  dS )	a  
        If a previous call to get_resource_filename has saved the file, but
        the file has been subsequently mutated with different file of the
        same size and modification time, it should not be overwritten on a
        subsequent call to get_resource_filename.
        r   Nr   r   zutf-8)Úencodingzhello, world?r    )r6   r7   ÚResourceManagerr8   Úget_resource_filenameÚdatetimeÚfromtimestampr   ÚstatÚst_mtimer(   r;   ÚopenÚwriter,   Ú	timestampÚutimeÚreadÚcleanup_resources)r   r6   Úmanagerr=   r'   ÚactualÚfÚtsr   r   r   Ú)test_resource_filename_rewrites_on_change`   s    


z9TestZipProvider.test_resource_filename_rewrites_on_changeN)r   r   r   r   Ú__annotations__rB   r(   Úclassmethodr2   r4   r>   rP   r   r   r   r   r      s   


r   c                   @  s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestResourceManagerc                 C  s<   t  ¡ }| d¡}tt|ƒƒ}d| }t|tƒs8t|ƒ‚d S )NÚfooz%Unexpected type from get_cache_path: )r7   r@   Úget_cache_pathÚstrÚtypeÚ
isinstancer;   )r   Úmgrr
   Útype_Úmessager   r   r   Útest_get_cache_pathz   s
    
z'TestResourceManager.test_get_cache_pathc              	     sÂ   t jf‡ fdd„	‰ g ˆ _t  ¡ }| t|ƒ¡ tj d¡}t	j
jt dˆ d�� | |¡ W 5 Q R X ˆ j}t|ƒdksxt‚|d  tj¡dd … d	d
gksœt‚|d  tj¡dd … d	gks¾t‚d S )Nc                   s&   ˆ j  | ¡ || ƒ}|s"t | ¡ |S r   )Údirnamesr-   r   Úmakedirs)ÚdirnameZunpatched_isdirZwas_dir©Úpatched_isdirr   r   ra   ƒ   s
    
zCTestResourceManager.test_get_cache_path_race.<locals>.patched_isdir)rT   ÚbarZbazÚisdir)Únewé   r   éþÿÿÿrT   rb   é   éÿÿÿÿ)r7   rc   r]   r@   Úset_extraction_pathrV   r   Úsepr/   r   ÚpatchÚobjectrU   Úlenr;   Úsplit)r   ÚtmpdirrY   Úarchive_nameZcalled_dirnamesr   r`   r   Útest_get_cache_path_race�   s    $z,TestResourceManager.test_get_cache_path_racec                 C  s$   d}t jdd |¡g}t |¡ dS )z�
        In a separate Python environment, import pkg_resources and assert
        that action doesn't cause setuptools to be imported.
        )zimport pkg_resourcesz
import syszAassert "setuptools" not in sys.modules, "setuptools was imported"z-cz; N)r	   Ú
executabler/   Ú
subprocessÚ
check_call)r   ÚlinesÚcmdr   r   r   Útest_setuptools_not_imported¡   s    z0TestResourceManager.test_setuptools_not_importedN)r   r   r   r\   rq   rw   r   r   r   r   rS   y   s    rS   c              	   C  sN   t j | ¡}t  |¡ t| dƒ�}| |¡ W 5 Q R X tt |¡ƒ}|\}|S )a†  
    Make a test Distribution object, and return it.

    :param metadata_path: the path to the metadata file that should be
        created. This should be inside a distribution directory that should
        also be created. For example, an argument value might end with
        "<project>.dist-info/METADATA".
    :param metadata: the desired contents of the metadata file, as bytes.
    Úwb)	r   r
   r_   ÚmkdirrF   rG   Úlistr7   Údistributions_from_metadata)Úmetadata_pathÚmetadataÚdist_dirrN   ÚdistsÚdistr   r   r   Úmake_test_distribution¯   s    

r�   c           	   	   C  s’   d}t j t| ƒd|¡}d d¡}t||d�}t t¡�}| 	|¡ W 5 Q R X |j
}t|ƒ}d}||ksvtd |¡ƒ‚| |¡sŽtd |¡ƒ‚dS )	zI
    Test a metadata file with bytes that can't be decoded as utf-8.
    ÚMETADATAzfoo.dist-infou   nÃ©ez
iso-8859-1)r}   z`codec can't decode byte 0xe9 in position 1: invalid continuation byte in METADATA file at path: z
actual: {}N)r   r
   r/   rV   Úencoder�   ÚpytestÚraisesÚUnicodeDecodeErrorÚget_metadataÚvaluer;   ÚformatÚendswith)	ro   r'   r|   r}   r€   ÚexcinfoÚexcrM   Úexpectedr   r   r   Útest_get_metadata__bad_utf8Ã   s    
ýrŽ   c                 C  sJ   | | }|  ¡  | d¡ ¡  tt |¡ƒ}t|ƒdks<t‚|\}||fS )zN
    Create a distribution directory with no file containing the version.
    ztemp.txtrg   )Ú
ensure_dirr/   Zensurerz   r7   r{   rm   r;   )ro   Úbasenamer~   r   r€   r   r   r   Úmake_distribution_no_versionÝ   s    r‘   z-suffix, expected_filename, expected_dist_typezegg-infozPKG-INFOz	dist-infor‚   re   )é   r   Úfinalz/https://github.com/python/cpython/issues/103632©Úreasonc              	   C  s²   d  |¡}t| |ƒ\}}d  |¡}tj ||¡}t t¡�}	|j W 5 Q R X t	|	j
ƒ}
||
ksntt	||
fƒƒ‚|	j
j\}}||ks†t‚||ksžtt	||fƒƒ‚t|ƒ|ks®t‚dS )zI
    Test Distribution.version when the "Version" header is missing.
    zfoo.{}z2Missing 'Version:' header and/or {} file at path: N)r‰   r‘   r   r
   r/   r„   r…   Ú
ValueErrorÚversionrV   rˆ   r;   ÚargsrW   )ro   r   Zexpected_filenameZexpected_dist_typer�   r€   r~   Zexpected_textr|   r‹   ÚerrÚmsgr   r   r   Ú!test_distribution_version_missingî   s    
ÿ
r›   c               	   C  sD   t dƒ} t t¡�}| j W 5 Q R X |jj\}} d}||ks@t‚dS )zl
    Test Distribution.version when the "Version" header is missing and
    the path can't be detected.
    z/foozJMissing 'Version:' header and/or PKG-INFO file at path: [could not detect]N)r   r„   r…   r–   r—   rˆ   r˜   r;   )r€   r‹   rš   r�   r   r   r   Ú1test_distribution_version_missing_undetected_path  s    ÿrœ   ÚonlyFTc                 C  s.   | d }|  ¡  t t| ƒt|ƒ|¡r*t‚dS )z5Test path containing a file with dist-info extension.zfoobar.dist-infoN)Útouchr7   Údist_factoryrV   r;   )Útmp_pathr�   Z	dist_infor   r   r   Útest_dist_info_is_not_dir.  s    r¡   c              	     sº   t j‰ |  dtjdd�¡ tˆd dƒ�}t ddi|¡ W 5 Q R X |  dtjd	d�¡ ‡ ‡fd
d„}t dtj|d�¡�.}tj	 
¡  t 	¡ ddgksšt‚tj	 
¡  W 5 Q R X | ¡  dS )z-Regression test for pkg_resources._macos_verszplatform.mac_ver)r5   r   r5   )Zreturn_valueú
fake.plistrx   ÚProductVersionz11.4zos.path.existsTc                   s   ˆ ˆd f|ž|ŽS )Nr¢   r   )Úfiler˜   Úkwargs©Z	orig_openr    r   r   Ú	fake_openD  s    z+test_macos_vers_fallback.<locals>.fake_openzbuiltins.open)Zside_effectZ11Ú4N)ÚbuiltinsrF   Úsetattrr   ZMockÚplistlibÚdumprk   r7   Ú_macos_versÚcache_clearr;   Zassert_called)Zmonkeypatchr    Z	fake_filer§   Úmr   r¦   r   Útest_macos_vers_fallback6  s    
r°   c                   @  s¸   e Zd Zejdd„ ƒZdd„ Zdd„ Zej 	ddd	d
dg¡dd„ ƒZ
ejjej d¡ej d¡kdd�ej 	ddg¡dd„ ƒƒZejjejjdkdd�ej 	ddddg¡dd„ ƒƒZdS )ÚTestDeepVersionLookupDistutilsc                   sZ   G dd„ dt ƒ}|ˆ ƒ}ˆ  tj¡ d}t‡ fdd„|D ƒƒ|_tttj	|j 
¡ ƒƒ |S )zq
        Create a package environment, similar to a virtualenv,
        in which packages are installed.
        c                   @  s   e Zd ZdS )z7TestDeepVersionLookupDistutils.env.<locals>.EnvironmentN)r   r   r   r   r   r   r   ÚEnvironmentX  s   r²   )ÚhomeÚlibÚscriptsÚdatazegg-basec                 3  s   | ]}|t ˆ | ƒfV  qd S r   )rV   )Ú.0r_   ©ro   r   r   Ú	<genexpr>^  s     z5TestDeepVersionLookupDistutils.env.<locals>.<genexpr>)rV   ÚchmodrD   ÚS_IRWXUÚdictÚpathsrz   Úmapr   ry   Úvalues)r   ro   r²   ÚenvÚsubsr   r¸   r   rÀ   Q  s    z"TestDeepVersionLookupDistutils.envc                 C  sT   d}t d||d�}tj |¡}tjj |¡}| ¡  |jd |_| 	¡  | 
¡  dS )zj
        Create a foo package installed (distutils-style) to env.paths['lib']
        as version.
        u&   This package has unicode metadata! â�„rT   )r.   r—   Úlong_descriptionr´   N)r¼   Ú	distutilsr€   r   ÚcommandÚinstall_egg_infoÚinitialize_optionsr½   Zinstall_dirÚfinalize_optionsÚrun)r   rÀ   r—   ÚldÚattrsr€   Ziei_cmdr   r   r   Úcreate_foo_pkgb  s    z-TestDeepVersionLookupDistutils.create_foo_pkgc                 C  sF   d}|   ||¡ tj d¡}t |jd g¡ |¡}|j|ksBt‚d S )Nz1.11.0.dev0+2329eaezfoo>=1.9r´   )	rË   r7   ÚRequirementÚparseÚ
WorkingSetr½   Úfindr—   r;   )r   rÀ   r—   Úreqr€   r   r   r   Ú#test_version_resolved_from_egg_infop  s
    zBTestDeepVersionLookupDistutils.test_version_resolved_from_egg_infozunnormalized, normalized)rT   rT   )zfoo/rT   )úfoo/barrÒ   )zfoo/bar/rÒ   c                 C  s$   t  |¡}t  |¡}||ks t‚dS )zeEnsure the trailing slash is cleaned for path comparison.

        See pypa/setuptools#1519.
        N©r7   Únormalize_pathr;   ©r   ÚunnormalizedÚ
normalizedZresult_from_unnormalizedZresult_from_normalizedr   r   r   Ú test_normalize_path_trailing_sepz  s    

z?TestDeepVersionLookupDistutils.test_normalize_path_trailing_sepÚAÚaz%Testing case-insensitive filesystems.r”   )z
MiXeD/CasEz
mixed/casec                 C  s$   t  |¡}t  |¡}||ks t‚dS )z@Ensure mixed case is normalized on case-insensitive filesystems.NrÓ   rÕ   r   r   r   Útest_normalize_path_normcaseŒ  s    

z;TestDeepVersionLookupDistutils.test_normalize_path_normcaseú\z5Testing systems using backslashes as path separators.zunnormalized, expected)zforward/slashúforward\slash)zforward/slash/rÝ   )zbackward\slash\zbackward\slashc                 C  s   t  |¡}| |¡st‚dS )z;Ensure path seps are cleaned on backslash path sep systems.N)r7   rÔ   rŠ   r;   )r   rÖ   r�   Úresultr   r   r   Ú!test_normalize_path_backslash_sepœ  s    
z@TestDeepVersionLookupDistutils.test_normalize_path_backslash_sepN)r   r   r   r„   ZfixturerÀ   rË   rÑ   ÚmarkÚparametrizerØ   Zskipifr   r
   ÚnormcaserÛ   rj   rß   r   r   r   r   r±   P  sF   

üþ	
	þÿþ
þýþr±   )&Ú
__future__r   r©   rB   r   r«   rD   rs   r	   r"   r$   Zunittestr   r„   r7   r   r   r   Z"distutils.command.install_egg_inforÃ   Údistutils.distrV   r   r   rS   r�   rŽ   r‘   rà   rá   ZxfailÚversion_infoÚreleaselevelr›   rœ   r¡   r°   r±   r   r   r   r   Ú<module>   sR   Z6þþþþ

