o
    h                     @   s   d 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m	Z	 ej
jej
jgZdd Zdd Zd	d
 Zdd Zdd Zdd ZdS )zF
Test various resource downloading functions from resources/common.py
    N)common)TEST_MODELS_DIRTEST_WORKING_DIRc               	   C   sJ  t jtd} tj| d}tt t	
| W d    n1 s#w   Y  t|ddd}|d W d    n1 s?w   Y  d}t	
| t	j
||d tt t	j
|d	d W d    n1 siw   Y  tt t	j
|d	d	d
 W d    n1 sw   Y  t	j
|d	|d
 W d    d S 1 sw   Y  d S )Ndirztest.txtwzutf-8)encodingzUnban mox opal! 44dbf21b4e89cea5184615a72a825a36)md512345)r
   alternate_md5)tempfileTemporaryDirectoryr   ospathjoinpytestraisesFileNotFoundErrorr   assert_file_existsopenwrite
ValueError)test_dirfilenamefoutEXPECTED_MD5 r   ]/var/www/html/env_mimamsha/lib/python3.10/site-packages/stanza/tests/resources/test_common.pytest_assert_file_exists   s&   
"r   c                  C   sz   t jtd-} tjd| dddd tjd| ddd}t|tjs"J t|jdks+J W d    d S 1 s6w   Y  d S )	Nr   entokenizeewtF	model_dir
processorspackageverbose)r$   r%   r&      )	r   r   r   stanzadownloadPipeline
isinstancelenloaded_processors)r   pipeliner   r   r   test_download_tokenize_mwt%   s   "r0   c               	   C   s   t jtdZ} tjd| dddd tt| ddgksJ tj	| d}tt|}|g dks4J ttj	|dd	gksCJ |D ]}t
ttj	||d
ksWJ qEW d   dS 1 scw   Y  dS )z
    Test the download path for a single file rather than the default zip

    The expectation is that an NER model will also download two charlm models.
    If that layout changes on purpose, this test will fail and will need to be updated
    r   r    nerontonotes_charlmFr#   resources.jsonbackward_charlmforward_charlmr1   pretrainontonotes_charlm.pt   Nr   r   r   r)   r*   sortedr   listdirr   r   r-   r   en_diren_dir_listingir   r   r   test_download_non_default-   s   ""rA   c               	   C   s   t jtda} tjd| ddddgidd tt| ddgks"J tj	| d}tt|}|g d	ks8J tttj	|dd
dgksJJ |D ]}t
ttj	||dks^J qLW d   dS 1 sjw   Y  dS )a  
    Test the download path for two NER models

    The package system should now allow for multiple NER models to be
    specified, and a consequence of that is it should be possible to
    download two models at once

    The expectation is that the two different NER models both download
    a different forward & backward charlm.  If that changes, the test
    will fail.  Best way to update it will be two different models
    which download two different charlms
    r   r    r1   r2   anatemFr#   r3   r4   z	anatem.ptr8   r(   Nr:   r=   r   r   r   test_download_two_models?   s   $""rC   c                  C   s  t jtdy} td| dd\}}}}|dddksJ |dks"J td| ddid\}}}}|dddks9J |dks?J td| d	d
id\}}}}|dd
dksVJ |dks\J td| d
d\}}}}|d
d
dksqJ |dkswJ W d   dS 1 sw   Y  dS )zD
    Test a few options for specifying which processors to load
    r   r    Nztokenize,posdefault)r!   posr!   spacyrE   r"   )r   r   r   r   process_pipeline_parameters)r   langr$   r&   r%   r   r   r    test_process_pipeline_parametersW   s   "rI   c                  C   s   t t} d}|| v rt|dk r|d }|| v rt|dk s|| vs%J t | |d ks/J d| v s5J d| d v s=J | d d dksGJ t | d}d|v sSJ d|vsYJ d|d v saJ t | d}||ksmJ d S )	Nzd   zhaliaszzh-hansr!   Chinese	lang_name)r   load_resources_jsonr   r-   get_language_resources)	resourcesbad_langzh_resourceszh_hans_resourcesr   r   r   test_language_resourcesl   s    
rV   )__doc__r   r   r   r)   stanza.resourcesr   stanza.testsr   r   marktravisclient
pytestmarkr   r0   rA   rC   rI   rV   r   r   r   r   <module>   s    