a
    ijm                     @   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	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re"  dS )"    N   )Traversable   )util)import_helper	os_helperc                  c   sD   t jdd$} t jdtd | V  W d    n1 s60    Y  d S )NT)recorddefault)category)warningscatch_warningssimplefilterDeprecationWarning)ctx r   b/home/ghrups/robot-bench/.venv/lib/python3.9/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&J d S )N
utf-8.files   Hello, UTF-8 world!
)	resourcesfilesdatajoinpath
read_bytesselfr   actualr   r   r   test_read_bytes   s    zFilesTests.test_read_bytesc                 C   s.   t | j}|djdd}|dks*J d S )Nr   utf-8encodingzHello, UTF-8 world!
)r   r   r   r   	read_textr   r   r   r   test_read_text   s    zFilesTests.test_read_textc                 C   s   t t| jtsJ d S N)
isinstancer   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   s8   t   tj| jd W d   n1 s*0    Y  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   r/   3   s   r/   c                   @   s   e Zd ZdS )OpenZipTestsNr0   r   r   r   r   r1   7   s   r1   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__)r3   __path__appendr   r   )r   r3   r   r   r   test_non_paths_in_dunder_path>   s
    z0OpenNamespaceTests.test_non_paths_in_dunder_pathN)r,   r-   r.   MODULEr6   r   r   r   r   r2   ;   s   r2   c                   @   s   e Zd ZdZdS )OpenNamespaceZipTestsr3   N)r,   r-   r.   Z
ZIP_MODULEr   r   r   r   r8   S   s   r8   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__r7   r<   r   r   r   r   r9   W   s   r9   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s2J dS )zK
        A module can have resources found adjacent to the module.
        r   NrA   r   r   )modr   r   r   r!   r:   )r   rB   r   r   r   r   test_module_resourcesh   s    z"ModulesFiles.test_module_resourcesN)r,   r-   r.   r:   rC   r   r   r   r   r>   b   s   r>   c                   @   s   e Zd ZdS )ModuleFilesDiskTestsNr0   r   r   r   r   rD   r   s   rD   c                   @   s   e Zd ZdS )ModuleFilesZipTestsNr0   r   r   r   r   rE   v   s   rE   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')
        r@   )__init__.pyz	submod.pyrA   c_resources)rG   rA   )somepkg	frozenpkgc                 C   s   t djdksJ dS )W
        Without any parameter, files() will infer the location as the caller.
        rI   r@   N	importlibimport_modulevalr%   r   r   r   test_implicit_files_package   s    z0ImplicitContextFiles.test_implicit_files_packagec                 C   s   t djdksJ dS )rK   zsomepkg.submodr@   NrL   r%   r   r   r   test_implicit_files_submodule   s    z2ImplicitContextFiles.test_implicit_files_submodulec                 C   sr   | j t }t|d}ttjj}|	dD ]&}|
||d}t|| q4| j t| dS )z
        Make a compiled-only copy of the importlib resources package.

        Currently only code is copied, as importlib resources doesn't itself
        have any resources.
        rH   z**/*.pyz.pycN)Zfixturesenter_contextr   temp_dirpathlibPathr   __file__parentglobr   relative_towith_suffix
py_compilecompiler   ZDirsOnSysPath)r   Zbin_siterH   sourcessource_pathZc_pathr   r   r   _compile_importlib   s    z'ImplicitContextFiles._compile_importlibc                 C   s    |    tdjdksJ dS )zk
        Caller detection works for compiled-only resources module.

        python/cpython#123085
        rJ   r@   N)r_   rM   rN   rO   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:   rP   rQ   r_   r`   r   r   r   r   rF   z   s"   rF   c                   @   s   e Zd ZdS )ImplicitContextFilesDiskTestsNr0   r   r   r   r   rd      s   rd   c                   @   s   e Zd ZdS )ImplicitContextFilesZipTestsNr0   r   r   r   r   re      s   re   __main__)#
contextlibrM   rT   r[   ra   Zunittestr   Zimportlib_resourcesr   abcr   r?   r   Zcompat.py39r   r   contextmanagerr   r   Z	DiskSetupZTestCaser/   ZZipSetupr1   r2   r8   r9   r>   rD   rE   rF   rd   re   r,   mainr   r   r   r   <module>   s<   
;


