U
    i2e                     @   s   d dl Z d dlZd dlZ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 ddl
mZ ddl
mZ ddlmZmZ ejd	d
 ZG dd dZG dd deejZG dd deejejZG dd deejZG dd dZG dd deejZG dd deejZedkre  dS )    N   )Traversable   )data01)util)_path)	os_helperimport_helperc               	   c   s0   t jdd} t jdtd | V  W 5 Q R X d S )NT)recorddefault)category)warningscatch_warningssimplefilterDeprecationWarning)ctx r   H/tmp/pip-unpacked-wheel-bn52x7jx/importlib_resources/tests/test_files.pysuppress_known_deprecation   s    r   c                   @   s>   e Zd Zdd Zdd Zeeedddd Z	d	d
 Z
dS )
FilesTestsc                 C   s*   t | j}|d }|dks&td S )N
utf-8.files   Hello, UTF-8 world!
)	resourcesfilesdatajoinpath
read_bytesAssertionErrorselfr   actualr   r   r   test_read_bytes   s    zFilesTests.test_read_bytesc                 C   s.   t | j}|djdd}|dks*td S )Nr   utf-8encodingzHello, UTF-8 world!
)r   r   r   r   	read_textr   r   r   r   r   test_read_text   s    zFilesTests.test_read_textruntime_checkablez4Only suitable when typing supports runtime_checkablec                 C   s   t t| jtstd S N)
isinstancer   r   r   r   r   r   r   r   r   test_traversable"   s    zFilesTests.test_traversablec              	   C   s$   t   tj| jd W 5 Q R X dS )zx
        Files used to take a 'package' parameter. Make sure anyone
        passing by name is still supported.
        )packageN)r   r   r   r   r)   r   r   r   test_old_parameter)   s    zFilesTests.test_old_parameterN)__name__
__module____qualname__r    r%   unittestZ
skipUnlesshasattrtypingr*   r,   r   r   r   r   r      s   
r   c                   @   s   e Zd Zdd ZdS )OpenDiskTestsc                 C   s
   t | _d S r'   )r   r   r)   r   r   r   setUp3   s    zOpenDiskTests.setUpNr-   r.   r/   r4   r   r   r   r   r3   2   s   r3   c                   @   s   e Zd ZdS )OpenZipTestsN)r-   r.   r/   r   r   r   r   r6   7   s   r6   c                   @   s   e Zd Zdd ZdS )OpenNamespaceTestsc                 C   s   ddl m} || _d S )Nr   )namespacedata01) r8   r   )r   r8   r   r   r   r4   <   s    zOpenNamespaceTests.setUpNr5   r   r   r   r   r7   ;   s   r7   c                   @   s   e Zd Zdd ZdS )SiteDirc                 C   sR   t  | _| | jj | jt | _| jt	
| j | jt	  d S r'   )
contextlib	ExitStackZfixturesZ
addCleanupcloseenter_contextr   temp_dirsite_dirr	   ZDirsOnSysPathZCleanImportr)   r   r   r   r4   C   s
    
zSiteDir.setUpNr5   r   r   r   r   r:   B   s   r:   c                   @   s   e Zd Zdd ZdS )ModulesFilesTestsc                 C   sL   ddd}t || j ddl}t|djdd}||d ksHtdS )	zK
        A module can have resources found adjacent to the module.
        r9   resources are the best)zmod.pyres.txtr   NrC   r!   r"   )	r   buildr@   modr   r   r   r$   r   )r   specrE   r   r   r   r   test_module_resourcesL   s    z'ModulesFilesTests.test_module_resourcesN)r-   r.   r/   rG   r   r   r   r   rA   K   s   rA   c                   @   s   e Zd Zdd ZdS )ImplicitContextFilesTestsc                 C   s:   dt dddi}t|| j tdjdks6tdS )zW
        Without any parameter, files() will infer the location as the caller.
        Zsomepkgz
                    import importlib_resources as res
                    val = res.files().joinpath('res.txt').read_text(encoding='utf-8')
                    rB   )z__init__.pyrC   N)	textwrapdedentr   rD   r@   	importlibimport_modulevalr   )r   rF   r   r   r   test_implicit_files\   s    z-ImplicitContextFilesTests.test_implicit_filesN)r-   r.   r/   rN   r   r   r   r   rH   [   s   rH   __main__)r2   rI   r0   r   rK   r;   Zimportlib_resourcesr   abcr   r9   r   r   r   _compatr   r	   contextmanagerr   r   ZTestCaser3   ZZipSetupr6   r7   r:   rA   rH   r-   mainr   r   r   r   <module>   s,   
	
