a
    i‚j/  ã                   @   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__© úc/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/importlib_resources/tests/test_reader.pyr      s    
zMultiplexedPathTest.setUpc                 C   s4   |   t¡ tƒ  W d   ƒ n1 s&0    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   ƒ n1 s.0    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0 |  |h d£¡ d S )Nc                 S   s   h | ]
}|j ’qS r   ©Úname©Ú.0Úpathr   r   r   Ú	<setcomp>   ó    z3MultiplexedPathTest.test_iterdir.<locals>.<setcomp>Ú__pycache__>   r   úutf-16.fileú
utf-8.fileÚsubdirectory)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yH   Y q 0 q |  |h d£¡ 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__.pyc>   r   r)   r*   r+   z__init__.py)r   r   r	   r,   r-   r.   r/   r0   )r   r1   r-   r   r   r   Útest_iterdir_duplicate&   s    ÿþz*MultiplexedPathTest.test_iterdir_duplicatec                 C   s   |   t| jƒ ¡ d¡ d S )NT)r0   r   r   Úis_dirr   r   r   r   Útest_is_dir4   s    zMultiplexedPathTest.test_is_dirc                 C   s   |   t| jƒ ¡ d¡ d S )NF)r0   r   r   Úis_filer   r   r   r   Útest_is_file7   s    z MultiplexedPathTest.test_is_filec                 C   s¤   t | jƒ}|  t¡ | ¡  W d   ƒ n1 s20    Y  |  t¡ | ¡  W d   ƒ n1 sd0    Y  |  t¡ | ¡  W d   ƒ n1 s–0    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ƒsbJ ‚dt |ƒv srJ ‚dt |ƒv s‚J ‚|  t | d¡ƒt|ƒd d … tj	 
dd¡¡ |  | ¡ |¡ d S )Nr   r   r   r+   r	   Ú	imaginary)Ústrr   r   r   r	   r0   Ú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   r?   Ú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+   Z	subsubdirr   r
   )r>   r
   r   r   r	   ÚassertIsInstancer?   r0   r@   rA   r%   rB   )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('ú'))r0   Úreprr   r   r   r   r   r   Ú	test_repra   s    þzMultiplexedPathTest.test_reprc                 C   s"   |   t| jƒjtj | j¡¡ d S r   )r0   r   r   r"   rA   r%   Úbasenamer   r   r   r   Ú	test_nameg   s    
þzMultiplexedPathTest.test_name)Ú__name__Ú
__module__Ú__qualname__ÚMODULEr   r   r    r2   r3   r5   r7   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 d   ƒ n1 s,0    Y  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   r0   Úresource_pathrA   r%   rB   )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   r0   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.pathrA   r   ZunittestÚ	importlibr   Zimportlib_resources.readersr   r   Ú r   Z	DiskSetupZTestCaser   rV   rQ   Úmainr   r   r   r   Ú<module>   s   c