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   s   t d}d S )Nzdistinfo-pkg)r   	from_name)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__Zversion_patternr   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}d S )Nr'   zimportlib.metadatagrp)namer)   group)r   )r   r'   r   r   r   test_resolve_without_attr8   s    z%ImportTests.test_resolve_without_attrN)r   r   r   r    r(   r*   r.   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}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.
        N)r:   r8   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-infor0   r1   r2   NZCherryPyr3   r7   r   r   r   pkg_with_mixed_caseX   s    (z*NameNormalizationTests.pkg_with_mixed_casec                 C   s   |  | j}dS )zG
        Ensure the metadata loads when queried with any case.
        N)r>   r8   r;   r   r   r    test_dist_name_found_as_any_casee   s    z7NameNormalizationTests.test_dist_name_found_as_any_caseN)r   r   r   staticmethodr:   r=   r>   r?   r   r   r   r   r/   A   s   

r/   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-infor0   r1   utf-8encodingu   Description: pôrˈtend
Nportendr3   r8   r9   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.
        rB   r0   r1   rC   rD   uK   
                Name: portend

                pôrˈtend
                NrF   )r4   r5   r6   textwrapdedentlstriprG   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 S r   )rI   r8   r
   r   r<   metar   r   r   test_metadata_loads   s    z!NonASCIITests.test_metadata_loadsc                 C   s   |  | j}t|}d S r   )rM   r8   r
   rN   r   r   r   test_metadata_loads_egg_info   s    z*NonASCIITests.test_metadata_loads_egg_infoN)r   r   r   r@   rI   rM   rP   rQ   r   r   r   r   rA   o   s   

rA   c                   @   s   e Zd Zdd Zdd ZdS )DiscoveryTestsc                 C   s   t t }d S r   )listr   )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)contextr,   )r   
ValueErrorrS   r   r   r   r   r   test_invalid_usage   s    z!DiscoveryTests.test_invalid_usageN)r   r   r   rT   rX   r   r   r   r   rR      s   rR   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)r8   joinpathr4   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)r8   rZ   r4   Zadd_sys_pathr   r   r   )r   Zeggr   r   r   test_egg   s
    zDirectoryTest.test_eggN)r   r   r   r[   r\   r   r   r   r   rY      s   rY   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   r8   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   )Z	perm_bits)superr`   setUpZsetUpPyfakefsfsZ
create_dirr8   r   	__class__r   r   rb      s    zInaccessibleSysPath.setUpc                 C   s   t tj  dS r^   )rS   r   r
   r   r   r   r   r   r_      s    z"InaccessibleSysPath.test_discovery)r   r   r   r8   rb   r_   __classcell__r   r   rd   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jddd| _d S )Nr,   r)   r-   )ra   rg   __init__r   r
   r   r'   )r   argsrd   r   r   rh      s    zTestEntryPoints.__init__c                 C   s   t t | 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'   r,   r   r   r   r   test_immutable   s    zTestEntryPoints.test_immutablec                 C   s   d S r   r   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jsonrl   r'   r   r   r   r   test_json_dump   s    zTestEntryPoints.test_json_dumpc                 C   s   d S r   r   r   r   r   r   test_module   s    zTestEntryPoints.test_modulec                 C   s   d S r   r   r   r   r   r   	test_attr   s    zTestEntryPoints.test_attr)r   r   r   rh   rm   ro   rp   rr   ru   rv   rw   rf   r   r   rd   r   rg      s   rg   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_filenamer8   rS   r   r   r   r   r   test_unicode_dir_on_sys_path  s
    
z'FileSystem.test_unicode_dir_on_sys_pathN)r   r   r   rz   r   r   r   r   rx     s   rx   )%rert   rj   rJ   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SiteDirr/   rA   Z
EggInfoPkgrR   rY   r]   r`   rg   ZFileBuilderrx   r   r   r   r   <module>   s:   $
.*%
