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}d S Negginfo-pkgr   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}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   s   t d}|d}d S )Nr   Z
Classifier)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dr|  qd S )Nr   z.py)rootr"   endswithr   )r	   r.   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	   reprhash)r   r3   utilr   r   r   test_file_hash_reprK   s    zAPITests.test_file_hash_reprc                 C   s   |  td d S r   r1   r	   r   r   r   r   test_files_dist_infoV   s    zAPITests.test_files_dist_infoc                 C   s   |  td d S r   r8   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 )Nr;   )r   ZassertIsNone)r   Zrequirementsr   r   r   test_requires_egg_info_file_   s    z$APITests.test_requires_egg_info_filec                 C   s   t d}d S r   r   r   depsr   r   r   test_requires_egg_infoc   s    zAPITests.test_requires_egg_infoc                 C   s   t d}d S r   r>   r?   r   r   r   test_requires_dist_infok   s    z APITests.test_requires_dist_infoc                 C   s$   t d}tt|}g d}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   r@   Zexpectedr   r   r   $test_more_complex_deps_requires_textr   s    
z-APITests.test_more_complex_deps_requires_textN)__name__
__module____qualname__Zversion_patternr   r   r   r    r&   r,   r-   staticmethodr1   r7   r9   r:   r<   r=   rA   rB   rF   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}d S )N)r$   )r   Zdiscoverstrsite_dir)r   Zdistsr   r   r   &test_find_distributions_specified_path   s    z6OffSysPathTests.test_find_distributions_specified_pathc                 C   s   | j d }t|}d S Nzdistinfo_pkg-1.0.0.dist-info)rM   r   atr   Zdist_info_pathdistr   r   r   test_distribution_at_pathlib   s    

z,OffSysPathTests.test_distribution_at_pathlibc                 C   s   | j d }tt|}d S rO   )rM   r   rP   rL   rQ   r   r   r   test_distribution_at_str   s    
z(OffSysPathTests.test_distribution_at_strN)rG   rH   rI   rN   rS   rT   r   r   r   r   rK      s   rK   )rerC   Zunittestcollections.abcr    r   importlib.metadatar   r   r   r   r	   r
   r   r   Z
EggInfoPkgZDistInfoPkgZEggInfoFileZTestCaser   ZDistInfoPkgOffPathrK   r   r   r   r   <module>   s   (
 