
    -PhE                     R    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
 d Zd ZdS )z$Test the example recommender plugin.    N)ExampleRecommender_write_recommendationsc                     t          j        d          } t                      }ddddddg}|                    |          }|                     g dg dg          }| j                            ||           |                    |          }|                     g d	g d
g          }| j                            ||           dS )z0Test dict_vectorizer and compute_tf_idf methods.numpy      )foobar   )r	   baz)g       @              ?)r   r   g      @)g5#&?r   g9ms?)r   g!&?gfAC?N)	pytestimportorskipr   dict_vectorizerarraytestingassert_array_equalcompute_tf_idfassert_array_almost_equal)nprecommenderDX
expected_XX_tfidfexpected_X_tfidfs          e/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx_gallery/tests/test_recommender.py test_example_recommender_methodsr      s    		W	%	%B$&&K1		q334A##A&&A???OOO<==JJ!!!Z000((++Gxx	&	&	&(E(E(EF  J((2BCCCCC    c                     t          j        d            d                             ddg           ddddd	}|                                D ]\  }}t          j                             d
         |          }t          |d          5 }|                    |           ddd           n# 1 swxY w Y   t          j
        d|dd            t          j        dd|          }t          j        dd|          }t          j        |          5 }|                                }ddd           n# 1 swxY w Y   ||v sJ d t	          j         d
                   D             }	 fd|	D             }
t!          dd          }|                    |
           |                    |          }t          j                            |d                   dk    sJ t          j                             d
         d          }t	          j        |d           d}t          j                            ||          }t          |d          5 }	 ddd           n# 1 swxY w Y   t          j        dd|          }t+          ||            t          j        |          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ dS )z;Test generated files and that recommendations are relevant.r   r   )enableT)rubric_headerzCustom headerz,The quick brown fox jumped over the lazy dogzThe lazy dog slept all dayz+The quick brown fox ate the lazy dog's foodz&The quick dog jumped over the lazy fox)fox_jumps_dog.pyzdog_sleeps.pyzfox_eats_dog_food.pyzdog_jumps_fox.pygallery_dirwNexample_rstr   z\.py$z.rstz.recommendationsc                 d    g | ]-}t           j                            |          d          dk    +|.S )r   z.py)ospathsplitext).0fnames     r   
<listcomp>z-test_recommendation_files.<locals>.<listcomp>:   sB       7E""1%.. 	...r    c                 \    g | ](}t           j                            d          |          )S )r%   )r)   r*   join)r,   r-   gallery_confs     r   r.   z-test_recommendation_files.<locals>.<listcomp>?   s;       =B\-0%88  r    r   )
n_examplesmin_dfr$   zimages/thumbT)exist_okz sphx_glr_fox_jumps_dog_thumb.pngwbz.. rubric:: Custom header)r   r   updateitemsr)   r*   r0   openwritesgsave_rst_exampleresubcodecsreadlistdirr   fitpredictbasenamemakedirsr   )r1   	file_dict	file_namecontent	file_pathf	test_filerecommendation_filerstpy_filesgallery_py_filesr   recommended_example
thumb_pathpng_filepng_file_paths   `               r   test_recommendation_filesrS       s   
   &&	=>   K5 MD	 I (oo// * *	7GLLm!<iHH	)S!! 	QGGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
M9aLIIIF8VY77	 fX/A9MM[## 	q&&((C	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 #c))))) Z] ;<<  H
   FN   %!<<<KOO$%%%%--i887/2337IIIII l=9>JJJK
T****1HGLLX66M	mT	"	" a               &+=yII;	<@@@	(	)	) Qffhh              &#------sH   	B++B/	2B/	D//D3	6D3	IIIJ<<K K )__doc__r>   r)   r<   r   sphinx_gallery.gen_rstgen_rstr:   sphinx_gallery.recommenderr   r   r   rS    r    r   <module>rY      s    + *  				 				  # # # # # # Q Q Q Q Q Q Q QD D D"5. 5. 5. 5. 5.r    