U
    ?h"                     @   s   d dl Z d dlZ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Z
G d	d
 d
ejZG dd de	ee jZG dd de
ee jZdS )    N   )warnings_helper)utilc                   @   s   e Zd ZdZdZdS )StringAnchorMixindata01data02N)__name__
__module____qualname__anchor01anchor02 r   r   [/var/www/html/venv/lib/python3.8/site-packages/importlib_resources/tests/test_functional.pyr      s   r   c                   @   s$   e Zd Zedd Zedd ZdS )ModuleAnchorMixinc                 C   s
   t dS )Nr   	importlibimport_moduleselfr   r   r   r      s    zModuleAnchorMixin.anchor01c                 C   s
   t dS Nr   r   r   r   r   r   r      s    zModuleAnchorMixin.anchor02N)r   r	   r
   propertyr   r   r   r   r   r   r      s   
r   c                       s   e 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ejeddd Zdd Z  ZS )FunctionalAPIBasec                    s   t    | d d S r   )supersetUpZload_fixturer   	__class__r   r   r       s    
zFunctionalAPIBase.setUpc              
   c   s,   dD ]"}| j |d |V  W 5 Q R X qdS )zAYield various names of a text file in anchor02, each in a subTest))subdirectory	subsubdirresource.txt)z#subdirectory/subsubdir/resource.txt)zsubdirectory/subsubdirr   )
path_partsN)subTestr   r   r   r   r   _gen_resourcetxt_path_parts$   s    z-FunctionalAPIBase._gen_resourcetxt_path_partsc                 C   s   |  |t| d | dS )zqAssert that `string` ends with `suffix`.

        Used to ignore an architecture-specific UTF-16 byte-order mark.N)assertEquallen)r   stringsuffixr   r   r   assertEndsWith.   s    z FunctionalAPIBase.assertEndsWithc              	   C   s  |  t| jdd |  tj| jdddddd |  D ]$}|  tj| jf|d	did q<| t t| j W 5 Q R X | t t| jd
 W 5 Q R X | t t| jd W 5 Q R X |  tj| jdddd | 	tj| jdddd
djdd d S )N
utf-8.fileHello, UTF-8 world!
r   r   r   utf-8encoding
a resourcer,   no-such-fileutf-16.filebinary.filelatin1 backslashreplaceerrorsHello, UTF-16 world!
	utf-16-le)r#   	resources	read_textr   r   r"   assertRaisesOSErrorUnicodeDecodeErrorr'   encodedecoder!   r   r   r   test_read_text4   sb    


z FunctionalAPIBase.test_read_textc                 C   sB   |  t| jdd |  D ]}|  tj| jf| d qd S Nr(   s   Hello, UTF-8 world!
s
   a resource)r#   r8   read_binaryr   r"   r   r!   r   r   r   test_read_binaryg   s    z"FunctionalAPIBase.test_read_binaryc              
   C   sX  t | jd}| | d W 5 Q R X |  D ]8}t j| jf|ddi}| | d W 5 Q R X q2| t t | j W 5 Q R X | t t | jd W 5 Q R X t | jd$}| t	 |  W 5 Q R X W 5 Q R X t j| jdd	d
}| | d W 5 Q R X t j| jddd$}| 
| ddjdd W 5 Q R X d S )Nr(   r)   r,   r*   r-   r.   r/   r0   r1   r+   r2   r3   r4   r6   r7   )r8   	open_textr   r#   readr"   r   r:   r;   r<   r'   r=   r>   r   fr   r   r   r   test_open_textr   sL    
z FunctionalAPIBase.test_open_textc              
   C   sj   t | jd}| | d W 5 Q R X |  D ]2}t j| jf| }| | d W 5 Q R X q2d S r@   )r8   open_binaryr   r#   rD   r"   r   rE   r   r   r   test_open_binary   s    z"FunctionalAPIBase.test_open_binaryc              
   C   s   t | jd2}tt|dd}| | d W 5 Q R X W 5 Q R X t | j8}ttj|ddd}| | d W 5 Q R X W 5 Q R X d S )Nr(   r*   r+   r)   )	r8   pathr   openstrr#   rD   osjoin)r   rJ   rF   r   r   r   	test_path   s    $zFunctionalAPIBase.test_pathc                 C   st   t j}| || jd | || jd | || j | || jd |  D ]}| || jf|  qTd S )Nr(   Zno_such_filer   )r8   is_resourceZ
assertTruer   ZassertFalser"   r   )r   rP   r   r   r   r   test_is_resource   s    z"FunctionalAPIBase.test_is_resourcec                 C   s  t dtf t| j}W 5 Q R X | t|ddddh | t	2 t dtf t
t| jd W 5 Q R X W 5 Q R X |  D ]J}| t	6 t dtf t
tj| jf|  W 5 Q R X W 5 Q R X qt dtf t| jd}W 5 Q R X | t|dh d S )Nz.*contents.*r(   r/   r0   r   )r   Zcheck_warningsDeprecationWarningr8   contentsr   ZassertGreaterEqualsetr:   r;   listr"   )r   cr   r   r   r   test_contents   s.    
&,zFunctionalAPIBase.test_contents)categoryc                 C   s   t jt jt jt jt jt jt jfD ]z}| j|dd | 	t
 |d  W 5 Q R X | 	t
tf |d W 5 Q R X | 	t |d W 5 Q R X W 5 Q R X q d S )Nfunci  z$missing module$)r8   r9   rA   rC   rH   rJ   rP   rS   r    r:   	TypeErrorAttributeErrorModuleNotFoundErrorr   rZ   r   r   r   test_common_errors   s    	z$FunctionalAPIBase.test_common_errorsc                 C   sT   t jt jfD ]B}| j|d, | t || jddd W 5 Q R X W 5 Q R X qd S )NrY   r   r   r   )r8   r9   rC   r    r:   r[   r   r^   r   r   r   test_text_errors   s    z"FunctionalAPIBase.test_text_errors)r   r	   r
   r   r"   r'   r?   rB   rG   rI   rO   rQ   rW   r   Zignore_warningsrR   r_   r`   __classcell__r   r   r   r   r      s   
3%
	

r   c                   @   s   e Zd ZdS )FunctionalAPITest_StringAnchorNr   r	   r
   r   r   r   r   rb      s   rb   c                   @   s   e Zd ZdS )FunctionalAPITest_ModuleAnchorNrc   r   r   r   r   rd      s   rd   )ZunittestrM   r   Zcompat.py39r   Zimportlib_resourcesr8    r   r   r   Z	DiskSetupr   ZTestCaserb   rd   r   r   r   r   <module>   s&   
 T

