o
    ‹¨ÊhB#  ã                   @   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	m
Z ddlmZ ddlmZmZmZmZmZmZmZmZ zd dlmZ W n eyY   d dlmZ Y nw G d	d
„ d
ejejƒZG dd„ dejejƒZG dd„ dej ej!ejƒZ"G dd„ dej ej!ejƒZ#G dd„ dej$ejejƒZ%G dd„ dej ej!ejƒZ&G dd„ dej ejƒZ'G dd„ dej ejƒZ(G dd„ dejƒZ)G dd„ dej ej!ej*ejƒZ+dS )é    )Úunicode_literalsNé   )Úfixturesé   )ÚDistributionÚ
EntryPointÚMetadataPathFinderÚPackageNotFoundErrorÚdistributionsÚentry_pointsÚmetadataÚversion)Ústr)Úunicodec                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú
BasicTestsz\d+\.\d+(\.\d)?c                 C   s2   t  d¡}t|jtƒsJ ‚t | j|j¡sJ ‚d S )Núdistinfo-pkg)r   Ú	from_nameÚ
isinstancer   ÚtextÚreÚmatchÚversion_pattern)ÚselfÚdist© r   úT/var/www/html/env/lib/python3.10/site-packages/importlib_metadata/tests/test_main.pyÚtest_retrieves_version_of_self   s   
z)BasicTests.test_retrieves_version_of_selfc                 C   ó:   |   t¡� t d¡ W d   ƒ d S 1 sw   Y  d S )Núdoes-not-exist)ÚassertRaisesr	   r   r   ©r   r   r   r   Útest_for_name_does_not_exist"   s   "ÿz'BasicTests.test_for_name_does_not_existc                 C   sJ   |   t¡�}t d¡ W d  ƒ n1 sw   Y  dt|jƒv s#J ‚dS )zý
        When a package is not found, that could indicate that the
        packgae is not installed or that it is installed without
        metadata. Ensure the exception mentions metadata to help
        guide users toward the cause. See #124.
        r   Nr   )r   r	   r   r   r   Ú	exception)r   Úctxr   r   r   Ú(test_package_not_found_mentions_metadata&   s   ÿz3BasicTests.test_package_not_found_mentions_metadatac                 C   s   |   tt¡ |   tt¡ d S ©N)ÚassertIsInstancer   Útyper   r    r   r   r   Útest_new_style_classes2   s   z!BasicTests.test_new_style_classesN)Ú__name__Ú
__module__Ú__qualname__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	S )
ÚImportTestsc                 C   r   )NÚdoes_not_exist)r   ÚImportErrorÚ	importlibÚimport_moduler    r   r   r   Útest_import_nonexistent_module8   s   "ÿz*ImportTests.test_import_nonexistent_modulec                 C   s,   t tƒ d ƒ}|d }|  | ¡ jd¡ d S )NÚentriesÚmain)Údictr   ÚassertEqualÚloadr)   ©r   r2   Úepr   r   r   Útest_resolve>   ó   zImportTests.test_resolvec                 C   s(   t tƒ d ƒ}|d }|  |jd¡ d S )Nr2   zns:subzmod:main)r4   r   r5   Úvaluer7   r   r   r   Ú"test_entrypoint_with_colon_in_nameC   s   z.ImportTests.test_entrypoint_with_colon_in_namec                 C   s"   t dddd�}| ¡ tu sJ ‚d S )Nr8   Úimportlib_metadataÚgrp)Únamer;   Úgroup)r   r6   r=   )r   r8   r   r   r   Útest_resolve_without_attrH   s   ýz%ImportTests.test_resolve_without_attrN)r)   r*   r+   r1   r9   r<   rA   r   r   r   r   r,   7   s
    r,   c                   @   s4   e Zd Zedd„ ƒZdd„ Zedd„ ƒZdd„ Zd	S )
ÚNameNormalizationTestsc                 C   óR   | d }|  ¡  |d }| d¡�}| d¡ W d  ƒ dS 1 s"w   Y  dS )z
        Create minimal metadata for a package with dashes
        in the name (and thus underscores in the filename).
        zmy_pkg.dist-infoÚMETADATAÚwúVersion: 1.0
Nzmy-pkg©ÚmkdirÚopenÚwrite©Úsite_dirÚmetadata_dirr   Ústrmr   r   r   Úpkg_with_dashesS   ó   
ÿþz&NameNormalizationTests.pkg_with_dashesc                 C   s    |   | j¡}t|ƒdksJ ‚dS )z�
        For a package with a dash in the name, the dist-info metadata
        uses underscores in the name. Ensure the metadata loads.
        ú1.0N)rO   rL   r   ©r   Úpkg_namer   r   r   Ú-test_dashes_in_dist_name_found_as_underscores`   s   zDNameNormalizationTests.test_dashes_in_dist_name_found_as_underscoresc                 C   rC   )z\
        Create minimal metadata for a package with mixed case
        in the name.
        zCherryPy.dist-inforD   rE   rF   NÚCherryPyrG   rK   r   r   r   Úpkg_with_mixed_caseh   rP   z*NameNormalizationTests.pkg_with_mixed_casec                 C   sH   |   | j¡}t|ƒdksJ ‚t| ¡ ƒdksJ ‚t| ¡ ƒdks"J ‚dS )zG
        Ensure the metadata loads when queried with any case.
        rQ   N)rV   rL   r   ÚlowerÚupperrR   r   r   r   Ú test_dist_name_found_as_any_caseu   s   z7NameNormalizationTests.test_dist_name_found_as_any_caseN)r)   r*   r+   ÚstaticmethodrO   rT   rV   rY   r   r   r   r   rB   Q   s    

rB   c                   @   s4   e Zd Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zd	S )
ÚNonASCIITestsc                 C   sV   | d }|  ¡  |d }|jddd��}| d¡ W d  ƒ dS 1 s$w   Y  dS )	zb
        Create minimal metadata for a package with non-ASCII in
        the description.
        úportend.dist-inforD   rE   úutf-8©Úencodingu   Description: pÃ´rËˆtend
NÚportendrG   ©rL   rM   r   Úfpr   r   r   Úpkg_with_non_ascii_description€   s   
ÿþz,NonASCIITests.pkg_with_non_ascii_descriptionc                 C   s`   | d }|  ¡  |d }|jddd��}| t d¡ ¡ ¡ W d  ƒ dS 1 s)w   Y  dS )	zl
        Create minimal metadata for an egg-info package with
        non-ASCII in the description.
        r\   rD   rE   r]   r^   uK   
                Name: portend

                pÃ´rËˆtend
                Nr`   )rH   rI   rJ   ÚtextwrapÚdedentÚlstripra   r   r   r   Ú'pkg_with_non_ascii_description_egg_info�   s   ü
ÿúz5NonASCIITests.pkg_with_non_ascii_description_egg_infoc                 C   s(   |   | j¡}t|ƒ}|d dksJ ‚d S )NÚDescriptionu
   pÃ´rËˆtend)rc   rL   r   ©r   rS   Úmetar   r   r   Útest_metadata_loadsž   ó   z!NonASCIITests.test_metadata_loadsc                 C   s(   |   | j¡}t|ƒ}| ¡ dksJ ‚d S )Nu   pÃ´rËˆtend
)rg   rL   r   Úget_payloadri   r   r   r   Útest_metadata_loads_egg_info£   rl   z*NonASCIITests.test_metadata_loads_egg_infoN)r)   r*   r+   rZ   rc   rg   rk   rn   r   r   r   r   r[      s    

r[   c                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚDiscoveryTestsc                 C   sP   t tƒ ƒ}tdd„ |D ƒƒsJ ‚tdd„ |D ƒƒsJ ‚tdd„ |D ƒƒs&J ‚d S )Nc                 s   s   � | ]}t |tƒV  qd S r%   )r   r   ©Ú.0r   r   r   r   Ú	<genexpr>¯   s
   € ÿ
ÿz8DiscoveryTests.test_package_discovery.<locals>.<genexpr>c                 s   ó   � | ]
}|j d  dkV  qdS )ÚNamezegginfo-pkgN©r   rq   r   r   r   rs   ³   ó
   € ÿ
ÿc                 s   rt   )ru   r   Nrv   rq   r   r   r   rs   ·   rw   )Úlistr
   ÚallÚany)r   Údistsr   r   r   Útest_package_discovery­   s   
þþþz%DiscoveryTests.test_package_discoveryc                 C   s@   |   t¡� ttddd�ƒ W d   ƒ d S 1 sw   Y  d S )NÚ	somethingÚelse)Úcontextr?   )r   Ú
ValueErrorrx   r
   r    r   r   r   Útest_invalid_usage¼   s   "ÿz!DiscoveryTests.test_invalid_usageN)r)   r*   r+   r|   r�   r   r   r   r   rp   ©   s    rp   c                   @   ro   )ÚDirectoryTestc                 C   sH   | j  d¡ ¡  |  t¡� tdƒ W d   ƒ d S 1 sw   Y  d S )NzEGG-INFOzunknown-package)rL   ÚjoinpathrH   r   r	   r   r    r   r   r   Útest_egg_infoÂ   s   
"ÿzDirectoryTest.test_egg_infoc              	   C   s†   | j  d¡}| ¡  |  |¡�* |  t¡� tdƒ W d   ƒ n1 s$w   Y  W d   ƒ d S W d   ƒ d S 1 s<w   Y  d S )Nzfoo-3.6.eggÚfoo)rL   rƒ   rH   Úadd_sys_pathr   r	   r   )r   Úeggr   r   r   Útest_eggÉ   s   
ÿÿ"ÿzDirectoryTest.test_eggN)r)   r*   r+   r„   rˆ   r   r   r   r   r‚   Á   s    r‚   c                   @   s   e Zd ZdZdd„ ZdS )ÚMissingSysPathz/does-not-existc                 C   s   t  ¡  dS ©zp
        Discovering distributions should succeed even if
        there is an invalid path on sys.path.
        N)r=   r
   r    r   r   r   Útest_discoveryÔ   s   zMissingSysPath.test_discoveryN)r)   r*   r+   rL   r‹   r   r   r   r   r‰   Ñ   s    r‰   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚInaccessibleSysPathz/access-deniedc                    s,   t t| ƒ ¡  |  ¡  | jj| jdd� d S )Nr   )Ú	perm_bits)ÚsuperrŒ   ÚsetUpÚsetUpPyfakefsÚfsÚ
create_dirrL   r    ©Ú	__class__r   r   r�   ß   r:   zInaccessibleSysPath.setUpc                 C   s   t t ¡ ƒ dS rŠ   )rx   r=   r
   r    r   r   r   r‹   ä   s   z"InaccessibleSysPath.test_discovery)r)   r*   r+   rL   r�   r‹   Ú__classcell__r   r   r“   r   rŒ   Ü   s    rŒ   c                       sT   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
‡  ZS )ÚTestEntryPointsc                    s$   t t| ƒj|Ž  t ddd¡| _d S )Nr?   r;   r@   )rŽ   r–   Ú__init__r=   r   r8   )r   Úargsr“   r   r   r—   í   s   zTestEntryPoints.__init__c                 C   s$   t  t  | j¡¡}|| jksJ ‚d S r%   )ÚpickleÚloadsÚdumpsr8   )r   Úrevivedr   r   r   Útest_entry_point_pickleableñ   s   z+TestEntryPoints.test_entry_point_pickleablec                 C   s8   |   t¡� d| j_W d  ƒ dS 1 sw   Y  dS )zEntryPoints should be immutableÚbadactorN)r   ÚAttributeErrorr8   r?   r    r   r   r   Útest_immutableõ   s   
"ÿzTestEntryPoints.test_immutablec                 C   s:   dt | jƒv s	J ‚dt | jƒv sJ ‚dt | jƒv sJ ‚d S )Nr   zname=z'name')Úreprr8   r    r   r   r   Ú	test_reprú   s   zTestEntryPoints.test_reprc                 C   s   t | jƒ dS )zEntryPoints should be hashableN)Úhashr8   r    r   r   r   Útest_hashableÿ   s   zTestEntryPoints.test_hashablec                 C   s<   |   t¡� t | j¡ W d  ƒ dS 1 sw   Y  dS )zI
        json should not expect to be able to dump an EntryPoint
        N)r   Ú	ExceptionÚjsonr›   r8   r    r   r   r   Útest_json_dump  s   "ÿzTestEntryPoints.test_json_dumpc                 C   s   | j jdksJ ‚d S )Nr;   )r8   Úmoduler    r   r   r   Útest_module
  ó   zTestEntryPoints.test_modulec                 C   s   | j jd u sJ ‚d S r%   )r8   Úattrr    r   r   r   Ú	test_attr  rª   zTestEntryPoints.test_attr)r)   r*   r+   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S )Ú
FileSystemc                 C   s&   t j|  ¡ i i| jd� ttƒ ƒ dS )zb
        Ensure a Unicode subdirectory of a directory on sys.path
        does not crash.
        )ÚprefixN)r   Úbuild_filesÚunicode_filenamerL   rx   r
   r    r   r   r   Útest_unicode_dir_on_sys_path  s
   
þz'FileSystem.test_unicode_dir_on_sys_pathN)r)   r*   r+   r±   r   r   r   r   r­     s    r­   ),Ú
__future__r   r   r¦   r™   rd   Úunittestr/   r=   Ú!pyfakefs.fake_filesystem_unittestÚfake_filesystem_unittestÚffsÚ r   r   r   r   r	   r
   r   r   r   Úbuiltinsr   r   r.   Ú__builtin__r   ÚDistInfoPkgÚTestCaser   r,   Ú	OnSysPathÚSiteDirrB   r[   Ú
EggInfoPkgrp   r‚   r‰   rŒ   r–   ÚFileBuilderr­   r   r   r   r   Ú<module>   sD   (ÿ
ÿ.*þ
%þ