o
    g                     @   sx   d dl Zd dlZd dlZd dlZd dlmZ d dlmZm	Z	 G dd dej
ZG dd dej
Zedkr:e  dS dS )	    N)import_module)MultiplexedPathNamespaceReaderc                   @   sh   e Z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d Zdd ZdS )MultiplexedPathTestc                 C   s   t tjd }t|| _d S )Nnamespacedata01)pathlibPath__file__parentstrfolder)clspath r   U/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/test/test_importlib/test_reader.py
setUpClass   s   zMultiplexedPathTest.setUpClassc                 C   s6   |  t t  W d    d S 1 sw   Y  d S N)assertRaisesFileNotFoundErrorr   selfr   r   r   test_init_no_paths   s   "z&MultiplexedPathTest.test_init_no_pathsc                 C   sD   |  t ttj| jd W d    d S 1 sw   Y  d S )Nbinary.file)r   NotADirectoryErrorr   osr   joinr   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.0r   r   r   r   	<setcomp>   s    z3MultiplexedPathTest.test_iterdir.<locals>.<setcomp>__pycache__>   utf-16.file
utf-8.filer   )r   r   iterdirremoveKeyError
ValueErrorassertEqual)r   contentsr   r   r   test_iterdir   s   z MultiplexedPathTest.test_iterdirc              
   C   st   t jt jtdd}dd t| j| D }dD ]}z|| W q t	t
fy/   Y qw | |h d d S )N..data01c                 S   r   r   r   r    r   r   r   r"   "   s    z=MultiplexedPathTest.test_iterdir_duplicate.<locals>.<setcomp>)r#   z__init__.pyc>   r$   r%   r   z__init__.pysubdirectory)r   r   abspathr   r	   r   r   r&   r'   r(   r)   r*   )r   r.   r+   r'   r   r   r   test_iterdir_duplicate    s   z*MultiplexedPathTest.test_iterdir_duplicatec                 C      |  t| j d d S )NT)r*   r   r   is_dirr   r   r   r   test_is_dir/      zMultiplexedPathTest.test_is_dirc                 C   r2   )NF)r*   r   r   is_filer   r   r   r   test_is_file2   r5   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_file5   s   



"z"MultiplexedPathTest.test_open_filec                 C   s   t jt jtd}t j|d}t| j|}| t|	dt
|d d  t jdd | t|	dt
|d d  t jdd | t|	dt
|d d  t jdd d S )Nr-   r.   r      r   r/   	imaginary)r   r   r0   r   r	   r   r   r*   r   joinpathlen)r   prefixr.   r   r   r   r   test_join_path>   s   z"MultiplexedPathTest.test_join_pathc                 C   s$   |  tt| jd| j d d S )NMultiplexedPath(''))r*   reprr   r   r   r   r   r   	test_reprO   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_nameU   s   
zMultiplexedPathTest.test_nameN)__name__
__module____qualname__classmethodr   r   r   r,   r1   r4   r7   r;   rA   rE   rG   r   r   r   r   r   
   s    
	r   c                   @   sL   e Zd ZeeejZe	dd Z
e	dd Zdd Zdd Zd	d
 ZdS )NamespaceReaderTestc                 C      t j| j d S r   )sysr   appendsite_dirr   r   r   r   r   _      zNamespaceReaderTest.setUpClassc                 C   rM   r   )rN   r   r'   rP   rQ   r   r   r   tearDownClassc   rR   z!NamespaceReaderTest.tearDownClassc                 C   s<   |  t tddg W d    d S 1 sw   Y  d S )NZpath1Zpath2)r   r)   r   r   r   r   r   test_init_errorg   s   "z#NamespaceReaderTest.test_init_errorc                 C   sh   t d}t|jj}tjtjtdd}| 	|
dtj|d | 	|
dtj|d d S )Nr   r-   r   r=   )r   r   __spec__submodule_search_locationsr   r   r0   r   r	   r*   Zresource_pathr   r   readerrootr   r   r   test_resource_pathk   s   z&NamespaceReaderTest.test_resource_pathc                 C   s\   t d}t|jj}tjtjtdd}| 	|
 t | t|
 d| d d S )Nr   r-   rB   rC   )r   r   rU   rV   r   r   r0   r   r	   ZassertIsInstancefilesr   r*   rD   rW   r   r   r   
test_filesw   s
    zNamespaceReaderTest.test_filesN)rH   rI   rJ   r   r   r   r	   r
   rP   rK   r   rS   rT   rZ   r\   r   r   r   r   rL   \   s    

rL   __main__)Zos.pathr   rN   r   Zunittest	importlibr   importlib.readersr   r   ZTestCaser   rL   rH   mainr   r   r   r   <module>   s    R#