
    qi                     L    d dl Z d dlZd dlZd dlmZ d dlmZ d Zd Z	d Z
d Zy)    N)download)build_indexc                 \    t        | j                  d            }t        d|      }|du sJ y)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_statuss      P/opt/pipecat/venv/lib/python3.12/site-packages/nltk/test/unit/test_downloader.py2test_downloader_using_existing_parent_download_dirr   	   s3     x((78Lz<8Od"""    c                 ^    t        | j                  dd            }t        d|      }|du sJ y)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   s      r   6test_downloader_using_non_existing_parent_download_dirr      s<     68UVL z<8Od"""r   c           	      h   d}d}t        | j                  d            }t        ||dz         D ]  }t        j                  j                  d      5 }t        d|      }|du sJ ||k(  rht        j                  j                  dt        j                  j                  dd	      z        }|j                  d   j                  |j                  k(  sNJ ||k(  rGt        j                  j                  d
      }|j                  d   j                  |j                  k(  sJ ddd        y# 1 sw Y   xY w)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_calls           r   test_downloader_redownloadr(      s6    NOx(()?@AL>?Q#67 V]]  !12 	Vj&{LAO"d***N"'/}}'9'91ggll9o>?($ "00388<P<U<UUUUo%'/}}'9'9L($ "00388<P<U<UUUU	V 	VV	V 	Vs   CD''D1	c                 j   t        | j                  d            }d}t        j                  j	                  ||       }t        j
                  |d       t        j                  j	                  || d      }t        |d      5 }|j                  d| d       d	d	d	       t        j                  j	                  ||       }t        j                  |d
|t        j                  j                  |             t        t        j                  j                  |      d      }|d   d   }|j                  d      dk(  sJ |j                  d      }	t        |	t               sJ t        |	      dkD  sJ |j                  d      }
t        |
t               sJ t        |
      dkD  sJ y	# 1 sw Y   xY w)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_checksumr8   s              r   test_build_indexrL   4   s    x((45L"MGGLL-BMKK-GGLL=/0FGM	mS	! 
R
M? + 	

 ww||Mm_>H
!!-0	 WW__\*5FI  l1oOt$666"&&z2LlC(((|q   %))*;<Oos+++!###/
 
s   F((F2)r   r<   unittest.mockr   nltkr   nltk.downloaderr   r   r   r(   rL    r   r   <module>rQ      s)    	    '##V2$r   