o
    iq                     @   s   d 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mZ dd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Ze	ejfddZe	dd Zdd Zdd ZdS ) z
Utilities for testing code.
    N)Path)contextmanager   )__version__)check_version
get_loggerc                 C   sf   t j| sJ t| dd}| }W d   n1 sw   Y  dddg}| |ks1J dS )zN
    Load the tiny-data.txt file and check that the contents are correct.
    utf-8encodingN
z)# A tiny data file for test purposes only1  2  3  4  5  6)ospathexistsopenreadjoinstrip)fnameZtinydatacontenttrue_content r   `/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/pooch/tests/utils.pycheck_tiny_data   s   
r   c                 C   st   t j| sJ t| dd}| }W d   n1 sw   Y  dg}|dgd  | d|ks8J dS )zO
    Load the large-data.txt file and check that the contents are correct.
    r   r	   Nz*# A larer data file for test purposes onlyr   ir  r   )r   r   r   r   r   extendr   r   )r   datar   r   r   r   r   check_large_data#   s   
r   c                  C   s   t tdd} d|  d}|S )as  
    Get the base URL for the test data used in Pooch itself.

    The URL is a GitHub raw link to the ``pooch/tests/data`` directory from the
    `GitHub repository <https://github.com/fatiando/pooch>`__. It matches the
    pooch version specified in ``pooch.version.full_version``.

    Returns
    -------
    url
        The versioned URL for pooch's test data.

    main)fallbackz&https://github.com/fatiando/pooch/raw/z/pooch/tests/data/)r   full_version)versionurlr   r   r   pooch_test_url/   s   r"   c                  C      d} | S )z
    Get the base URL for the test data stored in figshare.

    The URL contains the DOI for the figshare dataset using the appropriate
    version for this version of Pooch.

    Returns
    -------
    url
        The URL for pooch's test data.

    z$doi:10.6084/m9.figshare.14763051.v1/r   r!   r   r   r   pooch_test_figshare_urlB      r%   c                  C   r#   )z
    Get the base URL for the test data stored in Zenodo.

    The URL contains the DOI for the Zenodo dataset using the appropriate
    version for this version of Pooch.

    Returns
    -------
    url
        The URL for pooch's test data.

    zdoi:10.5281/zenodo.4924875/r   r$   r   r   r   pooch_test_zenodo_urlS   r&   r'   c                  C   r#   )aj  
    Get base URL for test data in Zenodo, where the file name contains a slash

    The URL contains the DOI for the Zenodo dataset that has a slash in the
    filename (created with the GitHub-Zenodo integration service), using the
    appropriate version for this version of Pooch.

    Returns
    -------
    url
        The URL for pooch's test data.

    zdoi:10.5281/zenodo.7632643/r   r$   r   r   r    pooch_test_zenodo_with_slash_urld   s   r(   c                  C   r#   )z
    Get the base URL for the test data stored on a DataVerse instance.

    Returns
    -------
    url
        The URL for pooch's test data.
    zdoi:10.11588/data/TKCFEF/r   r$   r   r   r   pooch_test_dataverse_urlv   s   	r)   c                  C   s   dddddddddd	d

} | S )z
    Get a registry for the test data used in Pooch itself.

    Returns
    -------
    registry
        Dictionary with pooch's test data files and their hashes.

    Z@baee0894dba14b12085eacb204284b97e362f4f3e5a5807693cc90ef415c1b2dZ@98de171fb320da82982e6bf0f3994189fff4b42b23328769afce12bdd340444aZ@0d49e94f07bc1866ec57e7fd1b93a351fba36842ec9b13dd50bf94e8dfa35cbbZ@0498d2a001e71051bbd2acd2346f38da7cbd345a633cb7bf0f8a20938714b51aZ@41503f083814f43a01a8e9a30c28d7a9fe96839a99727a7fdd0acf7cd5bab63bZ@088c7f4e0f1859b1c769bb6065de24376f366374817ede8691a6ac2e49f29511Z@753663687a4040c90c8578061867d1df623e6aa8011c870a5dbd88ee3c82e306Z@2e2da6161291657617c32192dba95635706af80c6e7335750812907b58fd4b52Z@99dcb5c32a6e916344bacb4badcbc2f2b6ee196977d1d8187610c21e7e607765)
ztiny-data.txtzlarge-data.txtzsubdir/tiny-data.txtztiny-data.zipz	store.zipztiny-data.tar.gzzstore.tar.gzztiny-data.txt.bz2ztiny-data.txt.gzztiny-data.txt.xzr   )registryr   r   r   pooch_test_registry   s   r+   c                 c   s@    t  }t|}||  t | |V  t | dS )z
    Create a context manager for reading from the logs.

    Yields
    ------
    log_file : StringIO
        a file-like object to which the logs were written
    N)ioStringIOloggingStreamHandlersetLevelr   
addHandlerremoveHandler)levelZlog_filehandlerr   r   r   capture_log   s   


r5   c              	   c   s    t ttjd | }tj| j|}zt	|| d| }|V  W tj
|r1t| dS dS tj
|r?t| w w )a  
    Add a test data file to the test FTP server and clean it up afterwards.

    Parameters
    ----------
    server
        The ``ftpserver`` fixture provided by pytest-localftpserver.
    fname : str
        The name of a file *relative* to the test data folder of the package
        (usually just the file name, not the full path).

    Yields
    ------
    url : str
        The download URL of the data file from the test FTP server.

    r   zftp://localhost/N)strr   __file__parentr   r   r   Z	anon_rootshutilcopyfiler   remove)serverr   package_pathZserver_pathr!   r   r   r   data_over_ftp   s   
r>   c                 C   s8   |   D ]}| r|| j|B  t|| qdS )zg
    Recursively change the permissions on the child directories using a bitwise
    OR operation.
    N)iterdiris_dirchmodstatst_mode_recursive_chmod_directories)rootmodeitemr   r   r   rD      s   
rD   c                 C   s4   t | } t || j }t| | t|tjd |S )a  
    Copy contents of the source directory into destination and fix permissions.

    Parameters
    ----------
    source : str, :class:`pathlib.Path`
        Source data directory.
    destination : str, :class:`pathlib.Path`
        Destination directory that will contain the copy of source. The actual
        source directory (not just it's contents) is copied.

    Returns
    -------
    mirror : :class:`pathlib.Path`
        The path of the mirrored output directory.

    )rF   )r   namer9   copytreerD   rB   S_IWUSR)sourcedestinationZmirrorr   r   r   mirror_directory   s
   rM   )__doc__r   r,   r.   r9   rB   pathlibr   
contextlibr    r   r   utilsr   r   r   r   r"   r%   r'   r(   r)   r+   DEBUGr5   r>   rD   rM   r   r   r   r   <module>   s0   
