o
    gm                     @   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 dS )"    N   )Traversable   )util)import_helper	os_helperc                  c   sH    t jdd} t jdtd | V  W d    d S 1 sw   Y  d S )NT)recorddefault)category)warningscatch_warningssimplefilterDeprecationWarning)ctx r   [/var/www/visachat/venv/lib/python3.10/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   
assertTrueis_file)r   r   binfiler   r   r    test_joinpath_with_multiple_args%   s   z+FilesTests.test_joinpath_with_multiple_argsc                 C   s:   t   tj| jd W d   dS 1 sw   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                   @      e Zd ZdS )OpenDiskTestsNr.   r/   r0   r   r   r   r   r2   3       r2   c                   @   r1   )OpenZipTestsNr3   r   r   r   r   r5   7   r4   r5   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__)r7   __path__appendr   r   )r   r7   r   r   r   test_non_paths_in_dunder_path>   s
   z0OpenNamespaceTests.test_non_paths_in_dunder_pathN)r.   r/   r0   MODULEr:   r   r   r   r   r6   ;   s    r6   c                   @   s   e Zd ZdZdS )OpenNamespaceZipTestsr7   N)r.   r/   r0   
ZIP_MODULEr   r   r   r   r<   S   s    r<   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.
    unusedc                 C   s   |  | j d S r#   )tree_on_pathspec)r   namer   r   r   load_fixture^   s   zDirectSpec.load_fixtureN)r.   r/   r0   __doc__r;   rC   r   r   r   r   r>   W   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sJ dS )zK
        A module can have resources found adjacent to the module.
        r   NrH   r   r   )modr   r   r   r!   rA   )r   rI   r   r   r   r   test_module_resourcesh   s   z"ModulesFiles.test_module_resourcesN)r.   r/   r0   rA   rJ   r   r   r   r   rE   b   s
    rE   c                   @   r1   )ModuleFilesDiskTestsNr3   r   r   r   r   rK   r   r4   rK   c                   @   r1   )ModuleFilesZipTestsNr3   r   r   r   r   rL   v   r4   rL   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')
        rG   )__init__.pyz	submod.pyrH   c_resources)rN   rH   )somepkg	frozenpkgc                 C      t djdks
J dS )W
        Without any parameter, files() will infer the location as the caller.
        rP   rG   N	importlibimport_modulevalr%   r   r   r   test_implicit_files_package      z0ImplicitContextFiles.test_implicit_files_packagec                 C   rR   )rS   zsomepkg.submodrG   NrT   r%   r   r   r   test_implicit_files_submodule   rY   z2ImplicitContextFiles.test_implicit_files_submodulec                 C   sr   | j t }t|d}ttjj}|	dD ]}|
||d}t|| q| 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.
        rO   z**/*.pyz.pycN)fixturesenter_contextr   temp_dirpathlibPathr   __file__parentglobr   relative_towith_suffix
py_compilecompiler   DirsOnSysPath)r   bin_siterO   sourcessource_path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
        rQ   rG   N)rl   rU   rV   rW   r%   r   r   r   +test_implicit_files_with_compiled_importlib   s   z@ImplicitContextFiles.test_implicit_files_with_compiled_importlibN)r.   r/   r0   textwrapdedentr   set_valreplacerA   rX   rZ   rl   rm   r   r   r   r   rM   z   s$    rM   c                   @   r1   )ImplicitContextFilesDiskTestsNr3   r   r   r   r   rr          rr   c                   @   r1   )ImplicitContextFilesZipTestsNr3   r   r   r   r   rt      rs   rt   __main__)#
contextlibrU   r^   re   rn   unittestr   importlib_resourcesr   abcr   rF   r   compat.py39r   r   contextmanagerr   r   	DiskSetupTestCaser2   ZipSetupr5   r6   r<   r>   rE   rK   rL   rM   rr   rt   r.   mainr   r   r   r   <module>   s@    

;
