a
    i‚jñ  ã                   @   s\   d dl Z d dlZd dlZd dlmZmZ ddlmZ G dd„ dej	ƒZ
G dd„ dej	ƒZdS )	é    N)ÚCompatibilityFilesÚ	wrap_specé   )Úutilc                   @   sœ   e Zd Zed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d„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#S )$ÚCompatibilityFilesTestsc                 C   s   t  d¡}tj|dddS )Nó   Hello, world!Z	some_path©ÚaÚbÚc)ÚfileÚpathÚcontents)ÚioÚBytesIOr   Zcreate_package)ÚselfÚ
bytes_data© r   úo/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/importlib_resources/tests/test_compatibilty_files.pyÚpackage   s    
ýzCompatibilityFilesTests.packagec                 C   s   t  | j¡S ©N©Ú	resourcesÚfilesr   ©r   r   r   r   r      s    zCompatibilityFilesTests.filesc                 C   s(   |   tdd„ | j ¡ D ƒƒg d¢¡ d S )Nc                 s   s   | ]}|j V  qd S r   )Úname)Ú.0r   r   r   r   Ú	<genexpr>   ó    z>CompatibilityFilesTests.test_spec_path_iter.<locals>.<genexpr>r   )ÚassertEqualÚsortedr   Úiterdirr   r   r   r   Útest_spec_path_iter   s    þz+CompatibilityFilesTests.test_spec_path_iterc                 C   s   |   t| jd  ¡ ƒg ¡ d S ©Nr	   ©r   Úlistr   r!   r   r   r   r   Útest_child_path_iter!   s    z,CompatibilityFilesTests.test_child_path_iterc                 C   sD   |   t| jd d  ¡ ƒg ¡ |   t| jd d d  ¡ ƒg ¡ d S r#   r$   r   r   r   r   Útest_orphan_path_iter$   s    z-CompatibilityFilesTests.test_orphan_path_iterc                 C   s$   |   | j ¡ ¡ |   | j ¡ ¡ d S r   ©ÚassertFalser   Úis_fileÚis_dirr   r   r   r   Útest_spec_path_is(   s    z)CompatibilityFilesTests.test_spec_path_isc                 C   s,   |   | jd  ¡ ¡ |  | jd  ¡ ¡ d S r#   )Z
assertTruer   r*   r)   r+   r   r   r   r   Útest_child_path_is,   s    z*CompatibilityFilesTests.test_child_path_isc                 C   sl   |   | jd d  ¡ ¡ |   | jd d  ¡ ¡ |   | jd d d  ¡ ¡ |   | jd d d  ¡ ¡ d S r#   r(   r   r   r   r   Útest_orphan_path_is0   s    z+CompatibilityFilesTests.test_orphan_path_isc                 C   s   |   | jjd¡ d S )NZtestingpackage©r   r   r   r   r   r   r   Útest_spec_path_name6   s    z+CompatibilityFilesTests.test_spec_path_namec                 C   s   |   | jd jd¡ d S r#   r/   r   r   r   r   Útest_child_path_name9   s    z,CompatibilityFilesTests.test_child_path_namec                 C   s8   |   | jd d jd¡ |   | jd d d jd¡ d S ©Nr	   r
   r   r/   r   r   r   r   Útest_orphan_path_name<   s    z-CompatibilityFilesTests.test_orphan_path_namec                 C   s,   |   | j ¡ d¡ |   | jjddd¡ d S )Nr   úutf-8©ÚencodingúHello, world!©r   r   Ú
read_bytesÚ	read_textr   r   r   r   Útest_spec_path_open@   s    z+CompatibilityFilesTests.test_spec_path_openc                 C   s4   |   | jd  ¡ d¡ |   | jd jddd¡ d S )Nr	   r   r4   r5   r7   r8   r   r   r   r   Útest_child_path_openD   s    ÿz,CompatibilityFilesTests.test_child_path_openc                 C   s€   |   t¡" | jd d  ¡  W d   ƒ n1 s20    Y  |   t¡& | jd d d  ¡  W d   ƒ n1 sr0    Y  d S r2   )ÚassertRaisesÚFileNotFoundErrorr   r9   r   r   r   r   Útest_orphan_path_openJ   s    0z-CompatibilityFilesTests.test_orphan_path_openc                 C   s:   |   t¡ | j d¡ W d   ƒ n1 s,0    Y  d S )NÚ0)r=   Ú
ValueErrorr   Úopenr   r   r   r   Útest_open_invalid_modeP   s    z.CompatibilityFilesTests.test_open_invalid_modec                 C   s6   |   t¡ t ¡  W d   ƒ n1 s(0    Y  d S r   )r=   rA   r   Ú
OrphanPathr   r   r   r   Útest_orphan_path_invalidT   s    z0CompatibilityFilesTests.test_orphan_path_invalidc                 C   s"   t | jƒ}|  |j d ¡t¡ d S r   )r   r   ÚassertIsInstanceÚloaderÚget_resource_readerr   )r   Úspecr   r   r   Útest_wrap_specX   s    
z&CompatibilityFilesTests.test_wrap_specN)Ú__name__Ú
__module__Ú__qualname__Úpropertyr   r   r"   r&   r'   r,   r-   r.   r0   r1   r3   r;   r<   r?   rC   rE   rJ   r   r   r   r   r      s&   

r   c                   @   s,   e Zd Zedd„ ƒZedd„ ƒZdd„ ZdS )ÚCompatibilityFilesNoReaderTestsc                 C   s
   t  d ¡S r   )r   Zcreate_package_from_loaderr   r   r   r   r   ^   s    z'CompatibilityFilesNoReaderTests.packagec                 C   s   t  | j¡S r   r   r   r   r   r   r   b   s    z%CompatibilityFilesNoReaderTests.filesc                 C   s   |   | jd tj¡ d S r#   )rF   r   r   rD   r   r   r   r   Útest_spec_path_joinpathf   s    z7CompatibilityFilesNoReaderTests.test_spec_path_joinpathN)rK   rL   rM   rN   r   r   rP   r   r   r   r   rO   ]   s
   

rO   )r   ZunittestZimportlib_resourcesr   Zimportlib_resources._adaptersr   r   Ú r   ZTestCaser   rO   r   r   r   r   Ú<module>   s   P