o
    g/                     @   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 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__folderload_fixture__file__parentr	   r
   self	__class__ \/var/www/visachat/venv/lib/python3.10/site-packages/importlib_resources/tests/test_reader.pyr      s   
zMultiplexedPathTest.setUpc                 C   s6   |  t t  W d    d S 1 sw   Y  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 d    d S 1 sw   Y  d S )Nbinary.file)r   NotADirectoryErrorr   r   r   r   r   r   test_init_file   s   "z"MultiplexedPathTest.test_init_filec              	   C   sR   dd t | j D }z|d W n ttfy   Y nw | |h d d S )Nc                 S      h | ]}|j qS r   name.0pathr   r   r   	<setcomp>   s    z3MultiplexedPathTest.test_iterdir.<locals>.<setcomp>__pycache__>   subdirectory
utf-8.filer   utf-16.file)r   r   iterdirremoveKeyError
ValueErrorassertEqual)r   contentsr   r   r   test_iterdir   s   z MultiplexedPathTest.test_iterdirc              
   C   s^   dd t | j| j D }dD ]}z|| W q ttfy$   Y qw | |h d d S )Nc                 S   r"   r   r#   r%   r   r   r   r(   '   s    z=MultiplexedPathTest.test_iterdir_duplicate.<locals>.<setcomp>)r)   z__init__.pyc>   __init__.pyr*   r+   r   r,   )r   r   r	   r-   r.   r/   r0   r1   )r   r2   r.   r   r   r   test_iterdir_duplicate&   s   z*MultiplexedPathTest.test_iterdir_duplicatec                 C      |  t| j d d S )NT)r1   r   r   is_dirr   r   r   r   test_is_dir4      zMultiplexedPathTest.test_is_dirc                 C   r6   )NF)r1   r   r   is_filer   r   r   r   test_is_file7   r9   z MultiplexedPathTest.test_is_filec                 C   s   t | j}| t |  W d    n1 sw   Y  | t |  W d    n1 s2w   Y  | t |  W d    d S 1 sLw   Y  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s1J dt |v s9J dt |v sAJ | t |dt|d d  tj	
dd | | | d S )Nr   r   r   r*   r	   	imaginary)strr   r   r   r	   r1   joinpathlenosr'   join
isinstance)r   prefixr'   subr   r   r   test_join_pathC   s   
z"MultiplexedPathTest.test_join_pathc                 C   s    t | j}|d rJ d S )Nzimaginary/foo.py)r   r   rC   existsr?   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*   	subsubdirr   r
   )rB   r
   r   r   r	   assertIsInstancerC   r1   rD   rE   r'   rF   )r   rH   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(''))r1   reprr   r   r   r   r   r   	test_repra   s   zMultiplexedPathTest.test_reprc                 C   s"   |  t| jjtj| j d S r   )r1   r   r   r$   rE   r'   basenamer   r   r   r   	test_nameg   s   
zMultiplexedPathTest.test_name)__name__
__module____qualname__MODULEr   r   r!   r3   r5   r8   r;   r@   rJ   rL   rO   rS   rU   __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 d    d S 1 sw   Y  d S )Npath1path2)r   r0   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   rA   )r   r   __spec__submodule_search_locationsr   r   r1   resource_pathrE   r'   rF   )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   rP   rQ   )
r   r   r_   r`   r   rN   filesr   r1   rR   )r   rb   rc   r   r   r   
test_files   s    zNamespaceReaderTest.test_filesN)rV   rW   rX   rY   r^   rd   rf   r   r   r   r   r[   n   s
    r[   __main__)os.pathrE   r   unittest	importlibr   importlib_resources.readersr   r    r   	DiskSetupTestCaser   r[   rV   mainr   r   r   r   <module>   s    c