o
    gn#                     @   s   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 G dd dZ	G dd dZ
G d	d
 d
ZG dd de	eejejZG dd de
eejejZG dd de	eejejZdS )    N   )util)warnings_helperc                   @   s   e Zd ZdZdZdS )StringAnchorMixindata01data02N)__name__
__module____qualname__anchor01anchor02 r   r   `/var/www/visachat/venv/lib/python3.10/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   
   t dS )Nr   	importlibimport_moduleselfr   r   r   r         
zModuleAnchorMixin.anchor01c                 C   r   Nr   r   r   r   r   r   r      r   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setUpload_fixturer   	__class__r   r   r      s   
zFunctionalAPIBase.setUpc              	   c   sB    dD ]}| j |d |V  W d   n1 sw   Y  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   sX  |  t| jdd |  tj| jdddddd |  D ]}|  tj| jg|R d	did q| t t| j W d    n1 sHw   Y  | ttjj	f t| jd
 W d    n1 shw   Y  | t
 t| jd W d    n1 sw   Y  |  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abcTraversalErrorUnicodeDecodeErrorr*   encodedecoder$   r   r   r   test_read_text/   sh   


z FunctionalAPIBase.test_read_textc                 C   sD   |  t| jdd |  D ]}|  tj| jg|R  d qd S Nr+   s   Hello, UTF-8 world!
s
   a resource)r&   r;   read_binaryr   r%   r   r$   r   r   r   test_read_binaryb   s   z"FunctionalAPIBase.test_read_binaryc              	   C   s  t | jd}| | d W d    n1 sw   Y  |  D ]'}t j| jg|R ddi}| | d W d    n1 sEw   Y  q#| t t | j W d    n1 saw   Y  | tt j	j
f t | jd W d    n1 sw   Y  t | jd!}| t |  W d    n1 sw   Y  W d    n1 sw   Y  t j| jdd	d
}| | d W d    n1 sw   Y  t j| jddd}| | ddjdd W d    d S 1 sw   Y  d S )Nr+   r,   r/   r-   r0   r1   r2   r3   r4   r.   r5   r6   r7   r9   r:   )r;   	open_textr   r&   readr%   r   r=   r>   r?   r@   rA   r*   rB   rC   r   fr"   r   r   r   test_open_textm   s`   

"z FunctionalAPIBase.test_open_textc              	   C   s   t | jd}| | d W d    n1 sw   Y  |  D ]$}t j| jg|R  }| | d W d    n1 sBw   Y  q#d S rE   )r;   open_binaryr   r&   rI   r%   r   rJ   r   r   r   test_open_binary   s   z"FunctionalAPIBase.test_open_binaryc              	   C   s   t | jd(}tt|dd}| | d W d    n1 s#w   Y  W d    n1 s2w   Y  t | j4}ttj|ddd}| | d W d    n1 s\w   Y  W d    d S W d    d S 1 stw   Y  d S )Nr+   r-   r.   r,   )	r;   pathr   openstrr&   rI   osjoin)r   rO   rK   r   r   r   	test_path   s   "zFunctionalAPIBase.test_pathc                 C   sv   t j}| || jd | || jd | || j | || jd |  D ]}| || jg|R   q*d S )Nr+   no_such_filer   )r;   is_resource
assertTruer   assertFalser%   r   )r   rV   r"   r   r   r   test_is_resource   s   z"FunctionalAPIBase.test_is_resourcec              
   C   s  t dtf t| j}W d    n1 sw   Y  | t|h d | t	( t dtf t
t| jd W d    n1 sHw   Y  W d    n1 sWw   Y  |  D ]>}| t	tjjf+ t dtf t
tj| jg|R   W d    n1 sw   Y  W d    n1 sw   Y  q`t dtf t| jd}W d    n1 sw   Y  | t|dh d S )Nz.*contents.*>   r   r+   r3   r2   r+   r   r3   )r   check_warningsDeprecationWarningr;   contentsr   assertGreaterEqualsetr=   r>   listr%   r?   r@   )r   cr"   r   r   r   test_contents   sL    	 zFunctionalAPIBase.test_contents)categoryc              
   C   s   t jt jt jt jt jt jt jfD ]e}| j|dU | 	t
 |d  W d    n1 s-w   Y  | 	t
tf |d W d    n1 sHw   Y  | 	t |d W d    n1 saw   Y  W d    n1 spw   Y  qd S )Nfunci  z$missing module$)r;   r<   rF   rH   rM   rO   rV   r\   r#   r=   	TypeErrorAttributeErrorModuleNotFoundErrorr   rd   r   r   r   test_common_errors   s,   	


z$FunctionalAPIBase.test_common_errorsc              
   C   s|   t jt jfD ]5}| j|d% | t || jddd W d    n1 s'w   Y  W d    n1 s6w   Y  qd S )Nrc   r   r    r!   )r;   r<   rH   r#   r=   re   r   rh   r   r   r   test_text_errors   s    z"FunctionalAPIBase.test_text_errors)r   r	   r
   r   r%   r*   rD   rG   rL   rN   rT   rY   ra   r   ignore_warningsr[   ri   rj   __classcell__r   r   r   r   r      s    
3%
	
 
r   c                   @      e Zd ZdS )#FunctionalAPITest_StringAnchor_DiskNr   r	   r
   r   r   r   r   rn          rn   c                   @   rm   )#FunctionalAPITest_ModuleAnchor_DiskNro   r   r   r   r   rq      rp   rq   c                   @   rm   )%FunctionalAPITest_StringAnchor_MemoryNro   r   r   r   r   rr     rp   rr   )r   rR   unittestimportlib_resourcesr;    r   compat.py39r   r   r   r   	DiskSetupTestCasern   rq   MemorySetuprr   r   r   r   r   <module>   s8    
 
Z
	
	