
    -Ph                       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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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d
lm Z m!Z!m"Z"m#Z#m$Z$ dZ%dZ&e%e&z
  Z'dZ(dZ)dZ*dZ+e%e(z   e)z   e*z   e+z   Z,de, de,dz
   de,dz
   dZ, ej-        d            ej-        d          Z.e.j/        0                    d          s ej1        dd            ej-        d            ej2        d          d             Z3 ej2        d          d              Z4d! Z5d" Z6d# Z7d$ Z8d% Z9d& Z:d' Z;d( Z<d) Z=d* Z>d+ Z?d, Z@d- ZAd. ZBd/ ZCd0 ZDejE        F                    d1 ejG        d2d3d45           ejG        d6d7d85          g          d9             ZHd: ZId; ZJdzd=ZKd> ZLd? ZMejE        F                    d@ ejG        dAdBdC5           ejG        dDdEdF5          g          dG             ZNejE        F                    d@ ejG        dAdBdC5           ejG        dDdEdF5          g          dH             ZOdI ZPdJ ZQdK ZR ej2        d          dL             ZSejE        F                    dMdNddOhfdPdQdOhfdRdSdOhfdTdUdOhfdVddOdWhfdXdYdOdWhfdZd[dOdWhfd\dd]hfd^dd_hfd`dah dbfdcddddegfdfddgdhgfdidh dbfg          dj             ZTdk ZUdl ZVdm ZWdn ZXdo ZYdp ZZdq Z[dr Z\ds Z]dt Z^du Z_dv Z`dw Zadx Zbdy ZcdS ){z4Test the SG pipeline used with Sphinx and tinybuild.    N)StringIO)Path)Version)__version__)Sphinx)ExtensionError)docutils_namespace)
_get_image_has_graphviz_has_optipng_has_pypandocscale_image                  (|      )jupyterlite_sphinxzmatplotlib.animationffmpegzffmpeg is not availableT)allow_module_leveljoblibmodule)scopec                 "    t          | d          S )Nhtml_sphinx_apptmpdir_factoryreq_mplreq_pils      ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx_gallery/tests/test_full.py
sphinx_appr)   D   s    ~v...    c                 "    t          | d          S )Ndirhtmlr"   r$   s      r(   sphinx_dirhtml_appr-   I   s    ~y111r*   c                    t          j        d           |                                 d| z  }t          t                    j        dz  }d }t          j        |||           |dz  }|dz  |z  }|dz  dz  }t                      5  t          |||||t                      t                      	          }|                    d
g            d d d            n# 1 swxY w Y   |S )Nnumpyroot_	tinybuildc                     dS )N)_buildgen_modulesauto_examplesauto_examples_README_headerauto_examples_rst_indexauto_examples_with_rst )srcnamess     r(   ignorez_sphinx_app.<locals>.ignoreU   s    
 
r*   r<   docr3   toctrees)buildernamestatuswarningF)pytestimportorskipgetbasetempr   __file__parentshutilcopytreer	   r   r   build)	r%   r@   temp_dirsrc_dirr<   conf_dirout_dirtoctrees_dirapps	            r(   r#   r#   N   sH   
   ))++.Ck.C.CCH8nn#k1G
 
 
 OGXf5555 %H!K/Gh&3L 
		  #::JJ
 
 
 			%               Js   ACC Cc                 t   | j         }| j        }t          j        |dd          }t          j        |          sJ t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ d}||v sJ t          j        |dd          }t          j        |          sJ t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d	|v sJ | j        	                                }t          j        d
dd          }	d|	 d|v sJ dS )z$Test that a timings page is created.r5   zsg_execution_times.rstrutf-8Nz6:ref:`sphx_glr_auto_examples_plot_numpy_matplotlib.py`z(``plot_numpy_matplotlib.py``)zsg_execution_times.htmlz href="plot_numpy_matplotlib.html..examplesplot_numpy_matplotlib.py- : )
outdirsrcdiropjoinisfilecodecsopenread_statusgetvalue)
r)   rN   rL   timings_rstfidcontentparentheticaltimings_htmlrA   fnames
             r(   test_timingsri   w   s   GG ''?4LMMK9[!!!!!	[#w	/	/ 3((**              CwNNNN4MG####77O5NOOL9\"""""	\3	0	0 C((**              -8888((**FGD*&@AAE>>>V######s$   A22A69A6C..C25C2c                 `   | j         }| j        }t          j        |d          }t          j        |          rJ t          j        |d          }t          j        |          sJ t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   t                      }d|v sJ |r,d|v sJ | j	        j
        d         rd	|v sJ nd	|vsJ d
|v sJ nd|vsJ d	|vsJ | j                                        }t          j        ddd          }	d|	 d|v sJ dS )z'Test that an api usage page is created.zsg_api_usage.rstzsg_api_usage.htmlrR   rS   NzShref="gen_modules/sphinx_gallery.gen_gallery.html#sphinx_gallery.gen_gallery.setup"zalt="API unused entries graph"show_api_usagez alt="sphinx_gallery usage graph"zsrc="_images/graphviz-rT   rU   rV   rW   rX   )rY   rZ   r[   r\   r]   r^   r_   r`   r   configsphinx_gallery_confra   rb   )
r)   rN   rL   api_rstapi_htmlrd   re   has_graphvizrA   rh   s
             r(   test_api_usagerq      s   GGgg122Gy!!!!!ww 344H9X	XsG	,	, ((**               ??L	-	   
  
A/7::::01AB 	E5@@@@@5WDDDD'722222/w>>>>1@@@@((**FGD*&@AAE>>>V######s   ;BB #B c                     | j                                         }| j                                        }d}t                      r||vsJ n||v sJ d|                                vsJ dS )zTest that optipng is detected.zwill not be optimizedzoptipng versionN)ra   rb   _warningr   lower)r)   rA   wsubstrs       r(   test_optipngrw      sv    ((**F$$&&A$F~~ Q{{{{FLLNN222222r*   c           	         | j         }t          |          dz  dz  }|                                sJ t          |d          5 }|                                }ddd           n# 1 swxY w Y   t
          j                            |          }t          dddt           d          }t          |j
                  }|d= ||k    sJ |                    d	          }d
|vsJ d|v sJ d|vsJ t          | j                  }	|dz  }
t          j        |	j        |
           ~	|
dz  }|dz  dz  }|dz  dz  }|j        dz  }|dz  }|dz  dz  }t!          d||           t          j        ||                    d                     t          j        ||           t          j        |                    d          |           t          j        |dz  |dz  dz             t)                      5  t+          ||||dd          }t-          j        t0          d          5  |                    dg            ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |dz  dz  }|                                sJ t          |d          5 }t
          j                            |                                          }ddd           n# 1 swxY w Y   |                    ddd !           t          |j
                  }|d= d"d#dd$d%d#dd$d&d'd(d$d)d#dd$d*d'd+d$g}t7          |          t7          |          k    sJ t9          ||          D ]\  }}|j
        d,         |d,         k    sJ |d-         j        |d.         k    sJ |j
        d,                     |d/         .|d-         j
        d/                             |d/                   sJ ||k    sJ dS )0zTest junit output.zsphinx-galleryzjunit-results.xmlrbN04)errorsfailuresskippedtestsnametimerS   local_modulezexpected example failurez<failure messager:   r>   r3   r!   r?   rU   rV   futurezplot_future_imports_broken.pyNamesz.tempzlocal_module.pyr   )r@   	verbosityzHere is a summary of the )matchF235)r}   r~   r   plot_failing_exampler~   )	classnametagmessageplot_failing_example_thumbnailplot_numpy_matplotlibfailurezRuntimeError: Forcingplot_scraper_brokenplot_future_imports_brokenz(Passed even though it was marked to failr   r   r   r   )rY   r   is_filer_   r`   lxmletree
fromstringdict
N_EXAMPLESattribdecoderZ   rH   rI   rG   printmovewith_suffixcopyfiler	   r   rC   raisesr   rJ   updatelenzipr   
startswith)r)   tmp_pathrN   
junit_filerd   contentssuitewantgotrL   new_root_dirnew_src_dirnew_out_dirnew_toctree_dirnew_examples_dirpassing_fnamefailing_fnamerP   skips_and_fails
this_suitethis_examples                        r(   
test_junitr      s   Gg!114GGJ	j$		 388::              J!!(++Eo  D u|

CF$;;;;w''H))))%1111X----:$%%Ge#L
OGNL111&K(61K!H,z9O")J6$'AAM$x/2QQM	'=-000
K}88AABBB
K}---
K))'22MBBB
O,,8#&77   
		 ! !
 
 
 ]>1LMMM 	! 	!IIeR   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!! ! ! ! ! ! ! ! ! ! ! ! ! ! ! //2EEJ	j$		 23
%%chhjj112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 	KKcK555
u|

CF 0	
 	
 :	
 	
 1.	
 	
 /	
 	
 6A	
 	
+O6 u::_------$'$?$? W W 
L -k1JJJJJ!} L$77779J;9W777	".a='	2==l9>UVVVVV$;;;;;;sZ   A$$A(+A(01I!I8II	II	II"I2KKKc                     t          | j                  }t          j        |          }d|v sJ d|v sJ d|v sJ d|v sJ d|v sJ |dz  }|                                sJ g d}|D ]}||z                                  sJ | j                                        }dt           dt           |v sJ d	|v sJ | j
                                        }d
}t          j        ||t          j                  
J |            dS )zTest basic outputs.
index.htmlr5   r8   r7   r6   )z0auto_examples_rst_index/examp_subdir1/index.htmlz0auto_examples_rst_index/examp_subdir2/index.htmlz"auto_examples_rst_index/index.htmlz	executed z out of zafter excluding 0z.*fetching .*wrong_url.*404.*N)r   rY   oslistdiris_dirr   ra   rb   N_GOODr   rs   rer   DOTALL)	r)   rN   	out_filesgenerated_examples_dirfiles_to_checkfrA   rB   r   s	            r(   test_run_sphinxr   "  sc   :$%%G
7##I9$$$$i''''#y0000$	1111(I5555$6!((*****  N
  ' '!$$&&&&&&((**F3v33z33v====&((((!**,,G*D8D'29--99799999r*   c                     t          | j                  dz  }|dz                                  sJ |dz                                  sJ dS )zCTest download zipfiles still generated when user supplies index.rstr7   z#auto_examples_rst_index_jupyter.zipz"auto_examples_rst_index_python.zipN)r   rZ   r   )r)   rL   s     r(   test_user_index_downloadr   >  sZ    :$%%(AAG;;DDFFFFF::CCEEEEEEEr*   c                    ddl }t          j        | j        dd          }t          j        | j        dd          }t          |                    d                    }t          ||g| j        j        d         R   t                      }|
                    |                    |                    }|
                    |                    |                    }|j        dd	         |j        dd	         k    sJ |j        d	         d
v sJ |                    |dddf                                         |dddf                                                   d         }	|	dk    sJ dS )z#Test sphinx_gallery_thumbnail_path.r   N_static_nonstandardzdemo.png_imagesz-sphx_glr_plot_second_future_imports_thumb.pngnew.pngthumbnail_sizer      r   .r   r   r   Gz?)r/   r[   r\   rZ   rY   strr   rl   rm   r
   asarrayr_   shapecorrcoefravel
r)   tmpdirnp
fname_origfname_thumb	fname_newImageorignewcorrs
             r(   test_thumbnail_pathr   E  sh    *,A:NNJ'9&U K FKK	**++II * 1 EFV W    LLE::ejj--..D
**UZZ	**
+
+C9RaR=DJrrN****9Q<6!!!!;;s37|))++T#rr']-@-@-B-BCCDID$;;;;;;r*   c                    ddl }t          j        | j        dd          }t          j        | j        dd          }t	          |                    d                    }t          ||g| j        j        d         R   t                      }|	                    |
                    |                    }|	                    |
                    |                    }|j        dd         |j        dd         k    sJ |j        d         d	v sJ |                    |d
ddf                                         |d
ddf                                                   d         }	|	dk    sJ dS )zKTest 'sphinx_gallery_thumbnail_number' config correct for negative numbers.r   Nr   z$sphx_glr_plot_matplotlib_alt_002.pngz&sphx_glr_plot_matplotlib_alt_thumb.pngr   r   r   r   .r   r   r   )r/   r[   r\   rY   r   r   rl   rm   r
   r   r_   r   r   r   r   s
             r(   test_negative_thumbnail_configr   [  so    9&L J '9&N K FKK	**++II * 1 EFV W    LLE::ejj--..D
**UZZ	**
+
+C9RaR=DJrrN****9Q<6!!!!;;s37|))++T#rr']-@-@-B-BCCDID$;;;;;;r*   c                 V   ddl }t          j        | j        dd          }t	          |                    d                    }t          ||g| j        j        d         R   t                      }|	                    |
                    |                    }|j        d         dv sJ t          j        | j        d	d
          }|	                    |
                    |                    }|j        dd         |j        dd         k    sJ |                    |dddf                                         |dddf                                                   d         }	|	dk    sJ t          j        | j        d	d          }|	                    |
                    |                    }|j        dd         |j        dd         k    sJ |                    |dddf                                         |dddf                                                   d         }	|	dk     sJ dS )z7Test thumbnail behaviour for expected failing examples.r   Nr   zbroken_example.pngr   r   r   r   r   z'sphx_glr_plot_failing_example_thumb.png.r   r   r   z1sphx_glr_plot_failing_example_thumbnail_thumb.pnggffffff?)r/   r[   r\   rZ   r   r   rl   rm   r
   r   r_   r   rY   r   r   )
r)   r   r   stamp_fnamestamp_fname_scaledr   broken_stampthumb_fname	thumbnailr   s
             r(   (test_thumbnail_expected_failing_examplesr   s  s=    '02F K V[[3344 
		./?	@   
 LLE::ejj);<<==La F**** '9&O K 

5::k2233Ibqb!Y_RaR%88888;;|C!G,2244iRaR6H6N6N6P6PQQRVWD$;;;; '; K
 

5::k2233Ibqb!Y_RaR%88888;;|C!G,2244iRaR6H6N6N6P6PQQRVWD#::::::r*   c                    t          j        | j        d          }t          j        |d          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ d|vsJ t          j        |d          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   t          j        d	|          }d
 |D             dgz   }t          |          dk    sJ t          t          |dd         |dd                             D ]7\  }\  }}	|||	         }
|dk    rd|
v sJ d|
vsJ %|dk    rd|
v sJ d|
vsJ 8dS )z4Test `sphinx_gallery_multi_image(_block)` variables.r5   zplot_multi_image_separate.htmlrR   rS   Nzsphx-glr-single-imgzsphx-glr-multi-imgz$plot_multi_image_block_separate.htmlz*<div class="highlight-Python notranslate">c                 6    g | ]}|                                 S r9   )start).0r   s     r(   
<listcomp>z$test_multi_image.<locals>.<listcomp>  s     111ekkmm111r*   r   r   r   )r[   r\   rY   r^   r_   r`   r   finditerr   	enumerater   )r)   r   
html_fnamerd   r!   matchesstarts	block_idxr   end
block_htmls              r(   test_multi_imager     s9   WZ%6HH /1QRRJ	Zg	.	. #xxzz               D((((t++++ /1WXXJ	Zg	.	. #xxzz               kFMMG11111RD8Fv;;!#,SfQRRj-I-I#J#J : :	<E3%)_
>>':5555(
:::::!^^(J6666'z9999: :s$   A''A+.A+)C

CCc                     t          j        | j        d          }d}t          j        ||          }t          j        |          s
J |            d S )Nr5   z4../_images/sphx_glr_plot_command_line_args_thumb.png)r[   r\   rY   r]   )r)   r   r   
file_fnames       r(   test_command_line_args_imgr     sR    WZ%6HHHK/==J9Z  ,,*,,,,,r*   c                    t          j        | j        d          }t          j        |d          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   g d}|D ]A}t          j        ||          }t          j        |          s
J |            d| d}||v sJ Bd	d
dgfdddgfddddgfdddgfdddgffD ]\  }	}
}t          j        ||	 d          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   |D ]}d|	 d|dd|
 }t          j        ||          }t          j        |          s
J |            d| d}||v sJ d|	 d|dd|
 }t          j        ||          }d| d| d}|
dv r$t          j        |          s
J |            ||v sJ dS )zTest Image format support.r5   r   rR   rS   N)z&../_images/sphx_glr_plot_svg_thumb.svgz3../_images/sphx_glr_plot_numpy_matplotlib_thumb.pngz,../_images/sphx_glr_plot_animation_thumb.gifz(../_images/sphx_glr_plot_webp_thumb.webpzsrc=""plot_svgsvgr   r   pngplot_animationr   mp4r   	plot_webpwebpz.htmlz../_images/sphx_glr__03.z_2_00x.zsrcset="z, z 2.00x")r   jpgr   r   )r[   r\   rY   r^   r_   r`   r]   )r)   r   generated_examples_indexrd   r!   thumb_fnamesr   r   	want_htmlexextnumsr   num
img_fname0
img_fname2file_fname2s                    r(   test_image_formatsr    s   WZ%6HH!w'=|LL	-sG	<	< xxzz                L $ ! !W3[AA
y$$00j000*K***	D      
UQC 	 %!-	51a&)	51#&	fqc" ) )C W3\\\BB
[S'22 	c88::D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	) 	)CCCCSCCCcCCJ!7DDJ9Z((44*444-
---I$$$$IIISIIICIIJ'"8*EEKD:DDDDDI333y--::{::: D((((	)) )s$   A''A+.A+D,,D0	3D0	c                     t          j        | j        dd          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ d|v sJ dS )z%Test appropriate _repr_html_ classes.r5   plot_repr.htmlrR   rS   NzBdiv class="output_subarea output_html rendered_html output_result"zgallery-rendered-html.cssr[   r\   rY   r^   r_   r`   )r)   example_filerd   liness       r(   test_repr_html_classesr    s    7:,o?OPPL	\3	0	0 C

              OSXXXXX&%//////   AAAc                    | j         }| j        }t          j        |d          }t          j        |          sJ t          j        |          }d|v sJ t          j        |d          }t          j        |dd          5 }|	                                }ddd           n# 1 swxY w Y   d|v sJ d|v sJ d|v sJ d	|v sJ d
|v sJ d|v sJ d|v sJ d|v sd|v sJ d|v sJ d|v sJ d|v sJ d|v sJ d|v sJ d|v sJ d|v sJ d|v sJ t          j        d|          }|J d|v sJ d|v sJ t          j        d|          J d|v sJ t          j        d|          	 J t          j        d|          	 J t          j        d|          }	|	J t          j        d|          }
|
J t          j        d |          }|J t          j        d!          }|                    |          J t          j        d"|          }	|	J t          j        d#|          }
|
J t          j        d$|          }|J t          j        d%          }|                    |          J d&|vsJ d'|v sJ d(|v sJ d)D ]}d*| d+|v sJ t          j        |dd,          }t          j        |          sJ t          j        |dd          5 }|	                                }ddd           n# 1 swxY w Y   d-|v sJ d.}t          j        ||t          j                  J t           j                            |           t'          |          d/z                      d          }d0|v sJ dS )1z8Test that links and styles are embedded properly in doc.r5   plot_numpy_matplotlib.htmlrR   rS   Nz#module-matplotlib.colorszmatplotlib.colors.is_color_likezTclass="sphx-glr-backref-module-matplotlib-colors sphx-glr-backref-type-py-function">z#module-numpyznumpy.arange.htmlzHclass="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-function">z#module-matplotlib.pyplotzpyplot.htmlzpyplot_summary.htmlz+.html#matplotlib.figure.Figure.tight_layoutz8matplotlib.axes.Axes.plot.html#matplotlib.axes.Axes.plotz5matplotlib_configuration_api.html#matplotlib.RcParamszTmpl_toolkits.mplot3d.axes3d.Axes3D.plot.html#mpl_toolkits.mplot3d.axes3d.Axes3D.plotzstdtypes.html#listzwarnings.html#warnings.warnz!itertools.html#itertools.compressznumpy.ndarray.htmlz_sphinx_gallery.backreferences.html#sphinx[_,-]gallery[.,-]backreferences[.,-]identify[_,-]nameszclass="sphx-glr-backref-module-matplotlib-figure sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span></a>zrclass="sphx-glr-backref-module-matplotlib-figure sphx-glr-backref-type-py-class"><span class="n">Figure</span></a>z"sphx-glr-backref-module-\S*"a  class="sphx-glr-backref-module-sphinx_gallery-backreferences sphx-glr-backref-type-py-function"><span class="n">sphinx_gallery</span><span class="o">.</span><span class="n">backreferences</span><span class="o">.</span><span class="n">identify_names</span></a>z\.html#numpy\.random\.(mtrand\.?)?RandomState" title="numpy\.random\.(mtrand\.?)?RandomState" class="sphx-glr-backref-module-numpy-random(-mtrand?)? sphx-glr-backref-type-py-class"><span class="n">np</span>z\.html#numpy\.random\.(mtrand\.?)?RandomState" title="numpy\.random\.(mtrand\.?)?RandomState" class="sphx-glr-backref-module-numpy-random(-mtrand?)? sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">rng</span></a>zsphinx_gallery._dummy.html#sphinx[_-]gallery[.-]_dummy[.-][Dd]ummy[Cc]lass" title="sphinx_gallery._dummy.DummyClass" class="sphx-glr-backref-module-sphinx_gallery-_dummy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">dc</span>a]  sphinx_gallery._dummy.html#sphinx[_-]gallery[.-]_dummy[.-][Dd]ummy[Cc]lass" title="sphinx_gallery._dummy.DummyClass" class="sphx-glr-backref-module-sphinx_gallery-_dummy sphx-glr-backref-type-py-class"><span class="n">sphinx_gallery</span><span class="o">.</span><span class="n">_dummy</span><span class="o">.</span><span class="n">DummyClass</span>a!  sphinx_gallery._dummy.html#sphinx[_-]gallery[.-]_dummy[.-][Dd]ummy[Cc]lass[.-]run" title="sphinx_gallery._dummy.DummyClass.run" class="sphx-glr-backref-module-sphinx_gallery-_dummy sphx-glr-backref-type-py-method"><span class="n">dc</span><span class="o">.</span><span class="n">run</span>a9  sphinx_gallery._dummy.html#sphinx[_-]gallery[.-]_dummy[.-][Dd]ummy[Cc]lass[.-]prop" title="sphinx_gallery._dummy.DummyClass.prop" class="sphx-glr-backref-module-sphinx_gallery-_dummy sphx-glr-backref-type-py-(attribute|method|property)"><span class="n">dc</span><span class="o">.</span><span class="n">prop</span>a  sphinx_gallery._dummy.nested.html#sphinx[_-]gallery[.-]_dummy[.-]nested[.-][Nn]ested[Dd]ummy[Cc]lass" title="sphinx_gallery._dummy.NestedDummyClass" class="sphx-glr-backref-module-sphinx_gallery-_dummy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">ndc</span>a  sphinx_gallery._dummy.nested.html#sphinx[_-]gallery[.-]_dummy[.-]nested[.-][Nn]ested[Dd]ummy[Cc]lass" title="sphinx_gallery._dummy.NestedDummyClass" class="sphx-glr-backref-module-sphinx_gallery-_dummy sphx-glr-backref-type-py-class"><span class="n">sphinx_gallery</span><span class="o">.</span><span class="n">_dummy</span><span class="o">.</span><span class="n">nested</span><span class="o">.</span><span class="n">NestedDummyClass</span>aB  sphinx_gallery._dummy.nested.html#sphinx[_-]gallery[.-]_dummy[.-]nested[.-][Nn]ested[Dd]ummy[Cc]lass[.-]run" title="sphinx_gallery._dummy.NestedDummyClass.run" class="sphx-glr-backref-module-sphinx_gallery-_dummy sphx-glr-backref-type-py-method"><span class="n">ndc</span><span class="o">.</span><span class="n">run</span>aZ  sphinx_gallery._dummy.nested.html#sphinx[_-]gallery[.-]_dummy[.-]nested[.-][Nn]ested[Dd]ummy[Cc]lass[.-]prop" title="sphinx_gallery._dummy.NestedDummyClass.prop" class="sphx-glr-backref-module-sphinx_gallery-_dummy sphx-glr-backref-type-py-(attribute|method|property)"><span class="n">ndc</span><span class="o">.</span><span class="n">prop</span>zmemory usagezclass="sphx-glr-signature"zclass="sphx-glr-timing")pythonjupyterz+class="sphx-glr-download sphx-glr-download-z docutils container"plot_numpy_matplotlib.rstz.. code-block:: Python
zc.*plot_numpy_matplotlib\.py:[0-9][0-9]: RuntimeWarning: This warning should show up in the output.*zplot_pickle.htmlzjoblib.Parallel.html)rY   rZ   r[   r\   isdirr   r   r^   r_   r`   r   searchcompiler]   r   r   sysstdoutwriter   	read_text)r)   rN   rL   examples_direxample_filesr  rd   r  id_namesdummy_class_instdummy_class_classdummy_class_methdummy_class_propkindrh   rst	want_warns                    r(   test_embed_links_and_stylesr-    s   GG77O44L8L!!!!!J|,,M'=88887<)EFFL	\3	0	0 C

               '%////,5555^	 	 	 	 e####%''''R	 	 	 	 '%////E!!%:e%C%C%C%C8EAAAAENNNNBeKKKK^	 	 	 	  5(((((E1111.%77775((((yj H  	R	 	 	 	 	}	 	 	 	 95u==EEE 	N	 	 	 	 		 ^	
 	
 		 	 	 		 }	
 	
 		 	 	 y 	I  '''	 	i  (((y 	m  '''z 	E  ""5))555 y 	j  '''	 	D  (((y 	N  '''z 	f  ""5))555 &&&& (50000$----% 
 
T$TTT    
 GG_.IJJE9U	UC	)	) Shhjj              %,,,,	7  8Iubi00<<<JU,"44??HHE!U******s$   ?B  B$'B$K11K58K5c                    | j         }t          j        |dd          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ d|v sJ d|v sJ d	|v sJ t          j        |dd
          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ d|v sJ t          j        |dd          }t          j        |          sJ t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ d|v sJ d|vsJ dS )zTest backreferences.r4   zsphinx_gallery.sorting.htmlrR   rS   NExplicitOrderzplot_second_future_imports.htmlFileNameSortKeyr  "sphinx_gallery.backreferences.html
NameFinderzplot_future_imports.htmlr5   z@sphinx_gallery.sorting.html#sphinx_gallery.sorting.ExplicitOrderzBsphinx_gallery.scrapers.html#sphinx_gallery.scrapers.clean_moduleszfigure_rst.html)rY   r[   r\   r^   r_   r`   r]   )r)   rN   mod_filerd   r  r!   s         r(   test_backreferencesr4    sT   Gww/LMMH	XsG	,	, 

              e####,5555%%%%'50000ww/STTH	XsG	,	, 

              5    %....77O-NOOD9T??	T3	(	( Cxxzz              MQUUUUUOSWWWWWD((((((s5   AAA$CC	C	D??EEzrst_file, example_used_inz5sphinx_gallery.backreferences.identify_names.examplesr   identify_names)idz-sphinx_gallery.sorting.ExplicitOrder.examplesplot_second_future_importsr/  c                 6   | j         }t          j        |dd|          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   ||v sJ |                    d          }|                    d          }||k    sJ dS )8Test linking to mini-galleries using backreferences_dir.r4   backreferencesrR   rS   N<div</div)rZ   r[   r\   r^   r_   r`   count)	r)   rst_fileexample_used_inbackref_direxamples_rstrd   r  n_openn_closes	            r(    test_backreferences_examples_rstrD    s    " #K7;7GRRL	\3	0	0 C

              e####[[  Fkk'""GWs   AAAc                 :   t          j        | j        dd          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   t          j        d          }t          |	                    |                    }d                    d |
                    d          D                       }|d	k    s
J |            |                    d
          }|dk    sJ |                    d          }|dk    sJ |                    d          }	|	dk    sJ |                    d          }
|                    d          }|
|k    sJ t          j        | j        dd          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   t          j        d          }t          |	                    |                    }d                    d |
                    d          D                       }|dk    s
J |            |                    d
          }|dk    sJ |                    d          }|dk    sJ |                    d          }	|	dk    sJ |                    d          }
|                    d          }|
|k    sJ t          j        | j        dd          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   t          j        d          }t          |	                    |                    }d                    d |
                    d          D                       }|dk    s
J |            |                    d
          }|dk    sJ |                    d          }|dk    sJ |                    d          }	|	dk    sJ |                    d          }
|                    d          }|
|k    sJ dS )r9  r4   r1  rR   rS   Nz2<dt[ \S]*id="sphinx_gallery.backreferences.[ \S]*>
c              3   "   K   | ]
}d |v |V  dS z<dt Nr9   r   lines     r(   	<genexpr>z4test_backreferences_examples_html.<locals>.<genexpr>  &      NN$v~~~~~~NNr*   r   zExamples using r   z<div class="sphx-glr-thumbnailsr   z#<div class="sphx-glr-thumbcontainerr;  r<  zsphinx_gallery._dummy.htmlz*<dt[ \S]*id="sphinx_gallery._dummy.[ \S]*>c              3   "   K   | ]
}d |v |V  dS rH  r9   rI  s     r(   rK  z4test_backreferences_examples_html.<locals>.<genexpr>  rL  r*   r   r   z!sphinx_gallery._dummy.nested.htmlz1<dt[ \S]*id="sphinx_gallery._dummy.nested.[ \S]*>c              3   "   K   | ]
}d |v |V  dS rH  r9   rI  s     r(   rK  z4test_backreferences_examples_html.<locals>.<genexpr>  rL  r*   )r[   r\   rY   r^   r_   r`   r   r  r   findallsplitr=  )r)   backref_filerd   r  regexn_documentedpossiblen_minin_divn_thumbrB  rC  s               r(   !test_backreferences_examples_htmlrX    s   7=*N L 
\3	0	0 C

               JLMMEu}}U++,,LyyNN%++d*;*;NNNNNH 1h[[*++FQ;;;;KK9::EA::::kk?@@Ga<<<<[[  Fkk'""GW7=*F L 
\3	0	0 C

               JDEEEu}}U++,,LyyNN%++d*;*;NNNNNH1h[[*++FQ;;;;KK9::EA::::kk?@@Ga<<<<[[  Fkk'""GW7=*M L 
\3	0	0 C

               JKLLEu}}U++,,LyyNN%++d*;*;NNNNNH1h[[*++FQ;;;;KK9::EA::::kk?@@Ga<<<<[[  Fkk'""GWs5   AAAF11F58F5.LLLc                     t          j        | j        dd          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ d|v sJ dS )z?Test that nested stdout/stderr uses within a given script work.r5   zplot_log.rstrR   rS   Nz-.. code-block:: none

    is in the same cellz1.. code-block:: none

    is not in the same cell)r[   r\   rZ   r^   r_   r`   )r)   log_rstrd   r  s       r(   test_logging_std_nestedr[    s    gj'.IIG	Wc7	+	+ s

              <EEEE@EIIIIIIr  r9   c           
         ddl }ddlm} d | D             d |D             k    sJ t          t                    t          d          k    }t          | |          D ]\  }}t          j        t          j        |                    d         }	|		                    d          r
|	dd         }	|	|v rE|rB|
                    t          j        |          t          j        |          z
            d	k    sJ |	|vrI |t          j        |          t          j        |          d
dt          j        |           d           dS )zAAssert that the correct set of files were changed based on mtime.r   N)assert_allclosec                 6    g | ]}t          j        |          S r9   r[   basenamer   xs     r(   r   z"_assert_mtimes.<locals>.<listcomp>'  s     ...qBKNN...r*   c                 6    g | ]}t          j        |          S r9   r_  ra  s     r(   r   z"_assert_mtimes.<locals>.<listcomp>'  s     2T2T2Ta2;q>>2T2T2Tr*   z4.1z.codeobji皙?gMbP?g#B;z% was updated but should not have been)atolrtolerr_msg)r/   numpy.testingr]  r   sphinx_versionr   r[   splitextr`  endswithabsgetmtime)
	list_origlist_new	differentr<   r   r]  good_sphinxr   r   
check_names
             r(   _assert_mtimesrs  "  sv   ------..I...2T2T82T2T2TTTTT .))WU^^;KH--  	c[T!2!233A6
z** 	)#CRCJ"" Jvvbk$//"+c2B2BBCCcIIIIv%%OD!!C  ;t,,SSS    r*   c                    |j                                         }d |                    d          D             }dt           d}t	          j        ||t          j        t          j        z            
J |            d}d |                    d          D             }t	          j        ||t          j        t          j        z            
J |            d |                    d          D             }d	t          t          fz  }t	          j        ||t          j        t          j        z            
J |            | 
                                d
z  j        t          j        |j                   t          fdt!          j        t%          j        d                    D                       }t          fdt!          j        t%          j        dd                    D                       }t          fdt!          j        t%          j        d                    D                       }t          fdt!          j        t%          j        d                    D                       }t          fdt!          j        t%          j        d                    D                       }	t          fdt!          j        t%          j        d                    D                       }
t)          |          dk    sJ t)          |          dk    sJ t)          |          dk    sJ t)          |          dk    sJ t)          |	          dk    sJ t)          |
          dk    sJ t)          |j        j        d                   dk    sJ t%          j        t%          j        |j        dd                    sJ |j        }~|}t%          j        |dd          }t%          j        |dd          }t3          j        d           t7                      5  t9          ||||dt;                                                    dg            ddd           n# 1 swxY w Y   j                                         }d |                    d          D             }t>          j         !                    d          r9t	          j        d |t          j        t          j        z            	 
J |            n8t	          j        d!|t          j        t          j        z            	 
J |            d"tD          d#t          d$}t	          j        ||t          j        t          j        z            J t)          j        j        d                   }|t          k    sJ t%          j        t%          j        j        dd                    sJ t          fd%t!          j        t%          j        j        d                    D                       }t          fd&t!          j        t%          j        j        dd                    D                       }t          fd't!          j        t%          j        j        d                    D                       }t          fd(t!          j        t%          j        j        d                    D                       }t          fd)t!          j        t%          j        j        d                    D                       }t          fd*t!          j        t%          j        j        d                    D                       }tG          ||           tG          ||           d+}tG          |||,           tG          ||           tG          |	|           tG          |
|           d-D ]}tI          ||||||||||	|
           dS ).z9Test examples that haven't been changed aren't run twice.c                     g | ]}d |v |	S )removedr9   rI  s     r(   r   z test_rebuild.<locals>.<listcomp>A  s"    FFFdI4E4ET4E4E4Er*   rF  z.*z added, 0 changed, 0 removed.*Nz8.*targets for [2-3] source files that are out of date$.*c                     g | ]}d |v |	S )zout of dater9   rI  s     r(   r   z test_rebuild.<locals>.<listcomp>E  s"    JJJdMT4I4IT4I4I4Ir*   c                     g | ]}d |v |	S )zon MD5r9   rI  s     r(   r   z test_rebuild.<locals>.<listcomp>G  s"    EEEdH4D4DT4D4D4Dr*   z@.*executed %d out of %d.*after excluding 0 files.*based on MD5.*root_oldc              3      K   | ]B}t          j        t          j        d |                    *t          j        d |          V  CdS r4   N)r[   r]   r\   r   r   old_src_dirs     r(   rK  ztest_rebuild.<locals>.<genexpr>O  sc       ! !9RW[-;;<<!
]A..! ! ! ! ! !r*   r4   c              3   N   K   | ]}d |vt          j        dd|          V   dS zbackreferences_all.jsonr4   r:  N)r[   r\   r|  s     r(   rK  ztest_rebuild.<locals>.<genexpr>T  sM       " "$A-- 	],<a@@ .---	" "r*   r:  c              3   n   K   | ]/}|                     d           t          j        d|          V  0dS .rstr5   Nrk  r[   r\   r|  s     r(   rK  ztest_rebuild.<locals>.<genexpr>Z  sW        ::f
_a00     r*   r5   c              3   n   K   | ]/}|                     d           t          j        d|          V  0dS z.jsonr5   Nr  r|  s     r(   rK  ztest_rebuild.<locals>.<genexpr>_  sW        ::g
_a00     r*   c              3   n   K   | ]/}|                     d           t          j        d|          V  0dS z.pyr5   Nr  r|  s     r(   rK  ztest_rebuild.<locals>.<genexpr>d  sW        ::e
_a00     r*   c              3   n   K   | ]/}|                     d           t          j        d|          V  0dS z.ipynbr5   Nr  r|  s     r(   rK  ztest_rebuild.<locals>.<genexpr>i  sW        ::h
_a00     r*   r   stale_examplesr   &sphx_glr_plot_numpy_matplotlib_001.pngr3   r!   r?   rd  )r@   rA   Fc                     g | ]}d |v |	S )z	0 removedr9   rI  s     r(   r   z test_rebuild.<locals>.<listcomp>  s"    HHHdK44G4GT4G4G4Gr*   winz3.*[0|1] added, ([1-9]|1[0-4]) changed, 0 removed$.*z3.*[0|1] added, ([1-9]|1[0-1]) changed, 0 removed$.*z.*executed 0 out of .*after excluding  files.*based on MD5.*c              3      K   | ]L}t          j        t          j        j        d |                    /t          j        j        d |          V  MdS r{  r[   r]   r\   rZ   r   r   new_apps     r(   rK  ztest_rebuild.<locals>.<genexpr>  g       ! !9RWW^]A>>??!
q11! ! ! ! ! !r*   c              3   X   K   | ]$}d |vt          j        j        dd|          V  %dS r  r[   r\   rZ   r  s     r(   rK  ztest_rebuild.<locals>.<genexpr>  O       " "$A-- 	/?CC .---	" "r*   c              3   x   K   | ]4}|                     d           t          j        j        d|          V  5dS r  rk  r[   r\   rZ   r  s     r(   rK  ztest_rebuild.<locals>.<genexpr>  Y        ::f
33     r*   c              3   x   K   | ]4}|                     d           t          j        j        d|          V  5dS r  r  r  s     r(   rK  ztest_rebuild.<locals>.<genexpr>  Y        ::g
33     r*   c              3   x   K   | ]4}|                     d           t          j        j        d|          V  5dS r  r  r  s     r(   rK  ztest_rebuild.<locals>.<genexpr>  Y        ::e
33     r*   c              3   x   K   | ]4}|                     d           t          j        j        d|          V  5dS r  r  r  s     r(   rK  ztest_rebuild.<locals>.<genexpr>  Y        ::h
33     r*   sg_execution_timessg_api_usager   r   r   r   r=   )	run_stalemodify)%ra   rb   rP  N_RSTr   r   	MULTILINEr   r   r   rE   strpathrH   rI   rZ   sortedr   r   r[   r\   r   rl   rm   r]   rY   r   sleepr	   r   r   rJ   r  platformr   	N_FAILINGrs  _rerun)r%   r)   rA   r  r   generated_modules_0generated_backrefs_0generated_rst_0generated_json_0copied_py_0copied_ipy_0rL   rM   rN   rO   n_stalegenerated_modules_1generated_backrefs_1generated_rst_1generated_json_1copied_py_1copied_ipy_1r<   howr  r}  s                           @@r(   test_rebuildr  =  s$	    ((**FFFfll400FFFE5555D8D&",":;;GGGGGEDJJfll400JJJE8D&",":;;GGGGGEEfll400EEEEMQ D 8D&",":;;GGGGG!--//*<EK
OJ%{333  ! ! ! !BGK??@@! ! !  
 " " " " "BGK@PQQRR" " "       BGKAABB    O
     BGKAABB    
     BGKAABB    K
     BGKAABB    L
 "##a''''#$$q((((!####  1$$$${a|q    z 45EFGG1LLLL9

!9.VWW     GHggx00G77Hj99LJsOOO			 	! 	!::
 
 
 	eR   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! _%%''FHHfll400HHHE
|u%% HEry( 
       HEry( 
      			D 8D&",":;;GGG'.45EFGGGf9
	+STT     ! ! ! ! !BGGNMBBCC! ! !  
 " " " " "BGGNMCSTTUU" " "       BGGNODDEE    O
     BGGNODDEE    
     BGGNODDEE    K
     BGGNODDEE    L &(;<<< ')=>>>
F ?OFCCCC #%5666 ;,,, <... ' 
 
 	 	
 	
 	
 	

 
s   8Q!!Q%(Q%c           
      
  " t          j        d           t                      }| dk    rt          j        |dd          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   t          j        |dd          5 }|D ]1}d	|v r|                    d	d
          }|	                    |           2	 ddd           n# 1 swxY w Y   t          dz   t          dz
  }}t          dz
  }n| dk    sJ d|d<   d|d<   d\  }}d}t                      5  t          ||||dt                      |          ""                    dg            ddd           n# 1 swxY w Y   "j                                        }d |                    d          D             }d                    | g|z             }t&          j        t&          j        z  }dt,           d}t'          j        |||          
J |            d |                    d          D             }| dk    rd}nd}d                    d|  d| dg|z             }d| d }t'          j        |||          
J |            d!|d"|d#}t'          j        |||          J t1          "j        j        d$                   }||k    sJ t          j        t          j        "j        d%d&                    sJ t;          "fd't=          j        t          j        "j         d(                    D                       }t;          "fd)t=          j        t          j        "j         d(d*                    D                       }t;          "fd+t=          j        t          j        "j         d,                    D                       }t;          "fd-t=          j        t          j        "j         d,                    D                       }t;          "fd.t=          j        t          j        "j         d,                    D                       }t;          "fd/t=          j        t          j        "j         d,                    D                       }tC          ||           tC          ||           d0}d1}tD          j#        $                    d2          pt=          j%        d3d4          d5k    } | sTtC          ||||           | dk    rd6n|}!tC          |||7           tC          |	||!8           tC          |
||!8           dS dS )9zCRerun the sphinx build and check that the right files were changed.rd  r  z../examplesrV   rR   rS   Nru   zFYI thiszFYA thisr   r  Truez&sphinx_gallery_conf.run_stale_examplesplot_numpy_maz$sphinx_gallery_conf.filename_pattern)r   r   r   r!   )r@   rA   confoverridesFc                     g | ]}d |v |	S )zsource files thatr9   rI  s     r(   r   z_rerun.<locals>.<listcomp>.  s#    PPPd4G44O4OT4O4O4Or*   rF  z.*targets for z% source files that are out of date$.*c                     g | ]}d |v |	S )zchanged,r9   rI  s     r(   r   z_rerun.<locals>.<listcomp>6  s"    GGGdJ$4F4FT4F4F4Fr*   z([3-9]|1[0-3])z([1-9]|1[01])z != :z&.*updating environment:.*[0|1] added, z changed, 0 removed.*z.*executed 1 out of r  r  r  r   r  c              3      K   | ]L}t          j        t          j        j        d |                    /t          j        j        d |          V  MdS r{  r  r  s     r(   rK  z_rerun.<locals>.<genexpr>\  r  r*   r4   c              3   X   K   | ]$}d |vt          j        j        dd|          V  %dS r  r  r  s     r(   rK  z_rerun.<locals>.<genexpr>a  r  r*   r:  c              3   x   K   | ]4}|                     d           t          j        j        d|          V  5dS r  r  r  s     r(   rK  z_rerun.<locals>.<genexpr>g  r  r*   r5   c              3   x   K   | ]4}|                     d           t          j        j        d|          V  5dS r  r  r  s     r(   rK  z_rerun.<locals>.<genexpr>l  r  r*   c              3   x   K   | ]4}|                     d           t          j        j        d|          V  5dS r  r  r  s     r(   rK  z_rerun.<locals>.<genexpr>q  r  r*   c              3   x   K   | ]4}|                     d           t          j        j        d|          V  5dS r  r  r  s     r(   rK  z_rerun.<locals>.<genexpr>v  r  r*   )r   r  r  	BAD_MTIMErz   1r9   r=   )rp  )&r   r  r   r[   r\   r^   r_   	readlinesreplacer!  r  r   r	   r   r   rJ   ra   rb   rP  r   r  r   r  r   r   rl   rm   r]   rY   r  r   r   rZ   rs  r  r  r   getenv)#r  rL   rM   rN   rO   r  r  r  r  r  r  r  rh   rd   r  rJ  out_of	excludingr  rA   flagsr   n_ch	got_staler  r  r  r  r  r  rp  r<   baduse_differentr  s#                                     @r(   r  r     s    	JsOOOFFM
h0JKK[W-- 	$MMOOE	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$[W-- 	     %%<<
J??D		$	 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  &M6A:	1*k!!!!BH>?@O<= 				 
! 
!::'
 
 
 	eR   
! 
! 
! 
! 
! 
! 
! 
! 
! 
! 
! 
! 
! 
! 
! _%%''FPPfll400PPPEIIseem$$EL29$E IEHHHD8D&%((44e444GGfll400GGGE( hII,C,,T,,,-566EODOOOD8D&%((44e4444		D 8D&%((444GN67GHIII9
	+STT     ! ! ! ! !BGGNMBBCC! ! !  
 " " " " "BGGNMCSTTUU" " "       BGGNODDEE    O
     BGGNODDEE    
     BGGNODDEE    K
     BGGNODDEE    L &(;<<< ')=>>> +IF ,
!
!%
(
(
NBIk3,G,G3,NC LFKKK "[00i')9&IIII 	{K=IIII 	|\]KKKKKKL Ls6   A77A;>A;5CC!C+9E00E47E4z
name, wantz!future/plot_future_imports_brokenz:.*RuntimeError.*Forcing this example to fail on Python 3.*r   r   z,.*ValueError.*zero-size array to reduction.*scraperc                     t          | j                  }|dz  |dz   z                      d          }t          j        ||t          j                  J | d|             dS )/Test that informative error messages are added.r5   r  rS   Nz should have had: )r   rZ   r"  r   r   r   )r)   r   r   rL   r+  s        r(   test_error_messagesr    sn    " :$%%G_$v6
A
A'
J
JC8D#ry))55$7X7XRV7X7X55555r*   c                 $   | j         }t          j        |d|dz             }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   |                    dd          }t          j        ||          J dS )r  r5   r  rR   rS   NrF   )	rZ   r[   r\   r^   r_   r`   r  r   r   )r-   r   r   rL   example_rstrd   r+  s          r(   test_error_messages_dirhtmlr    s    " !'G''?D6MBBK	[#w	/	/ 3hhjj              
++dC
 
 C8D#*****s   AAAc                 b   | j         }| j        }t          j        |dd          }t	          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ d|v sJ t          j        |dd          }t	          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d	|v sJ t          j        |dd
          }t	          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ dS )z4Test alt text for matplotlib images in html and rst.r5   zplot_matplotlib_alt.rstrR   rS   Nz/:alt: This is a sup title, subplot 1, subplot 2z+:alt: Left Title, Center Title, Right Titler  z:alt: plot numpy matplotlibr  zalt="plot numpy matplotlib"rY   rZ   r[   r\   r^   r_   r`   )r)   rN   rL   r  rd   r+  example_htmlr!   s           r(   test_alt_text_imager    s   GG''?4MNNK	[#w	/	/ 3hhjj               =CCCC8C???? ''?4OPPK	[#w	/	/ 3hhjj              (C////77O5QRRL	\3	0	0 Cxxzz              (D000000s5   AA #A C  CC=DD"%D"c                 V   | j         }| j        }t          j        |dd          }t	          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ t          j        |dd          }t	          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ t          j        |dd	          }t	          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d
|v sJ dS )z,Test alt text for thumbnail in html and rst.r5   r   rR   rS   Nzalt=""r4   r1  z	index.rstz:alt:r  )r)   rN   rL   r  rd   r!   backref_htmlr+  s           r(   test_alt_text_thumbnailr    s   GG!wwNN	-sG	<	< xxzz              t77M3WXXL	\3	0	0 Cxxzz              t!wwMM	-sG	<	< hhjj              c>>>>>>s5   AA #A B::B>B>7DDDc                    | j         }| j        }t          j        |dd          }t	          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d}||v sJ t          j        |d          }t	          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d}	|	|v sJ dS )	z%Tests that backreference labels work.r4   z!sphinx_gallery.backreferences.rstrR   rS   NzB.. _sphx_glr_backref_sphinx_gallery.backreferences.identify_names:r   zthref="gen_modules/sphinx_gallery.backreferences.html#sphx-glr-backref-sphinx-gallery-backreferences-identify-names">)rZ   rY   r[   r\   r^   r_   r`   )
r)   rL   rN   backref_rstrd   r+  label
index_htmlr!   links
             r(   test_backreference_labelsr    sH   GG''=2UVVK	[#w	/	/ 3hhjj              PEC<<<<,//J	Zg	.	. #xxzz               BD4<<<<<<s#   AA #A B;;B?B?c                    | j         }t          j        |d          }t          j        |dd          5 }t
          j                            |                                          }d d d            n# 1 swxY w Y   |	                    d          }|
                    d          }t          |          t          |          k    sJ d t          ||          D             S )Nzminigallery.htmlrR   rS   z //p[starts-with(text(), "Test")]zsphx-glr-thumbnailsc                 >    i | ]\  }}|                                 |S r9   )text_content)r   r   divs      r(   
<dictcomp>z$minigallery_tree.<locals>.<dictcomp>  s*    GGGsDGGGr*   )rY   r[   r\   r^   r_   r   r!   r   r`   xpath
find_classr   r   )r)   rN   minigallery_htmlrd   treer;   divss          r(   minigallery_treer    s   Gww(:;;	%sG	4	4 0y##CHHJJ//0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 JJ9::E??011Du::T""""GGc%6F6FGGGGs   2A11A58A5ztest, heading, sortkeyzTest 1-Nexplicitz
Test 1-D-D)h23Examples using sphinx_gallery.sorting.ExplicitOrderz
Test 1-D-C)h3r  z
Test 1-C-D)r  zThis is a custom headingzTest 2-Nfilenamez
Test 2-D-D)r  z&Examples using one of multiple objectsz
Test 2-C-C)h1z"This is a different custom headingzTest 1-Fpathz
Test 2-F-GglobzTest 3-F-G-B)r  zAll the input types >   r  r  r  r  
Test 1-F-Rplot_booplot_cosTest 1-S	plot_sub2	plot_sub1zTest 3-Nc                    || v sJ | |         }|J |                     d          }|rO|d         j        |d         k    sJ |d                                                             |d                   sJ n|g k    sJ |dv r|                     d          }|                     d          }|r|sJ t	          |||          D ]@\  }}	}
||	                                d         v r||
                                d         v sJ AdS d	d
ddd}|                                D ]H\  }}|                     d| d          }|                     d| d          }||v r|r|sJ B|s|rJ IdS )zTests the functionality of the minigallery directive.

    Use `print(f"{test}: {lxml.html.tostring(text)}")` for checking.
    Nz?preceding-sibling::*[position()=1 and starts-with(name(), "h")]r   r   )r  r  6descendant::img[starts-with(@src, "_images/sphx_glr")]z%descendant::a[contains(@href, "rst")]r   r7  r   plot_logplot_matplotlib_alt)r  r  r  r  z)descendant::img[@src = "_images/sphx_glr_z_thumb.png"]z0descendant::a[starts-with(@href, "auto_examples/z.html")])r  r   r  r   r   valuesitems)r  testheadingsortkeytextheading_elementimghrefpihrU   keyrh   s                 r(   test_minigallery_directiver    s   j #####D!DjjI O  %q!%3333q!..00;;GAJGGGGGG"$$$$)))jjQRR zzABBt7C.. 	C 	CGAq!B''a188::b>.A.A.A.A.A	C 	C 5/)	
 
 #..** 	) 	)JC**OEOOO C ::R5RRR D g~~#t####  (4((((	) 	)r*   c                 x    d| v sJ | d         }|                     d          }ddh}d |D             |k    sJ dS )a  Ensure minigallery removes duplicate examples.

    "Test duplicates" in `minigallery.rst` should result in only 2 examples:
    - plot_second_future_imports - object (`ExplicitOrder`) AND 2 file inputs
    - plot_numpy_matplotlib - object (`Block`) and 1 file input
    zTest duplicatesr  z5_images/sphx_glr_plot_second_future_imports_thumb.pngz0_images/sphx_glr_plot_numpy_matplotlib_thumb.pngc                 B    h | ]}|                                 d          S )r   )r	  )r   r  s     r(   	<setcomp>z.test_minigallery_duplicates.<locals>.<setcomp>  s%    ---CJJLL---r*   N)r  )r  r  imgsexpected_exampless       r(   test_minigallery_duplicatesr    si      00000-.D::NOOD?: .----1BBBBBBBr*   c                     | j         }t          j        |dd          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d}||vsJ d}||vsJ dS )z'Test Matplotlib agg warning is removed.r5   zplot_matplotlib_alt.htmlrR   rS   NzYMatplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.z,is non-interactive, and thus cannot be shown)rY   r[   r\   r^   r_   r`   )r)   rN   r  rd   r!   rB   s         r(   test_matplotlib_warning_filterr    s    G77O5OPPL	\3	0	0 Cxxzz              	7  $<G$   AAAc                    | j         }t          j        |dd          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d}d}t          t                                r||v sJ dS ||v sJ dS )zTest using pypandoc.r5   zplot_numpy_matplotlib.ipynbrR   rS   NzUse :mod:`sphinx_gallery` to link to other packages, like\n:mod:`numpy`, :mod:`matplotlib.colors`, and :mod:`matplotlib.pyplot`.zUse `sphinx_gallery`{.interpreted-text role=\"mod\"} to link to other\npackages, like `numpy`{.interpreted-text role=\"mod\"},\n`matplotlib.colors`{.interpreted-text role=\"mod\"}, and\n`matplotlib.pyplot`{.interpreted-text role=\"mod\"}.)rZ   r[   r\   r^   r_   r`   anyr   )r)   rL   rh   rd   mdmd_sg	md_pandocs          r(   test_jupyter_notebook_pandocr%    s    GGG_.KLLE	UC	)	) SXXZZ               PE BI
=?? B{{{{{{r  c                     | j         }t          j        |dd          }d}t          |          5 }|                                }ddd           n# 1 swxY w Y   ||k    sJ dS )zTest MD5 hashing.r5   zplot_log.py.md5 0edc2de97f96f3b55f8b4a21994931a8N)rZ   r[   r\   r_   r`   )r)   rL   rh   expected_md5md5_file
actual_md5s         r(   test_md5_hashr+    s    GGG_.?@@E5L	e %]]__
% % % % % % % % % % % % % % % %%%%%%s   AAAc                 p   t          j        | j        d          }t          j        t          j        |d          dd          5 }|                                }ddd           n# 1 swxY w Y   dd                    t          j        d|t          j                            z   }t          j	        d|t          j                  }|
J |            |
                                d	         }t          j        t          j        ||                    }d
|v sJ t          j        |          sJ d|v sJ t          j	        d|t          j                  }|J |
                                d	         }t          j        t          j        ||                    }d|v sJ t          j        |          sJ dS )z*Test that the binder logo path is correct.r5   plot_svg.htmlrR   rS   NrF  z<img [^>]+>zB.*<img alt="Launch binder" src="([^"]+)" (width|style)=[^/>]+\/>.*r   binder_badge_logozhttps://mybinder.org/v2/gh/sphinx-gallery/sphinx-gallery.github.io/master?urlpath=lab/tree/notebooks/auto_examples/plot_svg.ipynbzG.*<img alt="Launch JupyterLite" src="([^"]*)" (width|style)=[^/>]+\/>.*jupyterlite_badge_logo)r[   r\   rY   r^   r_   r`   r   rO  r   r   groupsabspathr]   )r)   rootrd   r!   img_strsr  	img_fnames          r(   $test_interactive_example_logo_existsr5    s   7:$o66D	RWT?33S'	B	B cxxzz              dii
=$	 J JKKKH8M
	 D
 X;;==D
274..//I)++++9Y 	L	 	 	 	 8R
	 D
 ;;==D
274..//I#y00009Y   A%%A),A)c                    t          j        | j        d          }t          j        t          j        |d          dd          5 }|                                }ddd           n# 1 swxY w Y   d}t          j        ||          sJ dS )zCTest text saying go to the end to download code or run the example.r5   r-  rR   rS   NzGto download the full example.+in your browser via JupyterLite or Binder)r[   r\   rY   r^   r_   r`   r   r  )r)   r2  rd   r!   patterns        r(   "test_download_and_interactive_noter9    s    7:$o66D	RWT?33S'	B	B cxxzz               	W  9Wd#######r6  c                     t          j        | j        d          }t          j        |d          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ d|vsJ dS )zTest the deferring of figures.r5   plot_defer_figures.htmlrR   rS   Nz.../_images/sphx_glr_plot_defer_figures_001.pngz.../_images/sphx_glr_plot_defer_figures_002.pngr  )r)   r2  rh   rd   r!   s        r(   test_defer_figuresr<    s    7:$o66DGD344E	UC	)	) Sxxzz               <tCCCC;4GGGGGGs   A''A+.A+c                     t          j        | j        ddd          }t          j        | j        ddd          }t          j        |          rJ t          j        |          rJ dS )zETest sphinx_gallery_dummy_images NOT created when executable is True.r5   imageszsphx_glr_plot_repr_001.pngzsphx_glr_plot_repr_002.pngN)r[   r\   rZ   r]   )r)   img1img2s      r(   test_no_dummy_imagerA    sp    7?H6R D 7?H6R D yyr*   c                 D   | j         }t          j        |ddd          }t          j        |d          }|D ]h}t	          |          5 }t          j        |          }d d d            n# 1 swxY w Y   |d         d         }|d         d	k    sJ d
| |d         v sJ id S )Njupyterlite_contentsz**z*.ipynbT)	recursivecellsr   	cell_typemarkdownz JupyterLite-specific change for source)rZ   r[   r\   r  r_   jsonload)r)   rL   jupyterlite_notebook_patternjupyterlite_notebook_filenamesnotebook_filenamer   notebook_content
first_cells           r(   test_jupyterlite_modificationsrP    s#   G#%7'y$ $  &*Y$& & &" < 	
 	
#$$ 	,#y||	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, &g.q1
+&*4444B/@BB(#$ $ $ $ $	
 	
s   A))A-	0A-	c                     t          | j                  dz  dz  }|                                }|                    d          dk    sJ |                    dd          sJ d|v sJ d|vsJ d	|vsJ d
|vsJ d S )Nr5   zparse_this.rstz.. code-block:: C++r   z
:dedent: 1r   zDownload C++ source codebinder-badge
lite-badgeDownload Jupyter notebookr   rZ   r"  r=  )r)   cpp_rstre   s      r(   test_cpp_rstrW    s    :$%%7:JJG!!G==.//14444==q)))))%0000((((w&&&&&g555555r*   c                     t          | j                  dz  dz  }|                                }|                    dd          sJ d|v sJ d|v sJ d S )Nr5   zisentropic.rstz.. code-block:: Matlabr   z1isentropic, adiabatic flow example
==============zDownload Matlab source coderU  )r)   
matlab_rstre   s      r(   test_matlab_rstrZ  %  sq    j'((?:=MMJ""$$G==1155555?7JJJJ(G333333r*   c                     t          | j                  dz  dz  }|                                }|                    dd          sJ d|v sJ d|v sJ d S )Nr5   zjulia_sample.rstz.. code-block:: Juliar   zJulia example
=============zDownload Julia source coderU  )r)   	julia_rstre   s      r(   test_julia_rstr]  -  sq    Z&''/9<NNI!!##G==0!44444)W4444'7222222r*   c                    t          j        d           t          j        | j        d          }t          j        |d          }t          j        |dd          5 }|                                }ddd           n# 1 swxY w Y   |                    d          }| j	        j
        d         d	         }d
|v sJ ||k    sJ d|v sJ d|v sJ d|v sJ dS )z5Test correct thumbnails are displayed for an example.r/   r5   r;  rR   rS   Nz&<div class="sphx-glr-thumbnail-title">recommender
n_examplesz&<p class="rubric">Related examples</p>z,sphx-glr-auto-examples-plot-defer-figures-pyz#sphx-glr-auto-examples-plot-webp-pyz0sphx-glr-auto-examples-plot-command-line-args-py)rC   rD   r[   r\   rY   r^   r_   r`   r=  rl   rm   )r)   r2  rh   rd   r!   r=  r`  s          r(   test_recommend_n_examplesra  5  s0   
   7:$o66DGD344E	UC	)	) Sxxzz               JJ?@@E"6}ElSJ3t;;;;J9TAAAA0D8888=EEEEEEs   A;;A?A?c                 4   t          j        | j        dd          }t          j        |dd          5 }t
          j                            |                                          }ddd           n# 1 swxY w Y   dD ]\  }}|	                    |          d         
                                d         
                                d         j        d         }|	                    | d	          d         }|j        d
         t          j                            |          k    sJ |
                                d         j        d         |k    sJ |
                                d                                                                         |k    sJ dS )zCTest that the `sg_download_links.html` component works as expected.r5   r  rR   rS   N))zsphx-glr-download-pythonzDownload source code)zsphx-glr-download-jupyterrT  )zsphx-glr-download-zipzDownload zippedr   r  -sidebartitle)r[   r\   rY   r^   r_   r   r!   r   r`   r  getchildrenr   r   r  r`  r  strip)r)   r  rd   r  
class_namedesc	orig_hrefsidebar_divs           r(   &test_sidebar_components_download_linksrk  H  s   7:,o?OPPL	\3	0	0 0Cy##CHHJJ//0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 K K
D OOJ''*[]]1[]]1 F 	 oo&=&=&=>>qA!'*bg.>.>y.I.IIIII&&((+26:iGGGG&&((+88::@@BBdJJJJJK K   2A00A47A4c                 &   t          j        | j        dd          }t          j        |dd          5 }t
          j                            |                                          }ddd           n# 1 swxY w Y   dD ]}|	                    |          d         
                                d         }|j        d         }|
                                d         }|	                    | d	          d         
                                d         }|j        d         |k    sJ |
                                d         j        d
         |j        d
         k    sJ |
                                d         j        d         |j        d         k    sJ dS )zCTest that the `sg_launcher_links.html` component works as expected.r5   r  rR   rS   N)rR  rS  r   r  rc  r:   alt)r[   r\   rY   r^   r_   r   r!   r   r`   r  re  r   )	r)   r  rd   r  rg  orig_anchorri  orig_imgsidebar_anchors	            r(   &test_sidebar_components_launcher_linksrr  _  s   7:,o?OPPL	\3	0	0 0Cy##CHHJJ//0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 W W
ooj11!4@@BB1E&v.	**,,Q/J)@)@)@AA!DPPRRSTU$V,	9999))++A.5e<PU@VVVVV))++A.5e<PU@VVVVVVW Wrl  )r9   r9   )d__doc__r^   r  rI  r   os.pathr  r[   r   rH   r  r   ior   pathlibr   
lxml.etreer   	lxml.htmlrC   packaging.versionr   sphinxr   ri  sphinx.applicationr   sphinx.errorsr   sphinx.util.docutilsr	   sphinx_gallery.utilsr
   r   r   r   r   r   r  r   N_PASSN_INDEX	N_EXECUTEN_OTHERr  rD   manimwritersis_availableskipfixturer)   r-   r#   ri   rq   rw   r   r   r   r   r   r   r   r   r  r  r-  r4  markparametrizeparamrD  rX  r[  rs  r  r  r  r  r  r  r  r  r  r  r  r%  r+  r5  r9  r<  rA  rP  rW  rZ  r]  ra  rk  rr  r9   r*   r(   <module>r     s   ; :    				       				  



                       % % % % % % 0 0 0 0 0 0 % % % % % % ( ( ( ( ( ( 3 3 3 3 3 3             $ 
		i	 
  	
Vg%	1G;,E,,EAI,,	,,,  ( ) ) )233}!!(++ DFK)dCCCC  H    h/ /  / h2 2  2& & &R$ $ $2!$ !$ !$H	3 	3 	3_ _ _DC C C8F F F  ,  0& & &R: : :<- - -)) )) ))X0 0 0Y+ Y+ Y+x) ) )2 C#	
 	
 	

 	;(	
 	
 	
 
 
 
O O OdJ J J   6@
 @
 @
F]L ]L ]L@ /H	
 	
 	

 	!:	
 	
 	
 Y Y Y /H	
 	
 	

 	!:	
 	
 	
 + + +1 1 12  *  $ h	H 	H  	H  
TJ<( IL	
 IL	
 
9J<H	TJ
34 <$	
 8$	
 
TF8$	tfX& -444	

 
tj*56	TK56	TCCCDW,/ /`2) 2)a/ /`2)jC C C&     & & &     B	$ 	$ 	$H H H	 	 	
 
 
*6 6 64 4 43 3 3F F F&K K K.W W W W Wr*   