o
    i                     @   sT   d dl Z d dlZd dlZd dlmZ d dlmZ dd Zdd Z	dd	 Z
d
d ZdS )    N)download)build_indexc                 C   s(   t | d}td|}|du sJ dS )zSTest that download works properly when the parent folder of the download_dir existsanother_dirmwa_ppdbTNstrjoinpathr   tmp_pathdownload_dirdownload_status r   Y/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/nltk/test/unit/test_downloader.py2test_downloader_using_existing_parent_download_dir	   s   
r   c                 C   s*   t | dd}td|}|du sJ dS )z[Test that download works properly when the parent folder of the download_dir does not existznon-existing-parent-folderzanother-non-existing-folderr   TNr   r	   r   r   r   6test_downloader_using_non_existing_parent_download_dir   s
   

r   c              	   C   s   d}d}t | d}t||d D ]U}tjdE}td|}|du s&J ||krCtjdtj	
dd	 }|jd j|jksBJ n||krXtjd
}|jd j|jksXJ W d   n1 sbw   Y  qdS )zOTest that a second download correctly triggers the 'already up-to-date' messager      test_repeat_downloadzbuiltins.print	stopwordsTz[nltk_data]   Unzipping %s.corporazstopwords.zipz6[nltk_data]   Package stopwords is already up-to-date!N)r   r   rangeunittestmockpatchr   callospathjoincall_args_listargs)r
   first_downloadsecond_downloadr   i
print_mockr   expected_second_callr   r   r   test_downloader_redownload   s.   
r$   c                 C   s0  t | d}d}tj|| }tj|dd tj|| d}t|d}|d| d W d	   n1 s;w   Y  tj|| }tj	|d
|tj
|d ttj|dd}|d d }|ddksnJ |d}	t|	t szJ t|	dksJ |d}
t|
t sJ t|
dksJ d	S )z(Test building index with both checksums.packagestest_packageT)exist_okz.xmlwz<package id="zF" name="A Test Package" webpage="http://www.somefake.url/" unzip="1"/>Nzip)	base_nameformatroot_dirbase_dirzhttps://someurl)rootbase_urlr   idchecksum   sha256_checksum)r   r   r   r   r   makedirsopenwriteshutilmake_archivebasenamer   dirnameget
isinstancelen)r
   test_pkg_dirtest_pkg_nametest_pkg_pathtest_xml_pathfizip_path	xml_indexpackage_elementmd5_checksumr3   r   r   r   test_build_index4   s8   



rG   )r   r7   unittest.mockr   nltkr   nltk.downloaderr   r   r   r$   rG   r   r   r   r   <module>   s    
