U
    ?h                     @   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re$  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   V/var/www/html/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   
:
   
   
