o
    tBhE                     @   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Zddlm	Z	 ddl
mZ ddl
mZ ddlmZ ddlmZ dadadag dZd	d
 Zdd Zdd Zdd Zdd Zdd Zdd ZdS )av  This test for the LFW require medium-size data downloading and processing

If the data has not been already downloaded by running the examples,
the tests won't run (skipped).

If the test are run, the first execution will be long (typically a bit
more than a couple of minutes) but as the dataset loader is leveraging
joblib, successive runs will be fast (less than 200ms).
    N)partial)fetch_lfw_pairs)fetch_lfw_people)assert_array_equal)check_return_X_y)Abdelatif_SmithAbhati_KeplerCamara_AlvaroChen_DupontJohn_Lee
Lin_Bauman
Onur_Lopezc               	   C   s  t d} tjddatjtdatjdda	tj
ts#tt td}tjd}i }tD ]G}tjtd|}tj
|sGt| |dd	}|||< t|D ]#}tj||d
|  }|jdddd}	| |	tj}
|
| qUq2ttjtddd}|d W d   n1 sw   Y  ttjtddj}|d dd | D }td	D ]}||}|t|| d\}}|d|||f   qtd	D ]+}|td\}}|t|| }|t|| }|d||||f   qW d   n	1 sw   Y  ttjtdd}|d W d   n	1 s2w   Y  ttjtdd}|d W d   dS 1 sSw   Y  dS )z<Test fixture run once and common to all tests of this modulez	PIL.Imagescikit_learn_lfw_test_)prefixlfw_homescikit_learn_empty_test_*   lfw_funneled      z	_%04d.jpgr      )   r      )sizez	.test.swpwbs.   Text file to be ignored by the dataset loader.NzpairsDevTrain.txts   10
c                 S   s   g | ]
\}}|d kr|qS )    ).0namecountr   r   v/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/sklearn/datasets/tests/test_lfw.py
<listcomp>O   s    z setup_module.<locals>.<listcomp>r   z	%s	%d	%d
z%s	%d	%s	%d
zpairsDevTest.txts&   Fake place holder that won't be testedz	pairs.txt)pytestimportorskiptempfilemkdtempSCIKIT_LEARN_DATAospathjoinLFW_HOMESCIKIT_LEARN_EMPTY_DATAexistsmakedirsrandomRandomnpRandomState
FAKE_NAMESrandintrange	fromarrayastypeuint8saveopenwriteitemschoicesampleencodearange)Imagerandom_statenp_rngcountsr   folder_namen_facesi	file_pathunifaceimgfmore_than_twofirstsecond
first_namesecond_namefirst_indexsecond_indexr   r   r    setup_module(   sb   






$rR   c                   C   s4   t jtrtt t jtrtt dS dS )z?Test fixture (clean up) run once after all tests of this moduleN)r'   r(   isdirr&   shutilrmtreer+   r   r   r   r    teardown_moduleg   s
   
rV   c                   C   <   t t ttdd W d    d S 1 sw   Y  d S NF	data_homedownload_if_missing)r"   raisesIOErrorr   r+   r   r   r   r    test_load_empty_lfw_peopleo      "r^   c                  C   s   t tddd} | jjdksJ | jjdksJ t| jg d g d}t| j| t td d ddd	} | jjd
ks:J | j	dsBJ t| jg d t| jg d t
t td d ddd	}t| | d S )Nr   FrZ   min_faces_per_personr[   )
   >   /   )rb   ib  )
r   r   r   r   r   r   r   r   r   r   )Abdelatif SmithAbhati Kepler
Onur LopezTrZ   resizeslice_colorr[   )   r   r   r   &.. _labeled_faces_in_the_wild_dataset:)r   r   r      r   rn   r   rn   r   r   rn   r   r      r   r   r   )re   rf   zCamara AlvarozChen DupontzJohn Leez
Lin Baumanrg   )r   r&   imagesshapedatar   targettarget_namesDESCR
startswithr   r   )
lfw_peopleexpected_classes
fetch_funcr   r   r    test_load_fake_lfw_peoplet   sB   
rz   c                   C   s>   t t ttddd W d    d S 1 sw   Y  d S )Nd   Fr`   )r"   r\   
ValueErrorr   r&   r   r   r   r    )test_load_fake_lfw_people_too_restrictive   s   "r}   c                   C   rW   rX   )r"   r\   r]   r   r+   r   r   r   r    test_load_empty_lfw_pairs   r_   r~   c                  C   s   t tdd} | jjdksJ t| jg d ddg}t| j| t td d ddd} | jjd	ks1J t| jg d t| j| | jd
sGJ d S )NFrY   )rb   r   rc   rd   )
r   r   r   r   r   r   r   r   r   r   zDifferent personszSame personTrh   )rb   r   r   r   r   rm   )	r   r&   pairsrq   r   rs   rt   ru   rv   )lfw_pairs_trainrx   r   r   r    test_load_fake_lfw_pairs   s$   r   )__doc__r.   r'   rT   r$   numpyr0   r"   	functoolsr   sklearn.datasetsr   r   sklearn.utils._testingr   "sklearn.datasets.tests.test_commonr   r&   r+   r*   r2   rR   rV   r^   rz   r}   r~   r   r   r   r   r    <module>   s.    
?:	