o
    g                     @   s2  d dl Z d dlmZ d dlZddlmZ G dd dZG dd deeje j	Z
G d	d
 d
eeje j	Zdd 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	ZG dd deje j	ZG dd deje j	ZG dd dZG dd dejee j	ZG dd dejee j	Zedkre   dS dS )    N)import_module   )utilc                   @   s$   e Zd Zdd Zdd Zdd ZdS )ResourceTestsc                 C   "   t | jd }| |  d S )Nbinary.file)	resourcesfilesdata
assertTrueis_fileselftarget r   ^/var/www/visachat/venv/lib/python3.10/site-packages/importlib_resources/tests/test_resource.pytest_is_file_exists      z!ResourceTests.test_is_file_existsc                 C   r   )Nz
not-a-file)r   r	   r
   assertFalser   r   r   r   r   test_is_file_missing   r   z"ResourceTests.test_is_file_missingc                 C   s0   t | jd }| |  | |  d S )Nsubdirectory)r   r	   r
   r   r   r   is_dirr   r   r   r   test_is_dir   s   zResourceTests.test_is_dirN)__name__
__module____qualname__r   r   r   r   r   r   r   r   	   s    r   c                   @      e Zd ZdS )ResourceDiskTestsNr   r   r   r   r   r   r   r          r   c                   @   r   )ResourceZipTestsNr   r   r   r   r   r       r   r    c                 C   s   dd |   D S )Nc                 S   s   h | ]}|j qS r   name.0itemr   r   r   	<setcomp>#       znames.<locals>.<setcomp>)iterdir)traversabler   r   r   names"   s   r*   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
ResourceLoaderTestsc                 C   s8   t j| j| jjg dd}| tt|h d d S )NABCfilepathcontents>   r-   r.   r/   )r   create_packager
   __file__assertEqualr*   r   r	   r   packager   r   r   test_resource_contents'   s   z*ResourceLoaderTests.test_resource_contentsc                 C   8   t j| j| jjg dd}| t|d  d S )Nr-   r.   r/   zD/EzD/Fr0   r.   )	r   r4   r
   r5   r   r   r	   joinpathr   r7   r   r   r   test_is_file-      z ResourceLoaderTests.test_is_filec                 C   r:   )Nr;   r0   D)	r   r4   r
   r5   r   r   r	   r<   r   r7   r   r   r   r   5   r>   zResourceLoaderTests.test_is_dirc                 C   r:   )Nr;   r0   Z)	r   r4   r
   r5   r   r   r	   r<   r   r7   r   r   r   test_resource_missing=   r>   z)ResourceLoaderTests.test_resource_missingN)r   r   r   r9   r=   r   rA   r   r   r   r   r+   &   s
    r+   c                   @   s   e Zd Zdd ZdS )ResourceCornerCaseTestsc                 C   sZ   t j| j| jjg dd}t |_d|_|j|j_|j|j_| 	t
|d  dS )z
        Test odd ball packages which:
        # 1. Do not have a ResourceReader as a loader
        # 2. Are not on the file system
        # 3. Are not in a zip file
        r,   r0   z/path/which/shall/not/be/namedr-   N)r   r4   r
   r5   object
__loader____spec__loaderoriginr   r   r	   r<   r   )r   moduler   r   r   #test_package_has_no_reader_fallbackG   s   

z;ResourceCornerCaseTests.test_package_has_no_reader_fallbackN)r   r   r   rI   r   r   r   r   rB   F   s    rB   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )ResourceFromZipsTest01c                 C   s&   t d}| t|d  d S Ndata01.subdirectoryr   )r   r   r   r	   r<   r   r   	submoduler   r   r   test_is_submodule_resource[   s   z1ResourceFromZipsTest01.test_is_submodule_resourcec                 C      |  tdd  d S rK   r   r   r	   r<   r   r   r   r   r   $test_read_submodule_resource_by_name_      z;ResourceFromZipsTest01.test_read_submodule_resource_by_namec                 C   s&   t d}| tt|ddh d S NrL   __init__.pyr   )r   r6   r*   r   r	   rM   r   r   r   test_submodule_contentsd   s   z.ResourceFromZipsTest01.test_submodule_contentsc                 C   s   |  ttdddh d S rU   r6   r*   r   r	   rR   r   r   r   test_submodule_contents_by_namej   s   z6ResourceFromZipsTest01.test_submodule_contents_by_namec                 C   s   t t d(}|jdksJ | sJ |d sJ tt| s)J W d    n1 s3w   Y  |j	
 r?J d S )Ndata01r   )r   as_filer	   r"   r   r<   lenlistr(   parentexists)r   r
   r   r   r   test_as_file_directoryp   s   z-ResourceFromZipsTest01.test_as_file_directoryN)r   r   r   rO   rS   rW   rY   r`   r   r   r   r   rJ   Z   s    rJ   c                   @   s   e Zd ZdZdd ZdS )ResourceFromZipsTest02data02c                 C   s8   |  ttdddh |  ttdddh dS )z
        Test thata zip with two unrelated subpackages return
        distinct resources. Ref python/importlib_resources#44.
        z
data02.onerV   zresource1.txtz
data02.twozresource2.txtNrX   rR   r   r   r   test_unrelated_contents|   s   z.ResourceFromZipsTest02.test_unrelated_contentsN)r   r   r   MODULErc   r   r   r   r   ra   y   s    ra   c                   @   sR   e Zd ZdZdd Zdd Zdd Zedd	d
 Z	dd Z
dd Zdd ZdS )DeletingZipsTestz^Having accessed resources in a zip file should not keep an open
    reference to the zip.
    c                 C   s   dd t d D  d S )Nc                 S   s   g | ]}|j qS r   r!   r#   r   r   r   
<listcomp>   r'   zDDeletingZipsTest.test_iterdir_does_not_keep_open.<locals>.<listcomp>rZ   )r   r	   r(   rR   r   r   r   test_iterdir_does_not_keep_open      z0DeletingZipsTest.test_iterdir_does_not_keep_openc                 C      t dd  d S NrZ   r   r   r	   r<   r   rR   r   r   r   test_is_file_does_not_keep_open      z0DeletingZipsTest.test_is_file_does_not_keep_openc                 C   ri   )NrZ   znot-presentrk   rR   r   r   r   'test_is_file_failure_does_not_keep_open   rm   z8DeletingZipsTest.test_is_file_failure_does_not_keep_openzDesired but not supported.c                 C   s   t t dd  d S rj   )r   r[   r	   rR   r   r   r   test_as_file_does_not_keep_open   s   z0DeletingZipsTest.test_as_file_does_not_keep_openc                 C   s   t t dd   dS )zr
        Mimic what certifi does on import to make its bundle
        available for the process duration.
        rZ   r   N)r   r[   r	   	__enter__rR   r   r   r   $test_entered_path_does_not_keep_open   s   z5DeletingZipsTest.test_entered_path_does_not_keep_openc                 C   ri   rj   )r   r	   r<   
read_bytesrR   r   r   r   #test_read_binary_does_not_keep_open   rm   z4DeletingZipsTest.test_read_binary_does_not_keep_openc                 C   s   t ddjdd d S )NrZ   
utf-8.filezutf-8)encoding)r   r	   r<   	read_textrR   r   r   r   !test_read_text_does_not_keep_open   rh   z2DeletingZipsTest.test_read_text_does_not_keep_openN)r   r   r   __doc__rg   rl   rn   unittestskipro   rq   rs   rw   r   r   r   r   re      s    
re   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )ResourceFromNamespaceTestsc                 C   s"   |  ttdd  d S Nnamespacedata01r   )r   r   r	   r   r<   r   rR   r   r   r   rO      s
   z5ResourceFromNamespaceTests.test_is_submodule_resourcec                 C   rP   r|   rQ   rR   r   r   r   rS      rT   z?ResourceFromNamespaceTests.test_read_submodule_resource_by_namec                 C   sH   t ttd}z|d W n	 ty   Y nw | |h d d S Nr}   __pycache__>   utf-16.filer   rt   r   r*   r   r	   r   removeKeyErrorr6   r   r3   r   r   r   rW      s   z2ResourceFromNamespaceTests.test_submodule_contentsc                 C   sD   t td}z|d W n	 ty   Y nw | |h d d S r~   r*   r   r	   r   r   r6   r   r   r   r   rY      s   z:ResourceFromNamespaceTests.test_submodule_contents_by_namec                 C   sF   t ttd}z|d W n	 ty   Y nw | |dh d S Nznamespacedata01.subdirectoryr   r   r   r   r   r   r   test_submodule_sub_contents   s   z6ResourceFromNamespaceTests.test_submodule_sub_contentsc                 C   sB   t td}z|d W n	 ty   Y nw | |dh d S r   r   r   r   r   r   #test_submodule_sub_contents_by_name   s   z>ResourceFromNamespaceTests.test_submodule_sub_contents_by_nameN)	r   r   r   rO   rS   rW   rY   r   r   r   r   r   r   r{      s    

r{   c                   @      e Zd ZdZdS )ResourceFromNamespaceDiskTestsr}   Nr   r   r   rd   r   r   r   r   r          r   c                   @   r   )ResourceFromNamespaceZipTestsr}   Nr   r   r   r   r   r      r   r   __main__)ry   	importlibr   importlib_resourcesr    r   r   	DiskSetupTestCaser   ZipSetupr    r*   r+   rB   rJ   ra   re   r{   r   r   r   mainr   r   r   r   <module>   s6      
2
