a
    3j                      @   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zd dlmZ	 W n e
y^   ddlmZ	 Y n0 ddlmZ d dlmZmZmZmZmZmZm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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 )    N   )fake_filesystem_unittest)fixtures)Distribution
EntryPointPackageNotFoundErrordistributionsentry_pointsmetadataversionc                   @   s(   e Zd Z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   strrematchversion_pattern)selfdist r   Y/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_importlib/test_main.pytest_retrieves_version_of_self   s    
z)BasicTests.test_retrieves_version_of_selfc                 C   s8   |  t td W d    n1 s*0    Y  d S )Nz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   s   |  tt d S N)ZassertIsInstancer   typer   r   r   r   test_new_style_classes#   s    z!BasicTests.test_new_style_classesN)__name__
__module____qualname__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   s8   |  t td W d    n1 s*0    Y  d S )NZdoes_not_exist)r   ImportError	importlibimport_moduler   r   r   r   test_import_nonexistent_module(   s    z*ImportTests.test_import_nonexistent_modulec                 C   s,   t t d }|d }| | jd d S )Nentriesmain)dictr	   assertEqualloadr   r   r'   epr   r   r   test_resolve.   s    zImportTests.test_resolvec                 C   s(   t t d }|d }| |jd d S )Nr'   zns:subzmod:main)r)   r	   r*   valuer,   r   r   r   "test_entrypoint_with_colon_in_name3   s    z.ImportTests.test_entrypoint_with_colon_in_namec                 C   s$   t dddd}| tju s J d S )Nr-   zimportlib.metadatagrp)namer/   group)r   r+   r$   r
   )r   r-   r   r   r   test_resolve_without_attr8   s    z%ImportTests.test_resolve_without_attrN)r   r    r!   r&   r.   r0   r4   r   r   r   r   r"   '   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   sP   | d }|   |d }|d}|d W d   n1 sB0    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
   Zstrmr   r   r   pkg_with_dashesC   s    (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)r@   r>   r   r   pkg_namer   r   r   -test_dashes_in_dist_name_found_as_underscoresP   s    zDNameNormalizationTests.test_dashes_in_dist_name_found_as_underscoresc                 C   sP   | d }|   |d }|d}|d W d   n1 sB0    Y  dS )z\
        Create minimal metadata for a package with mixed case
        in the name.
        zCherryPy.dist-infor6   r7   r8   NZCherryPyr9   r=   r   r   r   pkg_with_mixed_caseX   s    (z*NameNormalizationTests.pkg_with_mixed_casec                 C   sH   |  | j}t|dksJ t| dks0J t| dksDJ dS )zG
        Ensure the metadata loads when queried with any case.
        rA   N)rE   r>   r   lowerupperrB   r   r   r    test_dist_name_found_as_any_casee   s    z7NameNormalizationTests.test_dist_name_found_as_any_caseN)r   r    r!   staticmethodr@   rD   rE   rH   r   r   r   r   r5   A   s   

r5   c                   @   s4   e Zd Zedd Zedd Zdd Zdd Zd	S )
NonASCIITestsc                 C   sT   | d }|   |d }|jddd}|d W d   n1 sF0    Y  dS )	zb
        Create minimal metadata for a package with non-ASCII in
        the description.
        portend.dist-infor6   r7   utf-8encodingu   Description: pôrˈtend
Nportendr9   r>   r?   r
   fpr   r   r   pkg_with_non_ascii_descriptionp   s    (z,NonASCIITests.pkg_with_non_ascii_descriptionc                 C   s^   | d }|   |d }|jddd$}|td  W d   n1 sP0    Y  dS )	zl
        Create minimal metadata for an egg-info package with
        non-ASCII in the description.
        rK   r6   r7   rL   rM   uK   
                Name: portend

                pôrˈtend
                NrO   )r:   r;   r<   textwrapdedentlstriprP   r   r   r   'pkg_with_non_ascii_description_egg_info}   s    2z5NonASCIITests.pkg_with_non_ascii_description_egg_infoc                 C   s(   |  | j}t|}|d dks$J d S )NZDescriptionu
   pôrˈtend)rR   r>   r
   r   rC   metar   r   r   test_metadata_loads   s    z!NonASCIITests.test_metadata_loadsc                 C   s(   |  | j}t|}| dks$J d S )Nu   pôrˈtend
)rV   r>   r
   Zget_payloadrW   r   r   r   test_metadata_loads_egg_info   s    z*NonASCIITests.test_metadata_loads_egg_infoN)r   r    r!   rI   rR   rV   rY   rZ   r   r   r   r   rJ   o   s   

rJ   c                   @   s   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 s6J tdd |D sLJ 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   s   | ]}|j d  dkV  qdS )Namezegginfo-pkgNr
   r\   r   r   r   r^      s   c                 s   s   | ]}|j d  dkV  qdS )r_   r   Nr`   r\   r   r   r   r^      s   )listr   allany)r   Zdistsr   r   r   test_package_discovery   s    
z%DiscoveryTests.test_package_discoveryc                 C   s>   |  t  ttddd W d    n1 s00    Y  d S )NZ	somethingelse)contextr2   )r   
ValueErrorra   r   r   r   r   r   test_invalid_usage   s    z!DiscoveryTests.test_invalid_usageN)r   r    r!   rd   rh   r   r   r   r   r[      s   r[   c                   @   s   e Zd Zdd Zdd ZdS )DirectoryTestc                 C   sF   | j d  | t td W d    n1 s80    Y  d S )NzEGG-INFOzunknown-package)r>   joinpathr:   r   r   r   r   r   r   r   test_egg_info   s    zDirectoryTest.test_egg_infoc              	   C   st   | j d}|  | |B | t td W d    n1 sH0    Y  W d    n1 sf0    Y  d S )Nzfoo-3.6.eggZfoo)r>   rj   r:   Zadd_sys_pathr   r   r   )r   Zeggr   r   r   test_egg   s
    zDirectoryTest.test_eggN)r   r    r!   rk   rl   r   r   r   r   ri      s   ri   c                   @   s   e Zd ZdZdd ZdS )MissingSysPathz/does-not-existc                 C   s   t j  dS zp
        Discovering distributions should succeed even if
        there is an invalid path on sys.path.
        N)r$   r
   r   r   r   r   r   test_discovery   s    zMissingSysPath.test_discoveryN)r   r    r!   r>   ro   r   r   r   r   rm      s   rm   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   )Z	perm_bits)superrp   setUpZsetUpPyfakefsfsZ
create_dirr>   r   	__class__r   r   rr      s    zInaccessibleSysPath.setUpc                 C   s   t tj  dS rn   )ra   r$   r
   r   r   r   r   r   ro      s    z"InaccessibleSysPath.test_discovery)r   r    r!   r>   rr   ro   __classcell__r   r   rt   r   rp      s   rp   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jddd| _d S )Nr2   r/   r3   )rq   rw   __init__r$   r
   r   r-   )r   argsrt   r   r   rx      s    zTestEntryPoints.__init__c                 C   s$   t t | j}|| jks J d S r   )pickleloadsdumpsr-   )r   Zrevivedr   r   r   test_entry_point_pickleable   s    z+TestEntryPoints.test_entry_point_pickleablec                 C   s6   |  t d| j_W d   n1 s(0    Y  dS )zEntryPoints should be immutableZbadactorN)r   AttributeErrorr-   r2   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 s6J d S )Nr   zname=z'name')reprr-   r   r   r   r   	test_repr   s    zTestEntryPoints.test_reprc                 C   s   t | j dS )zEntryPoints should be hashableN)hashr-   r   r   r   r   test_hashable   s    zTestEntryPoints.test_hashablec                 C   s:   |  t t| j W d   n1 s,0    Y  dS )zI
        json should not expect to be able to dump an EntryPoint
        N)r   	Exceptionjsonr|   r-   r   r   r   r   test_json_dump   s    zTestEntryPoints.test_json_dumpc                 C   s   | j jdksJ d S )Nr/   )r-   moduler   r   r   r   test_module   s    zTestEntryPoints.test_modulec                 C   s   | j jd u sJ d S r   )r-   attrr   r   r   r   	test_attr   s    zTestEntryPoints.test_attr)r   r    r!   rx   r}   r   r   r   r   r   r   rv   r   r   rt   r   rw      s   rw   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   Zbuild_filesZunicode_filenamer>   ra   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   )%r   r   rz   rS   Zunittestimportlib.metadatar$   Z!pyfakefs.fake_filesystem_unittestr   Zffsr#   Zstubs r   r   r   r   r   r	   r
   r   ZDistInfoPkgZTestCaser   r"   Z	OnSysPathZSiteDirr5   rJ   Z
EggInfoPkgr[   ri   rm   rp   rw   ZFileBuilderr   r   r   r   r   <module>   s:   $
.*%
