U
    ^»{j¤  ã                   @   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Zd dlZd dl	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ejƒZG dd„ deejejƒZG dd„ deejejƒZG dd„ deejejƒZG dd„ dƒZG dd„ dƒZG dd„ deejeejƒZG dd„ deejeejƒZG dd„ dƒZ G dd„ deeje ejƒZ!G dd „ d eeje ejƒZ"e#d!k�r˜e $¡  dS )"é    Né   )ÚTraversableé   )Úutil)Ú	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   úc/var/www/html/bwave/python/venv/lib/python3.8/site-packages/importlib_resources/tests/test_files.pyÚsuppress_known_deprecation   s    r   c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Z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_textc                 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  | j¡}| dd¡}|  | ¡ ¡ d S )NÚsubdirectoryzbinary.file)r   r   r   r   Z
assertTrueÚis_file)r   r   Zbinfiler   r   r   Ú test_joinpath_with_multiple_args&   s    z+FilesTests.test_joinpath_with_multiple_argsc              	   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#   r'   r*   r,   r   r   r   r   r      s
   r   c                   @   s   e Zd ZdS )ÚOpenDiskTestsN©r-   r.   r/   r   r   r   r   r0   4   s   r0   c                   @   s   e Zd ZdS )ÚOpenZipTestsNr1   r   r   r   r   r2   8   s   r2   c                   @   s   e Zd ZdZdd„ ZdS )ÚOpenNamespaceTestsÚnamespacedata01c                 C   s"   ddl }|j d¡ t |¡ dS )aÿ  
        Non-path items in a namespace package's ``__path__`` are ignored.

        As reported in python/importlib_resources#311, some tools
        like Setuptools, when creating editable packages, will inject
        non-paths into a namespace package's ``__path__``, a
        sentinel like
        ``__editable__.sample_namespace-1.0.finder.__path_hook__``
        to cause the ``PathEntryFinder`` to be called when searching
        for packages. In that case, resources should still be loadable.
        r   Nz6__editable__.sample_namespace-1.0.finder.__path_hook__)r4   Ú__path__Úappendr   r   )r   r4   r   r   r   Útest_non_paths_in_dunder_path?   s
    ÿz0OpenNamespaceTests.test_non_paths_in_dunder_pathN)r-   r.   r/   ÚMODULEr7   r   r   r   r   r3   <   s   r3   c                   @   s   e Zd ZdZdS )ÚOpenNamespaceZipTestsr4   N)r-   r.   r/   Z
ZIP_MODULEr   r   r   r   r9   T   s   r9   c                   @   s   e Zd ZdZdZdd„ ZdS )Ú
DirectSpeczI
    Override behavior of ModuleSetup to write a full spec directly.
    Zunusedc                 C   s   |   | j¡ d S r$   )Ztree_on_pathÚspec)r   Únamer   r   r   Úload_fixture_   s    zDirectSpec.load_fixtureN)r-   r.   r/   Ú__doc__r8   r=   r   r   r   r   r:   X   s   r:   c                   @   s   e Zd ZdddœZdd„ ZdS )ÚModulesFilesÚ úresources are the best)zmod.pyúres.txtc                 C   s6   ddl }t |¡ d¡jdd�}|| jd ks2t‚dS )zK
        A module can have resources found adjacent to the module.
        r   NrB   r   r    )Úmodr   r   r   r"   r;   r   )r   rC   r   r   r   r   Útest_module_resourcesi   s    z"ModulesFiles.test_module_resourcesN)r-   r.   r/   r;   rD   r   r   r   r   r?   c   s   þr?   c                   @   s   e Zd ZdS )ÚModuleFilesDiskTestsNr1   r   r   r   r   rE   s   s   rE   c                   @   s   e Zd ZdS )ÚModuleFilesZipTestsNr1   r   r   r   r   rF   w   s   rF   c                   @   sb   e Zd Ze dej › d�¡Zeeddœe ej d¡ddœdœZdd	„ Z	d
d„ Z
dd„ Zdd„ ZdS )ÚImplicitContextFilesz
        import zZ as res
        val = res.files().joinpath('res.txt').read_text(encoding='utf-8')
        rA   )ú__init__.pyz	submod.pyrB   Úc_resources)rH   rB   )ÚsomepkgÚ	frozenpkgc                 C   s   t  d¡jdkst‚dS )úW
        Without any parameter, files() will infer the location as the caller.
        rJ   rA   N©Ú	importlibÚimport_moduleÚvalr   r&   r   r   r   Útest_implicit_files_packageŽ   s    z0ImplicitContextFiles.test_implicit_files_packagec                 C   s   t  d¡jdkst‚dS )rL   zsomepkg.submodrA   NrM   r&   r   r   r   Útest_implicit_files_submodule”   s    z2ImplicitContextFiles.test_implicit_files_submodulec           
      C   s¤   | j  t ¡ ¡}t |d¡}t tj¡j}t	j
||dd„ d� t |¡D ]D\}}}|D ]4}t |¡| }| d¡}	t ||	¡ tj |¡ qVqH| j  t |¡¡ dS )zO
        Make a compiled-only copy of the importlib resources package.
        rI   c                  W   s   dgS )NÚ__pycache__r   )Ú_r   r   r   Ú<lambda>¡   ó    z9ImplicitContextFiles._compile_importlib.<locals>.<lambda>)Úignorez.pycN)ZfixturesÚenter_contextr   Útemp_dirÚpathlibÚPathr   Ú__file__ÚparentÚshutilÚcopytreeÚosÚwalkÚwith_suffixÚ
py_compileÚcompileÚunlinkr   ZDirsOnSysPath)
r   Zbin_siterI   ÚsourcesÚdirpathrT   Ú	filenamesÚfilenameÚsource_pathÚcfiler   r   r   Ú_compile_importlibš   s    
z'ImplicitContextFiles._compile_importlibc                 C   s    |   ¡  t d¡jdkst‚dS )zk
        Caller detection works for compiled-only resources module.

        python/cpython#123085
        rK   rA   N)rl   rN   rO   rP   r   r&   r   r   r   Ú+test_implicit_files_with_compiled_importlib«   s    z@ImplicitContextFiles.test_implicit_files_with_compiled_importlibN)r-   r.   r/   ÚtextwrapÚdedentr   Zset_valÚreplacer;   rQ   rR   rl   rm   r   r   r   r   rG   {   s"   ÿÿýþúrG   c                   @   s   e Zd ZdS )ÚImplicitContextFilesDiskTestsNr1   r   r   r   r   rq   µ   s   rq   c                   @   s   e Zd ZdS )ÚImplicitContextFilesZipTestsNr1   r   r   r   r   rr   »   s   rr   Ú__main__)%r`   rZ   rc   r^   rn   Zunittestr   rN   Ú
contextlibZimportlib_resourcesr   Úabcr   r@   r   Zcompat.py39r   r   Úcontextmanagerr   r   Z	DiskSetupZTestCaser0   ZZipSetupr2   r3   r9   r:   r?   rE   rF   rG   rq   rr   r-   Úmainr   r   r   r   Ú<module>   sL   
:
   ÿ
   ÿ
