a
    3j                     @   s   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 G dd dejejejejZG dd	 d	ejejZdS )
    N)Iterator   )fixtures)DistributionPackageNotFoundErrordistributionentry_pointsfilesmetadatarequiresversionc                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	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d"S )#APITestsz\d+\.\d+(\.\d)?c                 C   s,   t d}t|tsJ t| j|s(J d S Negginfo-pkgr   
isinstancestrrematchversion_patternselfZpkg_version r   a/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_importlib/test_metadata_api.pytest_retrieves_version_of_self   s    z'APITests.test_retrieves_version_of_selfc                 C   s,   t d}t|tsJ t| j|s(J d S Ndistinfo-pkgr   r   r   r   r   &test_retrieves_version_of_distinfo_pkg   s    z/APITests.test_retrieves_version_of_distinfo_pkgc                 C   s6   |  t td W d    n1 s(0    Y  d S )Nzdoes-not-exist)ZassertRaisesr   r   r   r   r   r   test_for_name_does_not_exist    s    z%APITests.test_for_name_does_not_existc                 C   s   |  tdd d d S )Nr   top_level.txtmod)assertEqualr   	read_textstripr   r   r   r   test_for_top_level$   s    zAPITests.test_for_top_levelc                 C   s*   dd t dD d }| | d d S )Nc                 S   s   g | ]}|j d kr|qS )r    name).0pathr   r   r   
<listcomp>*   s   
z+APITests.test_read_text.<locals>.<listcomp>r   r   zmod
)r	   r"   r#   )r   Z	top_levelr   r   r   test_read_text)   s    zAPITests.test_read_textc                 C   s6   t t d }|d }| |jd | |jg  d S )Nentriesmainzmod:main)dictr   r"   valueextras)r   r,   Zepr   r   r   test_entry_points0   s    zAPITests.test_entry_pointsc                 C   sR   t d}|d dksJ |d dks(J |d dks8J |d}d|v sNJ d S )	Nr   Zauthorz	Steven MaLICENSEZUnknownNameZ
Classifierz*Topic :: Software Development :: Libraries)r
   Zget_all)r   ZmdZclassifiersr   r   r   test_metadata_for_this_package6   s    
z'APITests.test_metadata_for_this_packagec                 C   s   | d j }| D ]}|j |ks J |jr2|jjs2J |jrH|jjdksHJ |jr\|jdks\J |  slJ t| t	s~J |j
dr|  qd S )Nr   Zsha256z.py)roothashr/   modesizeZlocateexistsr   Zread_binarybytesr'   endswithr#   )r	   r5   filer   r   r   _test_files>   s    
zAPITests._test_filesc                 C   s0   | j }dd tdD d }|t|jd d S )Nc                 S   s   g | ]}|j d kr|qS )zmod.pyr&   )r(   pr   r   r   r*   N   s   
z0APITests.test_file_hash_repr.<locals>.<listcomp>r   r   z!<FileHash mode: sha256 value: .*>)assertRegexr	   reprr6   )r   r?   utilr   r   r   test_file_hash_reprK   s    zAPITests.test_file_hash_reprc                 C   s   |  td d S r   r=   r	   r   r   r   r   test_files_dist_infoV   s    zAPITests.test_files_dist_infoc                 C   s   |  td d S r   rC   r   r   r   r   test_files_egg_infoY   s    zAPITests.test_files_egg_infoc                 C   s   |  tdd d S )Negginfo-filez0.1)r"   r   r   r   r   r   test_version_egg_info_file\   s    z#APITests.test_version_egg_info_filec                 C   s   t d}| | d S )NrF   )r   ZassertIsNone)r   Zrequirementsr   r   r   test_requires_egg_info_file_   s    z$APITests.test_requires_egg_info_filec                 C   s2   t d}t|dksJ tdd |D s.J d S )Nr      c                 s   s   | ]}|d kV  qdS )z%wheel >= 1.0; python_version >= "2.7"Nr   )r(   Zdepr   r   r   	<genexpr>f   s   z2APITests.test_requires_egg_info.<locals>.<genexpr>)r   lenanyr   depsr   r   r   test_requires_egg_infoc   s
    zAPITests.test_requires_egg_infoc                 C   s@   t d}t|dksJ t|s$J d|v s0J d|v s<J d S )Nr   rI   zwheel >= 1.0zpytest; extra == 'test')r   rK   allrM   r   r   r   test_requires_dist_infok   s
    z APITests.test_requires_dist_infoc                 C   s0   t d}tt|}g d}||ks,J d S )Na  
            dep1
            dep2

            [:python_version < "3"]
            dep3

            [extra1]
            dep4
            dep6@ git+https://example.com/python/dep.git@v1.0.0

            [extra2:python_version < "3"]
            dep5
            )Zdep1Zdep2zdep3; python_version < "3"zdep4; extra == "extra1"z2dep5; (python_version < "3") and extra == "extra2"zGdep6@ git+https://example.com/python/dep.git@v1.0.0 ; extra == "extra1")textwrapdedentsortedr   Z_deps_from_requires_text)r   r   rN   Zexpectedr   r   r   $test_more_complex_deps_requires_textr   s    
z-APITests.test_more_complex_deps_requires_textN)__name__
__module____qualname__r   r   r   r   r%   r+   r1   r4   staticmethodr=   rB   rD   rE   rG   rH   rO   rQ   rU   r   r   r   r   r      s$   
r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )OffSysPathTestsc                 C   s.   t jt| jgd}tdd |D s*J d S )N)r)   c                 s   s   | ]}|j d  dkV  qdS )r3   r   N)r
   )r(   distr   r   r   rJ      s   zIOffSysPathTests.test_find_distributions_specified_path.<locals>.<genexpr>)r   Zdiscoverr   site_dirrL   )r   Zdistsr   r   r   &test_find_distributions_specified_path   s    z6OffSysPathTests.test_find_distributions_specified_pathc                 C   s&   | j d }t|}|jdks"J dS )zBDemonstrate how to load metadata direct from a directory.
        distinfo_pkg-1.0.0.dist-info1.0.0N)r\   r   atr   r   Zdist_info_pathr[   r   r   r   test_distribution_at_pathlib   s    

z,OffSysPathTests.test_distribution_at_pathlibc                 C   s*   | j d }tt|}|jdks&J d S )Nr^   r_   )r\   r   r`   r   r   ra   r   r   r   test_distribution_at_str   s    
z(OffSysPathTests.test_distribution_at_strN)rV   rW   rX   r]   rb   rc   r   r   r   r   rZ      s   rZ   )r   rR   Zunittestcollections.abcr    r   importlib.metadatar   r   r   r   r	   r
   r   r   Z
EggInfoPkgZDistInfoPkgZEggInfoFileZTestCaser   ZDistInfoPkgOffPathrZ   r   r   r   r   <module>   s   (
 