o
    7f5                     @   s  U d dl Z d dlZd dlmZ d dlZd dlZd dlZd dlm	Z	m
Z
mZmZmZmZ d dlZd dlmZmZmZ i ZeejjZz<d dlZeeedddZeD ](Zeee dZeerre defd	d
efee< qTe defd	ee< qTW n- e!y Z" z!e#dd$ dkre%de" ej&de" dd W Y dZ"["ndZ"["ww i Z'e
e(e
e(e	f f e)d< e* Z+eee(e(f  e)d< eeeddZ,dd eD Z-ej./de-Z0dKddZ1e0de(dee2e2f deee( ee( f ddfddZ3ej./dg ed 4d ed! 4d"dejddfd#d$Z5d%e(d&e(dee2 de(d'ee( ddfd(d)Z6e7d*Z8e7d+Z9e7d,Z:e7d-Z;e7d.Z<e7d/Z=e7d0Z>e7d1Z?d2e(d3e(deee2 ee2 f de(d'eee( ee( f ddfd4d5Z@ej./d6g d7d2e(d3e(d8e(ddfd9d:ZAej.jBe d;d<ej./d=g d>d2e(d3e(d?ee2 d@ee2 d8e(ddfdAdBZCh dCZDe0ej.jEdDdEde(dee2e2f dee2e2f ddfdFdGZFej.jEdDgdHdKdIdJZGdS )L    N)AnyDictIterableOptionalSetTuple)_builtin_dictionariessupported_languagesword_regex_defz..testsdataz-additional.wordlistlang)size80	wordlistsREQUIRE_ASPELLfalsetruez\Cannot run complete tests without aspell when REQUIRE_ASPELL=true. Got error during import:
zTaspell not found, but not required, skipping aspell tests. Got error during import:
   )
stacklevelglobal_err_dictsglobal_pairsc                 C   s:   g | ]}t td |d  d|dd |dd fqS )
dictionaryr   z.txt         )opjoin	_data_dir).0d r!   \/home/ertert/spirit/venv/lib/python3.10/site-packages/codespell_lib/tests/test_dictionary.py
<listcomp>2   s    ,r#   zfname, in_aspell, in_dictionaryreturnc                  C   s:   dd t D } dd tttdD }| |ksJ dS )z!Test consistency of dictionaries.c                 S   s   h | ]	}t |d  qS )r   r   basenamer   fr!   r!   r"   	<setcomp>=   s    z*test_dictionaries_exist.<locals>.<setcomp>c                 S   s   h | ]}t |qS r!   r%   r'   r!   r!   r"   r)   >   s    z*.txtN)_fnames_in_aspellglobr   r   r   )
doc_fnames
got_fnamesr!   r!   r"   test_dictionaries_exist;   s   r.   fname	in_aspellin_dictionaryc           	      C   s   g }t | ddG}|D ]<}|d\}}| }|d}z
t|||| | W q tyG } z|t|jdddd  W Y d}~qd}~ww W d   n1 sRw   Y  |rbtdd| dS )	+Test that all dictionary entries are valid.utf-8encoding->
   )maxsplitr   N)	opensplitlowerrstrip_check_err_repAssertionErrorappendstrr   )	r/   r0   r1   errorsfidlineerrrepexpr!   r!   r"   test_dictionary_formattingB   s"   
(	rH   filenamezdictionary*.txtz
tests/dataz
*.wordlistc                 C   sx   |  t}d }| jdd%}|D ]}|  }|d ur'||k s'J | d|}qW d    d S 1 s5w   Y  d S )Nr3   r4   z is not sorted)relative_torootr:   stripr<   )rI   relative_pathprevious_linefilecurrent_liner!   r!   r"   test_dictionary_sortingW   s   
"rQ   phrasemsg	languagesc                    s   t sd S |d u r
d S d v r  D ]
}t||||| qd S t fdd|D }dd| d| }|rD|sBJ | d| d S |rOJ | d| d S )	N c                 3   s4    | ]}t |  t |  d  d V  qdS )r5   r8   N)spellerscheckencode
ConfigKeys)r   r   rR   r!   r"   	<genexpr>x   s
    "
z _check_aspell.<locals>.<genexpr>zbe in aspell dictionaries (z, z) for dictionary z should z should not )rV   r;   _check_aspellanyr   )rR   rS   r0   r/   rT   wordthis_in_aspellendr!   rZ   r"   r\   i   s   r\   z\sz^\sz^,z\s,z,\s\sz,[^ ]z\s+$z^[^,]*,\s*$rE   rF   c           
      C   s  t | d u sJ d| dd| vsJ d| dt|dks,J d|  d|dt|r<J d|  d|dt| d| |d ||d  d|  d|}td	ftd
ftdft	dft
dftdffD ]\}}||rwJ ||f qg~|dr|dsJ d|  ddd |dD }dd |D }|D ]"}	| |	 ksJ d| dt|	d|  d|	|d ||d  qdd |D }tt|t|ksJ d|  d| dd S )Nerror z has whitespace,z has a commar   : correction z must be non-emptyz cannot start with whitespacez%s starts with a commaz6%s contains a whitespace character followed by a commaz>%s contains a comma followed by multiple whitespace charactersz-%s contains a comma *not* followed by a spacez%s has a trailing spacez3%s has a single entry but contains a trailing commaz1: multiple corrections must end with trailing ","c                 S      g | ]}|  qS r!   rL   r   rr!   r!   r"   r#          z"_check_err_rep.<locals>.<listcomp>c                 S      g | ]}t |r|qS r!   lenrf   r!   r!   r"   r#          z" corrects to itself amongst othersr8   c                 S   rd   r!   )r<   rf   r!   r!   r"   r#      rh   z: corrections "z" are not (lower-case) unique)
whitespacesearchrk   start_whitespacematchr\   start_commawhitespace_commacomma_whitespacescomma_without_spacewhitespace_endsingle_commacountendswithr;   r<   set)
rE   rF   r0   r/   rT   prefixregexrS   repsrg   r!   r!   r"   r>      s\   "

r>   zerr, rep, match))za abarzhas whitespace)za,ar}   zhas a comma)a z	non-empty)r~   z barzstart with whitespace)r~   z,barzstarts with a comma)r~   zbar,batz.*not.*followed by a space)r~   zbar ztrailing space)r~   zb ,arz*contains a whitespace.*followed by a comma)r~   zbar,zsingle entry.*comma)r~   zbar, batzmust end with trailing ",")r~   za, bar,z!corrects to itself amongst others)r~   r~   zcorrects to itself)r~   z	bar, Bar,uniquerp   c                 C   sH   t jt|d t| |ddttf W d   dS 1 sw   Y  dS )z#Test that our error checking works.rp   )NNdummyNpytestraisesr?   r>   r	   )rE   rF   rp   r!   r!   r"   test_error_checking   s   "r   zrequires aspell-en)reasonz'err, rep, err_aspell, rep_aspell, match))abcdefuvwxyz, bar,TNshould be in aspell)r~   r   FNshould not be in aspell)r~   zabcdef, uvwxyz,NTr   )r   r   TTr   )r   r   FTr   )r~   z
bar, back,NFr   )r~   zbar, back, Wednesday,NFr   )r   zghijkl, uvwxyz,TFr   )r   r   FFr   )r~   zabcdef uvwxyzNTr   )r~   zbar backNFr   )r~   zbar back WednesdayNFr   )r~   zbar back, abcdef uvwxyz, bar,NTr   )r~   z abcdef uvwxyz, bar back, ghijkl,NFr   )r~   z
bar abcdefNTr   )r~   zabcdef backNFr   
err_aspell
rep_aspellc                 C   sL   t jt|d t| |||fdttf W d   dS 1 sw   Y  dS )z/Test that our error checking works with aspell.r   r   Nr   )rE   rF   r   r   rp   r!   r!   r"   test_error_checking_in_aspell   s   0"r   >   dictionary.txtzdictionary_names.txtr   dictionary_code.txtr   dictionary_rare.txtr   dictionary_usage.txtr   dictionary_en-GB_to_en-US.txtr   r   r   r   r   r   zdictionary loop)namec                 C   sr  i }t | }tt}t| ddB}|D ]7}|d\}}	| }||vs0J d|d| |	d}	dd |	 d	D }
d
d |
D }
|
||< qW d   n1 sWw   Y  |D ]*}|	|spJ d|dt d|| D ]}||vsJ d| d| d| qtq^||f}|t
vsJ t
| t D ]\}}|D ]}||vsJ d|d| d| q||f}|tvr|D ].}||vsJ d|d| d| || D ]}||vsJ d| d| d| d| qq|t
vsJ t
| ||f}|tvr&|D ] }|| D ]}||vs"J d| d| d| d| qq|t
vs-J t
| q|t|< dS )r2   r3   r4   r6   ra   z already exists in r7   c                 S   rd   r!   re   rf   r!   r!   r"   r#   >  rh   z+test_dictionary_looping.<locals>.<listcomp>rb   c                 S   ri   r!   rj   rf   r!   r!   r"   r#   ?  rl   Nz$ does not match default word regex ''rc   z0 is an error itself in the same dictionary file z in dictionary z already exists in dictionary z from dictionary z" is an error itself in dictionary )r   r&   recompiler
   r:   r;   r<   r=   	fullmatchr   addr   itemsallowed_dups)r/   r0   r1   this_err_dictshort_fname
word_regexrC   rD   rE   rF   r|   rg   pairother_fnameother_err_dictr!   r!   r"   test_dictionary_looping+  s   











r   )dependsc                  C   s`   t D ]\} }}t| } t D ]\}}}t|}| |ftv s J qqtttt d ks.J dS )z!Test that all pairwise tests ran.r   N)r*   r   r&   r   rk   )f1_f2r!   r!   r"   test_ran_allr  s   

r   )r$   N)Hr+   osos.pathpathr   pathlibr   warningstypingr   r   r   r   r   r   r   codespell_lib._codespellr   r	   r
   rV   Path__file__parentrK   aspellr   dirname_test_data_dirr   	_wordlistisfileSpellerImportErrorrG   getenvr<   RuntimeErrorwarnr   rA   __annotations__ry   r   r   r*   markparametrizefname_paramsr.   boolrH   rglobrQ   r\   r   rm   ro   rq   rr   rs   rt   ru   rv   r>   r   skipifr   r   
dependencyr   r   r!   r!   r!   r"   <module>   s  
  













8'

E