U
    ?h/                     @   s   d dl Zd dlZd dlZd dlmZ d dlmZmZ ddl	m
Z
 G dd de
jejZG dd	 d	e
jejZed
kr|e  dS )    N)import_module)MultiplexedPathNamespaceReader   )utilc                       s   e Zd 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dd Zdd Zdd Zdd Zdd Z  ZS )MultiplexedPathTestnamespacedata01c                    sN   t    t| jjd | _t| djj	| _
t| djj	| _d S )Nr   data01data02)supersetUppathlibPathdata__path__folderZload_fixture__file__parentr	   r
   self	__class__ W/var/www/html/venv/lib/python3.8/site-packages/importlib_resources/tests/test_reader.pyr      s    
zMultiplexedPathTest.setUpc              	   C   s    |  t t  W 5 Q R X d S N)assertRaisesFileNotFoundErrorr   r   r   r   r   test_init_no_paths   s    z&MultiplexedPathTest.test_init_no_pathsc              	   C   s(   |  t t| jd  W 5 Q R X d S )Nbinary.file)r   NotADirectoryErrorr   r   r   r   r   r   test_init_file   s    z"MultiplexedPathTest.test_init_filec              	   C   sX   dd t | j D }z|d W n ttfk
r>   Y nX | |ddddh d S )Nc                 S   s   h | ]
}|j qS r   name.0pathr   r   r   	<setcomp>   s     z3MultiplexedPathTest.test_iterdir.<locals>.<setcomp>__pycache__subdirectoryr   utf-16.file
utf-8.file)r   r   iterdirremoveKeyError
ValueErrorassertEqual)r   contentsr   r   r   test_iterdir   s     
z MultiplexedPathTest.test_iterdirc              
   C   sh   dd t | j| j D }dD ],}z|| W q  ttfk
rJ   Y q X q | |dddddh d S )	Nc                 S   s   h | ]
}|j qS r   r!   r#   r   r   r   r&   '   s    z=MultiplexedPathTest.test_iterdir_duplicate.<locals>.<setcomp>)r'   z__init__.pycz__init__.pyr   r(   r)   r*   )r   r   r	   r+   r,   r-   r.   r/   )r   r0   r,   r   r   r   test_iterdir_duplicate&   s    z*MultiplexedPathTest.test_iterdir_duplicatec                 C   s   |  t| j d d S )NT)r/   r   r   is_dirr   r   r   r   test_is_dir4   s    zMultiplexedPathTest.test_is_dirc                 C   s   |  t| j d d S )NF)r/   r   r   is_filer   r   r   r   test_is_file7   s    z MultiplexedPathTest.test_is_filec              	   C   sh   t | j}| t |  W 5 Q R X | t |  W 5 Q R X | t |  W 5 Q R X d S r   )r   r   r   r   
read_bytes	read_textopenr   r%   r   r   r   test_open_file:   s    
z"MultiplexedPathTest.test_open_filec                 C   s   t | jj}t| j| j}| t |dt|d d  tj	
dd |d}t|tsbtdt |ksrtdt |kst| t |dt|d d  tj	
dd | | | d S )Nr   r   r   r(   r	   	imaginary)strr   r   r   r	   r/   joinpathlenosr%   join
isinstanceAssertionError)r   prefixr%   subr   r   r   test_join_pathC   s    
z"MultiplexedPathTest.test_join_pathc                 C   s    t | j}|d rtd S )Nzimaginary/foo.py)r   r   r>   existsrC   r:   r   r   r   test_join_path_compoundT   s    
z+MultiplexedPathTest.test_join_path_compoundc                 C   sd   t | jj}t| j| j}| |dt | t |ddt|d d  t	j
ddd d S )Nr(   Z	subsubdirr   r
   )r=   r
   r   r   r	   assertIsInstancer>   r/   r?   r@   r%   rA   )r   rD   r%   r   r   r   test_join_path_common_subdirX   s    z0MultiplexedPathTest.test_join_path_common_subdirc                 C   s$   |  tt| jd| j d d S )NMultiplexedPath(''))r/   reprr   r   r   r   r   r   	test_repra   s    zMultiplexedPathTest.test_reprc                 C   s"   |  t| jjtj| j d S r   )r/   r   r   r"   r@   r%   basenamer   r   r   r   	test_nameg   s    
zMultiplexedPathTest.test_name)__name__
__module____qualname__MODULEr   r   r    r1   r2   r4   r6   r;   rF   rH   rJ   rN   rP   __classcell__r   r   r   r   r      s   
		r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	NamespaceReaderTestr   c              	   C   s&   |  t tddg W 5 Q R X d S )NZpath1Zpath2)r   r.   r   r   r   r   r   test_init_errorq   s    z#NamespaceReaderTest.test_init_errorc                 C   s\   t d}t|jj}| jjd }| |dtj	
|d | |dtj	
|d d S )Nr   r   r   r<   )r   r   __spec__submodule_search_locationsr   r   r/   resource_pathr@   r%   rA   )r   r   readerrootr   r   r   test_resource_pathu   s      z&NamespaceReaderTest.test_resource_pathc                 C   sJ   t | jjj}| jjd }| | t | t	| d| d d S )Nr   rK   rL   )
r   r   rX   rY   r   rI   filesr   r/   rM   )r   r[   r\   r   r   r   
test_files   s    zNamespaceReaderTest.test_filesN)rQ   rR   rS   rT   rW   r]   r_   r   r   r   r   rV   n   s   rV   __main__)os.pathr@   r   Zunittest	importlibr   Zimportlib_resources.readersr   r    r   Z	DiskSetupZTestCaser   rV   rQ   mainr   r   r   r   <module>   s   c