a
    ijn#                     @   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   g/home/ghrups/robot-bench/.venv/lib/python3.9/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 ]6}| j |d |V  W d   q1 s00    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   sZ  |  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 s0    Y  | ttjj	f t| jd
 W d    n1 s0    Y  | t
 t| jd W d    n1 s
0    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/   sb    

*,.
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#   r8   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 s40    Y  |  D ]N}t j| jg|R ddi }| | d W d    qF1 s0    Y  qF| t t | j W d    n1 s0    Y  | tt j	j
f t | jd W d    n1 s0    Y  t | jdD}| t |  W d    n1 sH0    Y  W d    n1 sh0    Y  t j| jdd	d
 }| | d W d    n1 s0    Y  t j| jddd.}| | ddjdd W d    n1 s0    Y  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?   r@   r   fr   r   r   r   test_open_textm   sL    .0*.H0
z FunctionalAPIBase.test_open_textc              	   C   s   t | jd }| | d W d    n1 s40    Y  |  D ]H}t j| jg|R   }| | d W d    qF1 s0    Y  qFd S rB   )r8   open_binaryr   r#   rF   r"   r   rG   r   r   r   test_open_binary   s    .z"FunctionalAPIBase.test_open_binaryc              	   C   s   t | jdP}tt|dd }| | d W d    n1 sF0    Y  W d    n1 sd0    Y  t | jV}ttj|ddd }| | d W d    n1 s0    Y  W d    n1 s0    Y  d S )Nr(   r*   r+   r)   )	r8   pathr   openstrr#   rF   osjoin)r   rL   rH   r   r   r   	test_path   s    LzFunctionalAPIBase.test_pathc                 C   sv   t j}| || jd | || jd | || j | || jd |  D ]}| || jg|R   qTd S )Nr(   Zno_such_filer   )r8   is_resourceZ
assertTruer   ZassertFalser"   r   )r   rR   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 s00    Y  | t|h d | t	P t dtf" t
t| jd W d    n1 s0    Y  W d    n1 s0    Y  |  D ]}| t	tjjfX t dtf( t
tj| jg|R   W d    n1 s0    Y  W d    q1 s60    Y  qt dtf t| jd}W d    n1 sv0    Y  | t|dh d S )Nz.*contents.*>   r0   r/   r(   r   r(   r   r0   )r   Zcheck_warningsDeprecationWarningr8   contentsr   ZassertGreaterEqualsetr:   r;   listr"   r<   r=   )r   cr   r   r   r   test_contents   s:    *NZ.zFunctionalAPIBase.test_contents)categoryc              
   C   s   t jt jt jt jt jt jt jfD ]}| j|d | 	t
 |d  W d    n1 sZ0    Y  | 	t
tf |d W d    n1 s0    Y  | 	t |d W d    n1 s0    Y  W d    q 1 s0    Y  q d S )Nfunci  z$missing module$)r8   r9   rC   rE   rJ   rL   rR   rU   r    r:   	TypeErrorAttributeErrorModuleNotFoundErrorr   r\   r   r   r   test_common_errors   s    	&&z$FunctionalAPIBase.test_common_errorsc              
   C   s|   t jt jfD ]j}| j|dJ | t  || jddd W d    n1 sN0    Y  W d    q1 sl0    Y  qd S )Nr[   r   r   r   )r8   r9   rE   r    r:   r]   r   r`   r   r   r   test_text_errors   s    z"FunctionalAPIBase.test_text_errors)r   r	   r
   r   r"   r'   rA   rD   rI   rK   rQ   rS   rY   r   Zignore_warningsrT   ra   rb   __classcell__r   r   r   r   r      s   
3%
	 

r   c                   @   s   e Zd ZdS )#FunctionalAPITest_StringAnchor_DiskNr   r	   r
   r   r   r   r   rd      s   rd   c                   @   s   e Zd ZdS )#FunctionalAPITest_ModuleAnchor_DiskNre   r   r   r   r   rf      s   rf   c                   @   s   e Zd ZdS )%FunctionalAPITest_StringAnchor_MemoryNre   r   r   r   r   rg     s   rg   )r   rO   ZunittestZimportlib_resourcesr8    r   Zcompat.py39r   r   r   r   Z	DiskSetupZTestCaserd   rf   ZMemorySetuprg   r   r   r   r   <module>   s6   
 Z
	
	
