
    -Ph#              
       |   d Z ddlZddlZddlmZ ddlmZ ddlZddlm	Z	 ddl
mZ ddlmZmZmZmZmZmZ d Zd	 Zej                            d
ddg          ej                            dej                            dd          ej                            ddd          g          d                         Zd ZdS )z'Testing the binder badge functionality.    N)deepcopy)Mock)Sphinx)ConfigError)_copy_binder_reqscheck_binder_confcheck_jupyterlite_confgen_binder_rstgen_binder_urlgen_jupyterlite_rstc                  >   d} dddddd}t          |          }dd	d
}t          | ||          }d}||k    sJ t          |          }d}d|d<   t          |||          }d}||k    sJ d}t          |          }||d<   t          | ||          }d                    |          }||k    sJ |                    d           t          |          }	d|	d<   t          j        t          d          5  t          |	          }ddd           n# 1 swxY w Y   g d}
|                                D ]m}||
v rt          |          }|                    |           t          j        t          d          5  t          |          }ddd           n# 1 swxY w Y   nddg}|D ]X}t          |          }||d<   t          j        t          d          5  t          |          }ddd           n# 1 swxY w Y   Yt          |          }ddi|d<   t          j        t          d          5  t          |          }ddd           n# 1 swxY w Y   t          |          }dd g|d<   d! }d"|_	        t          j        t          d#          5  t          ||          }ddd           n# 1 swxY w Y   t          i           }t          d          }||fD ]
}|i k    sJ t          |          }d$|d%<   t          j        t          d&          5  t          |          }ddd           n# 1 swxY w Y   t          |          }d'|d(<   t          | ||          }d)}||k    sJ t          |          }d*} d+|d,<   t          | ||          }d-}||k    sJ dS ).z)Testing binder URL generation and checks.zblahblah/mydir/myfile.pyhttp://test1.comorgrepobranch../requirements.txtbinderhub_urlr   r   r   dependenciesmydirblahblahgallery_dirssrc_dirzLhttp://test1.com/v2/gh/org/repo/branch?filepath=notebooks/mydir/myfile.ipynbzblahblah/mydir/files_&_stuff.pyz100%_testedz\http://test1.com/v2/gh/org/repo/100%25_tested?filepath=notebooks/mydir/files_%26_stuff.ipynbzmy_prefix/foofilepath_prefixzOhttp://test1.com/v2/gh/org/repo/branch?filepath={}/notebooks/mydir/myfile.ipynbz	test1.comr   zdid not supply a valid urlmatchN)r   notebooks_diruse_jupyter_labzbinder_conf is missing valueszrequirements_not.txtzdoc-requirements.txtr   z;Did not find one of `requirements.txt` or `environment.yml`testz0`dependencies` value should be a list of stringszrequirements.txtzthis_doesntexist.txtc                      d S N r#       m/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx_gallery/tests/test_interactive_example.pyapptmpztest_binder.<locals>.apptmpl       r$   /z*Couldn't find the Binder requirements fileblahfoozUnknown Binder config keyTr   zThttp://test1.com/v2/gh/org/repo/branch?urlpath=lab/tree/notebooks/mydir/myfile.ipynbz!blahblah/mydir/myfolder/myfile.pyntbk_folderr   zWhttp://test1.com/v2/gh/org/repo/branch?filepath=ntbk_folder/mydir/myfolder/myfile.ipynb)r   r   r   formatpoppytestraisesr   keyssrcdirr   )	file_path	conf_basegallery_conf_baseurlexpectedconf0special_file_pathprefixconf1conf2optional_keyskeyconf3dependency_file_testsifileconf6conf7r&   conf4conf5iconfconf_labconf_statics                          r%   test_binderrH      s   *I+- I "),,I)0ZHH
I/@
A
ACV  (???? YE9#E(O
*E3D
E
EC	G  (???? FYE%E

E+<
=
=C	 fVnn	  (????	II    UOOE(E/	{*F	G	G	G ' '&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' LKKMzz|| + +-		#];.MNNN 	+ 	+#E**C	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 45KL& + + %n]S
 
 
 	+ 	+ $E**C		+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ UOOE#V,E.	M
 
 
 ' '  &&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' UOOE/1GHE.   FM	{*V	W	W	W / /../ / / / / / / / / / / / / / / b!!Ed##E  {{{{{ UOOEE%L	{*E	F	F	F ' '&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 	""H"&H
H.?
@
@C	?  (???? 9%%K3I#0K 
K1B
C
CC	B  (??????sl   3DDD8FF	F	G33G7	:G7	0IIIJ//J36J3L22L69L6c                 x   t          |           gdd}t          |                     ddd                    }ddddd	d
}t          |          }t          j                    }t          j        t          |                      	 t          |||          }t          j        |           n# t          j        |           w xY wd}d}d}||v sJ ||v sJ ||v sJ t          j                            t          j                            |          dd          }	t          j        	                    |	          sJ dS )%Check binder rst generated correctly.r   r   r   	myfile.pyr   r   r   r   r   r   z( .. image:: images/binder_badge_logo.svgzU:target: http://test1.com/v2/gh/org/repo/branch?filepath=notebooks/mydir/myfile.ipynbz:alt: Launch binderimageszbinder_badge_logo.svgN)
strjoinr   osgetcwdchdirr
   pathdirnameisfile)
tmpdirr4   r2   r3   orig_dirrst	image_rst
target_rstalt_rstimage_fnames
             r%   test_gen_binder_rstr\      sK   *-f++:NNFKK
G[AABBI+- I "),,Iy{{HHS[[Y	3DEE
:IhJ#Gc>>>>',,
	""H.E K 7>>+&&&&&&&s   B* *C r   TFexample_fileexample_dirrK   subdirc                    t          |          gdd| id}t          |                    d|                    }t          j                    }t          j        t          |                     	 t          ||          }t          j        |           n# t          j        |           w xY wd}d}d|vrd}	d}
nd	}	d
}
| rd}nd}|                    |	||
          }d}||v sJ t          j        ||          s
J |            ||v sJ t          j	                            t          j	        
                    |          dd          }t          j	                            |          sJ dS )rJ   r   r   )r   r   jupyterlitez- .. image:: images/jupyterlite_badge_logo.svgzI:target: {root_url}/lite/{jupyter_part}.+index.html.+path={notebook_path}r_   z\.\.zexample_dir/myfile\.ipynbz	\.\./\.\.z example_dir/subdir/myfile\.ipynblab	notebooks)root_urljupyter_partnotebook_pathz:alt: Launch JupyterLiterL   zjupyterlite_badge_logo.svgN)rM   rN   rO   rP   rQ   r   r,   researchrR   rS   rT   )r   r]   rU   gallery_confr2   rV   rW   rX   target_rst_templaterd   rf   re   rY   rZ   r[   s                  r%   test_gen_jupyterlite_rstrk      s    V)?; L
 FKK
L99::Iy{{HHS[[!)\::
?I 	T  y  4; #"$++M ,  J )G9Z%%**s***c>>>>',,
	""H.J K 7>>+&&&&&&&s   /B B*c                     t          t          t          dd i          g d          } t          d |           J t          i |           J dg| _        t          d |           J t          i |           t
          j                            dd          dd dk    sJ d	d
d}t
          j                            dd	          d
d d}t          ||           |k    sJ d }d|i}t
          j                            dd          d|d}t          ||           |k    sJ d}t          j	        t          |          5  t          ddd|            d d d            d S # 1 swxY w Y   d S )Nz.rst)source_suffixr1   )specconfig
extensionsr1   jupyterlite_sphinxjupyterlite_contentsT)rr   r   notebook_modification_functionthis_is_the_contents_dirF)rr   r   c                     d S r"   r#   )notebook_contentnotebook_filenames     r%   rs   zCtest_check_jupyterlite_conf.<locals>.notebook_modification_function  r'   r$   rs   zFound.+unknown keys.+another_unknown_key.+unknown_key.+Allowed keys are.+jupyterlite_contents.+notebook_modification_function.+use_jupyter_labr   valueanother_value)unknown_keyanother_unknown_key)r   r   dictr	   rp   rO   rR   rN   r.   r/   r   )appconfr6   rs   r   s        r%   test_check_jupyterlite_confr      s"   
64.111	  C "$,,444!"c**222*+CN!$,,444!"c** "X7M N N*./ /     !;  D
 !#X7Q R R *. H
 "$,,8888   -.LMD !#X7M N N*H H "$,,8888	: 

 
{%	0	0	0 
 
#OLLc	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   <EE!$E!)__doc__rO   rg   copyr   unittest.mockr   r.   sphinx.applicationr   sphinx.errorsr   "sphinx_gallery.interactive_exampler   r   r	   r
   r   r   rH   r\   markparametrizerR   rN   rk   r   r#   r$   r%   <module>r      s~   . - 				 				              % % % % % % % % % % % %               z z zz' ' '< *T5M::
]K00
]Hk:: )' )'  ;:)'X3
 3
 3
 3
 3
r$   