
    -Ph                     
   d Z ddlZddlZddlZddlZddlZddlZddl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mZ ddlmZ ddlmZ ddlmZmZ ddlmZ dd	lmZmZ dd
l m!Z!m"Z"  ee#          j$        d         Z%g dZ&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d Z.d Z/ej0        1                    dddgddgf          d             Z2ej0        1                    de&g dz   dfe&g dz   d fe&g d!z   d"fg          d#             Z3d$ Z4d%5                    d&          Z6d' Z7d( Z8d) Z9ej0        1                    d*d+d,g          d-             Z:d. Z;d/ Z<d0 Z=d1 Z>d25                    d&          Z?ej0        1                    d3dh d4fd5hd6d7hfd8hh d4fd9d:hd6d7hfgg d;<          d=             Z@ej0        1                    d>g d?          d@             ZAej0        1                    d>dAdBg          dC             ZBdD ZCej0        1                    dEg dF          dG             ZDej0        1                    dEg dH          dI             ZEdJ ZFdK ZGdL ZH ejI        dMN          dO             ZJdP ZKdQ ZLdR ZMdS ZNdTZOdUZPdVZQdWZRdXZSdYZTdZ ZUej0        1                    d[ ejV         eW            d\d]d^_           ejV         eW            d`d]da_           ejV         eW            dbdcdd_           ejV         eW            dedfdg_           ejV        dhd\d]di_           ejV        dhd`dcdj_           ejV        dhdbdcdk_           ejV        dhdedldm_           ejV        dhePdndo_           ejV        dheQdpdq_           ejV        dreOd]ds_           ejV        drePeSdt_           ejV        dreQd]X                    eTeSg          du_           ejV        dvePeSdw_           ejV        dxePdndy_           ejV        dveOdndz_           ejV        dreRd]d{_          g          d|             ZYej0        1                    d} ejV         eW            d~ddcd_           ejV         eW            dhddcd_           ejV        dhd~dd]d_           ejV         eW            dhd~d]d_           ejV        dhd~d~d]d_          g          d             ZZd Z[ej0        1                    dg d          d             Z\ej0        1                    dg d          d             Z]d Z^ejI        d             Z_d Z`d Zad Zbd Zcd Zdd Zed Zfd Zgd Zhd ZidS )z Testing the rst files generator.    N)Path)mock)ExtensionError)	downloads))_update_gallery_conf_exclude_implicit_docgenerate_dir_rst)check_binder_conf)Blocksplit_code_and_text_blocks)ImagePathIterator
figure_rst   )"""================Docstring headerr    z&This is the description of the exampleu   which goes on and on, Óscarr   r   zAnd this is a second paragraphr   r   %# sphinx_gallery_thumbnail_number = 1# sphinx_gallery_defer_figures# and now comes the module code# sphinx_gallery_start_ignore#pass # Will be run but not renderedz# sphinx_gallery_end_ignorezimport loggingz
import syszfrom warnings import warnx, y = 1, 2u.   print("Óscar output") # need some code outputzlogger = logging.getLogger()zlogger.setLevel(logging.INFO)z&lh = logging.StreamHandler(sys.stdout)z5lh.setFormatter(logging.Formatter("log:%(message)s"))zlogger.addHandler(lh)u   logger.info("Óscar")z3print(r"$\langle n_\uparrow n_\downarrow \rangle$")z&warn("WarningsAbound", RuntimeWarning)c                      t          t          dz  dz  dz            \  } }| i k    sJ |d         d         dk    sJ |d         d         dk    sJ dS )	z1Test if a known example file gets properly split.examples	no_outputzjust_code.pyr   text   codeN)r   root)	file_confblockss     a/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx_gallery/tests/test_gen_rst.pytest_split_code_and_text_blocksr#   G   so    2zK'.8 Iv ????!9Q<6!!!!!9Q<6!!!!!!    c                      t          j        t          t                    j        dz                      d                    } t          t          dz  dz            \  }}|i k    sJ || k    sJ dS )zTest the block splitting with supported syntax in notebook styled example.

    `plot_parse.py` uses both '#'s' and '#%%' as cell separators.
    zreference_parse.txtutf-8	tutorialszplot_parse.pyN)astliteral_evalr   __file__parent	read_textr   r   )
ref_blocksr    r!   s      r"   !test_bug_cases_of_notebook_syntaxr.   R   sx    
 !	h	!6	6AA'JJ J 34+3E3WXXIv????Zr$   c                     t          j        dd          5 } |                     d                    g d                     d d d            n# 1 swxY w Y   	 t	          | j                  \  }}t          j        | j                   n# t          j        | j                   w xY w|i k    sJ ddd                    g d          d	fg}||k    sJ d S )
NwFdelete
)"Docstring"r   # with a second line of commentr   r   r   	Docstringr   r   )r   r5   r   r   r   tempfileNamedTemporaryFilewritejoinr   nameosremove)fr    resultexpected_results       r"   #test_direct_comment_after_docstringrC   `   sE    
	$S	7	7	7 
1	II   
	
 
	
 
	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
6qv>>	6
	!&	!&???? II    	
O _$$$$$$   +AAAB B&c                 D   t          |                     d                    }t          |d          5 }|                    d                    g d                     ddd           n# 1 swxY w Y   t	          |j                  \  }}|i k    sJ g d}||k    sJ dS )z4Tests last word in final rst block included as text.temp.pyr0   r3   )r4   z# comment only code block#%%z# Include this whole sentence.N)r6   )r   z# comment only code block
r   )r   zInclude this whole sentence.   )strr<   openr;   r   r=   )tmpdirfilenamer@   r    rA   rB   s         r"   test_final_rst_last_wordrM      s    6;;y))**H	h		 

	II   		
 		
 		


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 316::Iv????  O
 _$$$$$$   +A**A.1A.c                 n   t          |                    d                    }t          |d          5 }|                    d                    g d                     ddd           n# 1 swxY w Y   t	          |          \  }}|i k    sJ t          |          dk    sJ |d         d         dk    sJ |d	         d         dk    sJ |d
         d         dk    sJ |d         d         dk    sJ ddi}i }t          j        ||| |          \  }}t          j        ||||           }	d}
|	|
k    sJ dS )zBAssert there is a blank line between the docstring and rst blocks.rF   r0   r3   )r4   ##################### Paragraph 1z
# is long.r   rG   z# Paragraph 2r   # %%z# Paragraph 3r   NrH   r   r   r   r      execute_scriptr   zDocstring

.. GENERATED FROM PYTHON SOURCE LINES 3-5

Paragraph 1
is long.

.. GENERATED FROM PYTHON SOURCE LINES 7-8

Paragraph 2

.. GENERATED FROM PYTHON SOURCE LINES 10-11

Paragraph 3

)	rI   r<   rJ   r;   r   lensgrT   
rst_blocksgallery_confrK   rL   r@   r    r!   script_varsoutput_blockstime_elapsedexample_rstwant_rsts              r"   test_rst_block_after_docstringr_      s   6;;y))**H	h		 
	II   	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
$ 38<<Iv????v;;!!9Q<6!!!!!9Q<6!!!!!9Q<6!!!!!9Q<6!!!!#R(KI"$"3\9# #M< -y,OOKH" (""""""rN   c                    |                      d           t          |                    d                    }t          |d          5 }|                    d                    g d                     ddd           n# 1 swxY w Y   t          |          \  }}|i k    sJ t          |          dk    sJ |d	         d	         d
k    sJ |d         d	         d
k    sJ |d         d	         dk    sJ d| d<   t          d|g |          }t          j	        ||| |          \  }}t          j
        ||||           }	d}
|	                    d          |
k    sJ dS )zATest that we can "execute" a code block containing only comments. image_scrapersrF   r0   r3   )r4   rP   rQ   r   z# just a commentNrS   r   r   r   r   r   Tabort_on_example_errorrT   src_fileimage_path_iteratortarget_filezDocstring

.. GENERATED FROM PYTHON SOURCE LINES 3-4

Paragraph 1

.. GENERATED FROM PYTHON SOURCE LINES 4-5

.. code-block:: python


    # just a comment)updaterI   r<   rJ   r;   r   rU   dictrV   rT   rW   rstriprX   s              r"   test_rst_empty_code_blockrl      s   r***6;;y))**H	h		 
	II   
	
 
	
 
	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 38<<Iv????v;;!!9Q<6!!!!!9Q<6!!!!!9Q<6!!!!-1L)*	  K #%"3\9# #M< -y,OOKH d##x//////s   	+B  BBc                 <   |                      d           t          |                    d                    }t          |d          5 }|                    d           ddd           n# 1 swxY w Y   t          |          \  }}t          |          dk    sJ |d         d         d	k    sJ |d
         d         dk    sJ |i k    sJ d|g |d}t          j        ||| |          \  }}d|v sJ |d         d         dk    sJ |d         d         dk    sJ dS )z"Assert the global vars get stored.ra   rb   rF   r0   z=
'''
My example
----------

This is it.
'''
a = 1.
b = 'foo'
Nr   r   r   r   r   Tre   example_globalsag      ?bfoo)	ri   rI   r<   rJ   r;   r   rU   rV   rT   )	rY   rK   rL   r@   r    r!   rZ   r[   r\   s	            r"   test_script_vars_globalsrr     s   r***6;;y))**H	h		 
			
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 38<<Ivv;;!!9Q<6!!!!!9Q<6!!!!????!	 K #%"3\9# #M< ++++()#.#5555()#.%777777s   	A++A/2A/c                  B    t          j        d          } d}|| k    sJ dS )z6Test the correct translation of a code block into rst.zprint("hello world")z0.. code-block:: python

    print("hello world")N)rV   codestr2rst)output	references     r"   test_codestr2rstrw   4  s2    ^233FI r$   c            	          t          j        dd                    t          dd                             \  } }|dk    sJ d| vsJ | dk    sJ d| vsJ t          j        dd                    d	d
gt          dd         z                       \  }}|| k    sJ ||k    sJ t          j        dd                    t          dd         d
gz   t          dd         z                       \  }}|| k    sJ ||k    sJ t          j        dd          \  } }| |cxk    rdk    sn J t          j        dd          \  } }| |cxk    rdk    sn J t          j        dd          \  } }|dk    sJ d                    d t	          d          D                       }t          j        dd|z             \  } }t          |          dk    sJ t          |           dk    sJ |                    dd          | k    sJ t          j        t          d          5  t          j        dd
           d d d            n# 1 swxY w Y   t          j        t          d          5  t          j        dd           d d d            d S # 1 swxY w Y   d S )Nz<string>r3   r   
   r   r7   uC   This is the description of the example which goes on and on, Óscarzsecond paragraphz.. my_labelr   rH      zTitle
-----TitlerL   z^^^^^
   Title  two  
^^^^^z
Title  twozB    ------------
"-`Header"-with:; `punct` mark's
----------------z"-`Header"-with:; punct mark'sc                     g | ]}d S )zthis is one linera   ).0_s     r"   
<listcomp>z0test_extract_intro_and_title.<locals>.<listcomp>d  s     G G G!3 G G Gr$   zTitle
-----

d    zshould have a headermatchzCould not find a titlez=====)
rV   extract_intro_and_titler<   CONTENTrangerU   replacepytestraisesr   )introtitleintro_labeltitle_labelintro_whitespacetitle_whitespaceintro_paragraphr~   s           r"   test_extract_intro_and_titler   >  s   -j$))GAbDM:R:RSSLE5&&&&&e####YYYYYU****  "9DII}b1GAbDMABB   K %%)+)CDIIgaclbT1GAbDMABB* *&& u$$$$u$$$$ -j.IILE5E$$$$W$$$$$$ -3 LE5 E))))\)))))) -O LE5 55555 ii G GU2YY G G GHHO)&8 HE1 #%%%%u::""4--6666 
~-C	D	D	D 3 3
":r2223 3 3 3 3 3 3 3 3 3 3 3 3 3 3	~-E	F	F	F 8 8
":w7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s$   H::H>H> JJ
Jzmode,expected_md5rp    a546be453c8f436e744838a4801bd3a0t ea8a570e9f3afc0a7c3f2a17a48b8047c                    d}|dz  }|                     |           t          j        ||           }||k    s
J |             t          j        |          r
J |             t	          t          |          dz   d          5 }|                    |           ddd           n# 1 swxY w Y   t          j        ||           s
J |             dS )z6Test md5sum check functions work on know file content.s   Local test
testz.md5r0   N)write_bytesrV   
get_md5summd5sum_is_currentrJ   rI   r;   )modeexpected_md5tmp_pathfile_contentfnamefile_md5file_checksums          r"   test_md5sumsr   s  s    %LvE	l###}UD))H|###T####E**00D000	c%jj6!3	'	' &=H%%%& & & & & & & & & & & & & & &t,,22d22222s    B""B&)B&zfailing_code, want)O###############################################################################First_test_failr   second_failznot defined)r   zinput("foo")r   r   Cannot use input)r   z
bad syntaxr   r   zinvalid syntaxc                 n   |                      dd           |                      d           t          j        t          j                            | d         d          dd          5 }|                    d	                    |                     d
d
d
           n# 1 swxY w Y   t          j        d| d         | d         |            |j	        
                                 |j	        j        d         d         }||v sJ d|vsJ d|vrd|vsJ d|vsJ t          j        t          j                            | d         d          dd          5 }|                                                    d          }|dk    s
J d            |dk    s
J d            	 d
d
d
           d
S # 1 swxY w Y   d
S )zATest that failing examples are only executed until failing block.ra   rc   reset_moduleszraise.pyfilename_patternexamples_dirr0   r&   r   encodingr3   Ngallery_dirr   r   gen_galleryr   gen_rst_check_inputz	raise.rstrpytbz#Did not run into errors in bad coder   z)Did not stop executing script after error)ri   codecsrJ   r>   pathr<   r;   rV   generate_file_rstwarningassert_called_once	call_argsreadcount)rY   failing_codewantlog_collectorreq_pilr@   msgex_failing_blockss           r"   test_fail_exampler     s     r<<<444	
\.1:>>
 
 
 ) 
			,''((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ]#^$	   ,,...


)!
,Q
/C3;;;;####$$####$$$$ 

\-0+>>
 
 
 S 
FFHHNN622 A%%%'L%%% A%%%'R%%%%S S S S S S S S S S S S S S S S S Ss%   ))BB"%B"AF**F.1F.c                    t          j        t          j                            | d         |          dd          5 }|                    d                    |                     ddd           n# 1 swxY w Y   t          j        t          j                            | d         d          dd          5  	 ddd           n# 1 swxY w Y   t          | d         | d	         | t                      d
           t          j                            |          d         dz   }t          j        t          j                            | d	         |          dd          5 }|	                                }ddd           n# 1 swxY w Y   |S )aC  Return the reST text of a given example content.

    This writes a file gallery_conf['examples_dir']/fname with *content*,
    creates the corresponding rst file by running generate_file_rst() and
    returns the generated reST code.

    Parameters
    ----------
    gallery_conf
        A gallery_conf as created by the gallery_conf fixture.
    fname : str
        A filename; e.g. 'test.py'. This is relative to
        gallery_conf['examples_dir']
    content : str
        The content of fname.

    Returns
    -------
    rst : str
        The generated reST code.
    r   r0   r&   r   r3   N
README.txtutf8r   F)is_subsectionr   .rstr   )
r   rJ   r>   r   r<   r;   r   setsplitextr   )rY   r   contentr@   	rst_fnamersts         r"   _generate_rstr     s$   , 

\.1599g
 
 
 $	
			'""###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 

\.1<@@#v
 
   	               ^$]#      ''*V3I	
\-0)<<3QX
 
 
 	
ffhh               Js5   )A11A58A56CCCE??FFza
"""
Make a plot
===========

Plot.
"""
import matplotlib.pyplot as plt
plt.plot([0, 1], [0, 1])
r3   c                    dd l m} |d         }t                      }t          |                                |          D ]}\  }}|                    |          }|                    d          sJ t          |                              d          }|	                    |           |
                    |           ~|                    d           t          ||d                   S )Nr   rg   z.png.jpgallsrc_dir)matplotlib.pyplotpyplotlistzipget_fignumsfigureendswithr   with_suffixsavefigappendcloser   )	block
block_varsrY   pltrg   image_pathsfig_num
image_pathfigs	            r"   _alpha_mpl_scraperr     s    ######$%:;&&K"3??#4#46IJJ ' 'jj!!""6******%%11&99
J:&&&&IIek<	#:;;;r$   c                 T    t           g| d<   t          | dt                    }d|v sJ dS )zDTest that thumbnails without an alpha channel work w/custom scraper.rc   plot_test.pyr   N)r   r   ALPHA_CONTENT)rY   req_mpl_jpgr   s      r"   #test_custom_scraper_thumbnail_alphar     s2    &8%9L!"
nm
D
DCS======r$   c                     t          | dt                    }d|v sJ d|v sJ d| d<   t          | dt                    }d|vsJ d|vsJ dS )z8Test the gallery_conf['remove_config_comments'] setting.test.pyr   r   Tremove_config_commentsNr   r   )rY   r   r   s      r"   test_remove_config_commentsr     sy    
i
9
9C2c9999+s2222-1L)*
i
9
9C2#====+3666666r$   r   TFc                     || d<   t          | dt                    }dt          v sJ d|vsJ dt          v sJ d|vsJ dS )zTest removal of ignore blocks.r   r   r   r   Nr   )rY   r   r   r   s       r"   test_remove_ignore_blocksr     sk     .DL)*
i
9
9C0G;;;;0;;;;*g5555*#555555r$   c                     t           dgz   }d}t          j        t          |          5  t	          | d|           ddd           dS # 1 swxY w Y   dS )z9Test sphinx_gallery_dummy_images configuration validated.z## sphinx_gallery_dummy_images=Falsez5sphinx_gallery_dummy_images setting is not an integerr   r   N)r   r   r   r   r   )rY   r   content_imager   s       r"   test_dummy_image_errorr   )  s    - M BC	~S	1	1	1 > >lI}===> > > > > > > > > > > > > > > > > >s   AAAc                 d    t           g dz   }d| d<   d| d<   t          | d|          }d}||v sJ dS )	zTest empty final block is removed.

    Empty final block can occur after sole config comment is removed from final block.
    )rR   r   z$# sphinx_gallery_line_numbers = TrueTr   min_reported_timer   z0RuntimeWarning)


.. rst-class:: sphx-glr-timingN)r   r   )rY   r   content_blockr   r   s        r"   test_final_empty_blockr   3  sR    
 RRRRM-1L)*(*L$%
i
?
?C@D3;;;;;;r$   c                 B    t          | dt                    }d}||v sJ dS )z+Test html only directive for download_link.r   zK.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

Nr   )rY   r   r   download_link_notes       r"   !test_download_link_note_only_htmlr   @  s6    
i
9
9C	: 
 $$$$$$r$   c                 N    t          | dt                    }dD ]}d|z   |v sJ dS )z Test classes for download links.r   )pythonjupyterz$sphx-glr-download sphx-glr-download-Nr   )rY   r   r   kinds       r"   test_download_link_classesr   K  sI    
i
9
9C% D D5<CCCCCD Dr$   zG
""":obj:`numpy.pi` :func:`numpy.sin`"""
import numpy
numpy.pi
numpy.e
zexclusion, expected>   numpy.enumpy.pi	numpy.sinz.*r  r  piznumpy\.esin)zexclude nothing (default)z/exclude anything (explicit backreferences only)z-explicit backref not shadowed by implicit onezexclude implicit backref)idsc                    t          j        t          j                  }|                    t          d|           d| d<   |r|| d<   t          |            t          | dt                     |j        j	        d         |k    sJ d S )N_write_backreferences)numpy
doc_moduleexclude_implicit_docztest_exclude_implicit.pyr   )
r   create_autospecrV   r  setattrr   r   EXCLUDE_CONTENTr   args)rY   	exclusionexpectedmonkeypatchr   mock_write_backreferencess         r"   test_exclude_implicitr  Z  s      !% 4R5M N N35NOOO!+L @/8+,1,???, :OLLL$.3A6(BBBBBBr$   gallery_header)zGALLERY_HEADER.rstr   z
README.rstc                 @   t          t          j                            | d         |          d          5 }|                    d                                           ddd           n# 1 swxY w Y   t          | d         | d         | g           }d|d         v sJ dS )zTest gen_dir_rst.r   wb   Testing
=======

Óscar here.Nr   u   Óscar herer   )rJ   r>   r   r<   r;   encoder   )rY   r  fidouts       r"   test_gen_dir_rstr  t  s     
bgll<	2NCCT	J	J ?c		4;;==>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Ym!<lB C CF""""""s   (A))A-0A-zGALLERY_HEADER.badz
README.badc                    t          t          j                            | d         |          d          5 }|                    d                                           ddd           n# 1 swxY w Y   t          j        t          d          5  t          | d         | d         | g            ddd           dS # 1 swxY w Y   dS )zFCheck `_get_gallery_header` raises error for invalid header extension.r   r  r  Nzdoes not have a GALLERY_HEADERr   r   )
rJ   r>   r   r<   r;   r  r   r   r   r   )rY   r  r  s      r"   test_gen_dir_rst_invalid_headerr    s:    
bgll<	2NCCT	J	J ?c		4;;==>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?	~-M	N	N	N 
 
#\-%@,PR	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s#   (A))A-0A-B;;B?B?c                    |                      dd           |                      t          j        t          j                  dz              d}d}g d}|D ]}t          | |t                    }t          j                            |          d         d	z   }t          j	        | d
         t          j        
                    | d         |                    r||v sJ ||v sJ ||vsJ ||vsJ dS )z4Test if only examples matching pattern are executed.ra   r   plot_0r   uf   
 .. code-block:: none

    Óscar output
    log:Óscar
    $\langle n_\uparrow n_\downarrow \rangle$zRuntimeWarning: WarningsAbound)z	plot_0.pyz	plot_1.pyz	plot_2.pyr   r   r   r   N)ri   reescaper>   sepr   r   r   r   searchr<   )	rY   r   r   code_outputwarn_outputfnamesr   r   r   s	            r"   test_pattern_matchingr(    s)   r<<<26):):X)EFFF	<  3K444F * *L%99G$$U++A.7	9+,GLLm4i@@
 
 	* #%%%%#%%%%%c))))c)))))* *r$   test_str)z$# sphinx_gallery_thumbnail_number= 2z## sphinx_gallery_thumbnail_number=2z$#sphinx_gallery_thumbnail_number = 2z'    # sphinx_gallery_thumbnail_number=2c                 j   t          j        dd          5 }|                    d                    d| g                     ddd           n# 1 swxY w Y   	 t	          |j                  \  }}t          j        |j                   n# t          j        |j                   w xY w|ddik    sJ dS )	z*Test correct plot used as thumbnail image.r0   Fr1   r3   r4   Nthumbnail_numberr   r8   r)  r@   r    r!   s       r"   test_thumbnail_numberr-    s     
	$S	7	7	7 61			=(3445556 6 6 6 6 6 6 6 6 6 6 6 6 6 66qv>>	6
	!&	!&+Q///////rD   )z3# sphinx_gallery_thumbnail_path= '_static/demo.png'z2# sphinx_gallery_thumbnail_path='_static/demo.png'z3#sphinx_gallery_thumbnail_path = '_static/demo.png'z6    # sphinx_gallery_thumbnail_path='_static/demo.png'c                 j   t          j        dd          5 }|                    d                    d| g                     ddd           n# 1 swxY w Y   	 t	          |j                  \  }}t          j        |j                   n# t          j        |j                   w xY w|ddik    sJ dS )	z+Test correct plot used for thumbnail image.r0   Fr1   r3   r4   Nthumbnail_pathz_static/demo.pngr8   r,  s       r"   test_thumbnail_pathr0    s     
	$S	7	7	7 61			=(3445556 6 6 6 6 6 6 6 6 6 6 6 6 6 66qv>>	6
	!&	!&)+=>>>>>>>rD   c                 r   |                      t          j                            | d         d                     t	          j        t          j                            t          j                            t                    dd          | d                    t          j	        | d                   }t          j
        || d                   }|                    d          sJ t          j        |          }|                                }|rJ d|             d	 |j        D             }d
|v sJ d|vsJ dS )LTest generated zipfiles are not corrupt and have expected name and contents.r   r   r   	tinybuildr   r   z_python.zipBad file in zipfile: c                     h | ]	}|j         
S ra   rL   r}   items     r"   	<setcomp>z"test_zip_python.<locals>.<setcomp>      9994999r$   "examples/plot_command_line_args.pyexamples/julia_sample.jlN)ri   r>   r   r<   shutilcopytreedirnamer*   r   list_downloadable_sources
python_zipr   zipfileZipFiletestzipfilelistrY   r   zipfilepathzipfcheck	filenamess         r"   test_zip_pythonrL    s+   RW\\,y2I:%V%VWWW
O
RW__X..ZHH^$   2<3OPPH&xm1LMMK.....?;''DLLNNE555e55555994=999I/9<<<<%Y666666r$   c                 H   |                      t          j                            | d         d                     t	          j        t          j                            t          j                            t                    dd          | d                    t          j	        | d         d          }t          j
        || d         d          }t          j        |          }|                                }|rJ d	|             d
 |j        D             }d|v sJ d|v sJ dS )r2  r   r   r3  r4  r   )z.pyz.jlr   Nr5  c                     h | ]	}|j         
S ra   r7  r8  s     r"   r:  z(test_zip_mixed_source.<locals>.<setcomp>  r;  r$   r<  r=  )ri   r>   r   r<   r>  r?  r@  r*   r   rA  rB  rC  rD  rE  rF  rG  s         r"   test_zip_mixed_sourcerO    s   RW\\,y2I:%V%VWWW
O
RW__X..ZHH^$   2^$n H &xm1LdSSK?;''DLLNNE555e55555994=999I/9<<<<%222222r$   c           	         t          ddddddd          }|                     |           d	| d
<   t          j                            | d         d          }t          j        d|dd|            t          j        dd|          }t          j
        |          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 generated rst file includes the correct paths for binder.zsphinx-galleryzsphinx-gallery.github.iozhttps://mybinder.orgmasterz./binder/requirements.txtT)orgrepobinderhub_urlbranchdependenciesuse_jupyter_lab)binderr   r   r   zplot.pyr]   r   z\.py$r   Nzlab/tree/notebooks/plot.ipynbzrst-class:: sphx-glr-signaturezrst-class:: sphx-glr-timing)r	   ri   r>   r   r<   rV   save_rst_exampler!  subr   rJ   r   )rY   binder_confexample_file	test_filer@   r   s         r"   test_rst_exampler^    sC   ##.37#	
 	
	 	K {+++(*L$%7<<] ;YGGL|Q<HHHx66I	Y		 1ffhh               +c1111 ,s2222(C//////s   B;;B?B?function)scopec                 ,   t           j                            t           j                            dd                     }|j                            ddi           dt          t          |                     d                              t          g |d}|S )N__main____doc__r   Tztemp.png)rT   rg   rf   memory_delta	fake_main)
	importlibutilmodule_from_specspec_from_loader__dict__ri   r   rI   r<   r*   )rK   re  rZ   s      r"   rZ   rZ     s    //''
D99 I y"o...0V[[5L5L1M1MNN K r$   c                    |                      d           t          j                    }d                    g d          }d|z   dz   }t	          d|d          }i }t          j        ||d	|| |          }d
                    d |                                                    d
          dd	         D                       }||	                    dd
          k    sJ d	S )z4Test whether indentation of code output is retained.ra   rb   z\n)z  A BzA 1 2zB 3 4zprint('z')r   r   Nr3   c                 "    g | ]}|d d         S rH   Nra   r}   lines     r"   r   z+test_output_indentation.<locals>.<listcomp>;       >>>dabb>>>r$   )
ri   codeopCompiler<   r
   rV   execute_code_blockstripsplitr   )	rY   rZ   compilertest_stringr   
code_blockr    ru   output_test_strings	            r"   test_output_indentationr{  .  s    r***~H**88899K{"T)DvtQ''JI"*dKy F >>fllnn22488=>>>  !4!4UD!A!AAAAAAAr$   c                    |                      d           t          j                    }d}t          d|d          }i }t	          j        ||d|| |          }d                    d |                                                    d          d	d         D                       }|                    d          d
         dk    sJ dS )z_Test ANSI characters are removed.

    See: https://en.wikipedia.org/wiki/ANSI_escape_code
    ra   rb   zprint("[94m0.25")r   r   Nr3   c                 "    g | ]}|d d         S rm  ra   rn  s     r"   r   z'test_output_no_ansi.<locals>.<listcomp>O  rp  r$   rq  r   z0.25)	ri   rr  rs  r
   rV   rt  r<   ru  rv  )rY   rZ   rw  r   ry  r    ru   rz  s           r"   test_output_no_ansir~  @  s    
 r***~H"DvtQ''JI"*dKy F >>fllnn22488=>>>  ##D))"-777777r$   c                     t          j        d           |                     d           t          j                    }d}t          j        |t          d|d          d|| i            t          j	                     dS )zTest using absl logging does not throw error.

    This is important, as many popular libraries like Tensorflow use absl for logging.
    abslra   rb   z:from absl import logging
logging.info("Should not crash!")r   r   N)
r   importorskipri   rr  rs  rV   rt  r
   loggingshutdown)rY   rZ   rw  r   s       r"   test_absl_loggingr  U  s    
 r***~HHD%a(($\2   r$   c                     |                      d           t          j                    }t          ddd          }i }t	          j        ||d|| |          }|                                sJ dS )z@Tests that `print(__doc__)` doesn't produce an empty output box.ra   rb   r   zprint(__doc__)r   N)ri   rr  rs  r
   rV   rt  isspace)rY   rZ   rw  ry  r    ru   s         r"   test_empty_output_boxr  i  sz    r***~Hv/33JI"*dKy F >>r$   z
class repr_only_class():

    def __init__(self):
        pass

    def __repr__(self):
        return "This is the __repr__"

class_inst = repr_only_class()
class_inst
a  
class repr_and_html_class():
    def __init__(self):
        pass

    def __repr__(self):
        return "This is the __repr__"

    def _repr_html_(self):
        return "<div> This is the _repr_html_ div </div>"

class_inst = repr_and_html_class()
class_inst
a!  
print("print statement")

class repr_and_html_class():
    def __init__(self):
        pass

    def __repr__(self):
        return "This is the __repr__"

    def _repr_html_(self):
        return "<div> This is the _repr_html_ div </div>"

class_inst = repr_and_html_class()
class_inst
zI
import matplotlib.pyplot as plt
fig = plt.figure()
plt.close('all')
fig
z.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div> This is the _repr_html_ div </div>
    </div>
    <br />
    <br />z,.. code-block:: none

    print statement


c                 6   d| v }d| v }|                                  rdS |rX|rVd                    |                                                     d          dd                    }|                                S |r`d                    d |                                                     d          dd          D                       }|                                S |r<d                    |                                                     d                    }|S d S )Nz".. rst-class:: sphx-glr-script-outz.. raw:: htmlr   r3   r   c                 "    g | ]}|d d         S rm  ra   rn  s     r"   r   z!_clean_output.<locals>.<listcomp>  s     AAA$T!""XAAAr$   rH   )r  r<   ru  rv  )ru   is_textis_htmlrz  s       r"   _clean_outputr    s   2f<G'G~~ "r	 
"W 
"!YYv||~~';';D'A'A!""'EFF!'')))	 "!YYAA&,,.."6"6t"<"<QRR"@AAA
 
 "'')))	 "!YYv||~~';';D'A'ABB!!" "r$   z capture_repr, code, expected_outza=2
b=3r   z	assign,())ida=2
azvar,()za=2
print(a)2zprint(var),()zprint("hello")
a=2
ahellozprint+var,())__repr__zassign,(repr)z
var,(repr)zprint(var),(repr)zhello

2zprint+var,(repr)zThis is the __repr__zrepr_and_html,(repr)z%print statement

This is the __repr__zprint and repr_and_html,(repr))_repr_html_zrepr_only,(html)zrepr_and_html,(html)zprint and repr_and_html,(html))r  r  zrepr_and_html,(html,repr))r  r  zrepr_and_html,(repr,html)zrepr_only,(html,repr)	html_nonec                     t          j                    }t          d|d          }|| d<   i }	t          j        ||d|| |	          }
t          |
          |k    sJ dS )z:Tests output capturing with various capture_repr settings.r   r   capture_reprNrr  rs  r
   rV   rt  r  )rY   r  r   expected_outreq_mplr   rZ   rw  ry  r    ru   s              r"   test_capture_reprr    sr    x ~HvtQ''J#/L I"*dKy F   L000000r$   z:caprepr_gallery, caprepr_file, caprepr_block, expected_outz()z("__repr__",)z() --> () --> reprz() --> repr --> Nonezrepr --> () --> Nonez() --> repr --> ()zrepr --> () --> ()c                     t          j                    }|rd| dnd}t          d| dd          }	|| d<   d|i}
t          j        ||	d|| |
          }t          |          |k    sJ dS )	z>Tests that per file/block capture_repr overrides gallery_conf.z$# sphinx_gallery_capture_repr_block=r3   r   r   za=2
2r   r  Nr  )rY   caprepr_gallerycaprepr_filecaprepr_blockr  r  r   rZ   rw  ry  r    ru   s               r"   (test_capture_repr_per_file_and_per_blockr    s    * ~H 	@}@@@@ 
 v-777;;J#2L .I"*dKy F   L000000r$   c                     t          j                    }t          ddd          }d| d<   i }t          j        ||d|| |          }t          |          dk    sJ dS )zOTests that `ignore_repr_types` correctly ignores the output of a specific type.r   r  r   intignore_repr_typesNr   r  )rY   r  r   rZ   rw  ry  r    ru   s           r"   test_ignore_repr_typesr  9  sp    ~Hvx++J(.L$%I"*dKy F   B&&&&&&r$   )order
call_count))beforer   )afterr   )bothr   c                     d }t          j        |          }|f| d<   || d<   t          | dt                     |j        |k    sJ dS )z)Test that reset module with 2 parameters.c                     d S Nra   )rY   r   s     r"   cleanup_2_paramz8test_reset_module_order_2_param.<locals>.cleanup_2_paramK      r$   r   reset_modules_orderr   N)r   r  r   r   r  )rY   r  r  r   r  mock_reset_modules         r"   test_reset_module_order_2_paramr  E  sh       ,_==%6$8L!*/L&',888':555555r$   )r  r  expected_call_order))r  r   )r  )r  r   )r  )r  r   )r  r  c                     d }t          j        |          }|f| d<   || d<   t          | dt                     |j        |k    sJ d |D             }|                    |           dS )z$Test reset module with 3 parameters.c                     d S r  ra   )rY   r   whens      r"   cleanup_3_paramz8test_reset_module_order_3_param.<locals>.cleanup_3_paramb  r  r$   r   r  r   c                 b    g | ],}t          j        t           j        t           j        |          -S ra   )r   callANY)r}   r  s     r"   r   z3test_reset_module_order_3_param.<locals>.<listcomp>k  s7       16	$(DHe,,  r$   N)r   r  r   r   r  assert_has_calls)rY   r  r  r  r   r  r  expected_callss           r"   test_reset_module_order_3_paramr  U  s       ,_==%6$8L!*/L&',888':5555 :M  N &&~66666r$   c                     d }t          j        |          }|f| d<   d| d<   t          j        t          d          5  t          | dt                     ddd           n# 1 swxY w Y   |j        d	k    sJ dS )
z-Test reset module with unknown 3rd parameter.c                     d S r  ra   )rY   r   invalids      r"   r  zEtest_reset_module_order_3_param_invalid_when.<locals>.cleanup_3_paramt  r  r$   r   r  r  zB3rd parameter in cleanup_3_param function signature must be 'when'r   r   Nr   )r   r  r   r   
ValueErrorr   r   r  )rY   r  r  s      r"   ,test_reset_module_order_3_param_invalid_whenr  q  s       ,_==%6$8L!*2L&'	S
 
 
 = = 	lNG<<<	= = = = = = = = = = = = = = =
 '1,,,,,,s   A!!A%(A%c              #   T   K   d}t          j        |          }|j        }| |||fV  dS )zWrap our log_collector.zsource file nameN)rV   _LoggingTeeru   )r   src_filenameteeoutput_files       r"   log_collector_wrapr    s>       &L
.
&
&C*K
sK
777777r$   c                 .   | \  }}}}|                     d           |                                 |                                dk    sJ |j        j        dk    sJ ||j        j        d         d         v sJ d|j        j        d         d         v sJ d S )NzOutput
r   r   Outputr   )r;   flushgetvalueverboser  call_args_listr  r   r  r  r  s        r"   test_full_liner    s    4F1M<kIIjIIKKK!!Z//// +q0000=0?B1EEEEE},;A>qAAAAAAAr$   c                 T   | \  }}}}|                     d           |                                dk    sJ |j                                         ||j        j        d         v sJ |                                 |j        j        dk    sJ d|j        j        d         d         v sJ d S )Nr  r   r   r   )r;   r  r  r   r   r  r  r  r  s        r"   test_incomplete_line_with_flushr    s    4F1M<kIIh!!X----,,...=0:1===== IIKKK +q0000},;A>qAAAAAAAr$   c                    | \  }}}}|                     d           |                                dk    sJ |j                                         ||j        j        d         v sJ |                     d           |                                dk    sJ |j        j        dk    sJ d|j        j        d         d         v sJ d|j        j        d         d         v sJ d S )	Nr  r   z
More output
zOutput
More output
rS   r   zMore outputr   )r;   r  r  r   r   r  r  r  s        r"   %test_incomplete_line_with_more_outputr    s   4F1M<kIIh!!X----,,...=0:1===== II   !!%<<<<< +q0000},;A>qAAAAAM1@CAFFFFFFFr$   c                 X   | \  }}}}|                     d           |                                dk    sJ |j        j        dk    sJ ||j        j        d         d         v sJ d|j        j        d         d         v sJ d|j        j        d         d         v sJ |j        dk    sJ d S )	Nz!first linesecond line
third linerS   r   z
first liner   zsecond liner   z
third line)r;   r  r  r  r  logger_bufferr  s        r"   test_multi_liner    s    4F1M<kII3444!!%JJJJJ +q0000=0?B1EEEEE=0?B1EEEEEM1@CAFFFFF,,,,,,r$   c                     | \  }}}}|                                 rJ |                                rJ |                                sJ d S r  )readableseekablewritabler  r~   r  s      r"   test_textio_compatr    sQ    %LAq#q||~~||~~<<>>r$   c                     | \  }}}}t          j        t          j                  5  |                                 d d d            d S # 1 swxY w Y   d S r  )r   r   ioUnsupportedOperationfilenor  s      r"   test_filenor    s    %LAq#q	r.	/	/  

                 s   AAAc                     |\  }}}}|                                 rJ |                     |j        dd            |                                 sJ d S )Nisattyc                      dS )NTra   ra   r$   r"   <lambda>ztest_isatty.<locals>.<lambda>  s    d r$   )r  r  ru   r  r  r~   r  s       r"   test_isattyr    sY    %LAq#qzz||
Hll;;;::<<r$   c                    |\  }}}}|                                 |j                                         k    sJ |                     |j        dd            |                                 |j                                         k    sJ d S )Ntellc                      dS )N*   ra   ra   r$   r"   r  ztest_tell.<locals>.<lambda>  s    B r$   )r  ru   r  r  s       r"   	test_tellr    s{    %LAq#q88::******
FJJ77788::********r$   c                 B    | \  }}}}|j         |j        j         k    sJ d S r  )errorsru   r  s      r"   test_errorsr    s-    %LAq#q:*******r$   c                 B    | \  }}}}|j         |j        j         k    sJ d S r  )newlinesru   r  s      r"   test_newlinesr    s-    %LAq#q<3:.......r$   )jrc  r(   r   rr  rf  r  r  r>   r!  r>  r9   rC  pathlibr   unittestr   r   sphinx.errorsr   sphinx_gallery.gen_rstr   rV   sphinx_galleryr   sphinx_gallery.gen_galleryr   r   "sphinx_gallery.interactive_exampler	   sphinx_gallery.py_source_parserr
   r   sphinx_gallery.scrapersr   r   r*   parentsr   r   r#   r.   rC   rM   r_   rl   rr   rw   r   markparametrizer   r   r   rv  r   r   r   r   r   r   r   r   r   r  r  r  r  r(  r-  r0  rL  rO  r^  fixturerZ   r{  r~  r  r  code_repr_onlycode_repr_and_htmlcode_print_and_repr_and_htmlcode_plthtml_outtext_above_htmlr  paramtupler<   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  ra   r$   r"   <module>r     s
   ' & 



       				  				 				                 ( ( ( ( ( ( # # # # # # $ $ $ $ $ $        A @ @ @ @ @ N M M M M M M M A A A A A A A AtH~~a      F" " "     $% $% $%N% % %47# 7# 7#t20 20 20j!8 !8 !8H  28 28 28j 	01	01 3 3 3   LLLL	

 IIII	
 
DDD	DFVW
 $S $S $SN- - -`	 
E$KK < < <   	7 	7 	7 1D%=AA6 6 BA6> > >
 
 
% % %D D D
 
E$KK  	3334
+z*+
5556
u	Z89		 	 	   C C C    # # #  
 
 
* * *:    0 0 0    ? ? ?7 7 7$3 3 3&0 0 0: j!!!  "!B B B$8 8 8*  (     "" " "( &UUWWj"===UUWWhx888UUWWosGGGUUWW6NSSS]JGGG]HclCCC]OS=PQQQ3\FX	
 	
 	
 	"%		
 	
 	
 	(5/		
 	
 	
 	%~r>PQQQ0(?U	
 	
 	
 	(GG_h/00/		
 	
 	
 	'*		
 	
 	
 	'"*		
 	
 	
 	'"&		
 	
 	
 	%xDDDg47 7p1 1q7 7p1 @UUWWdOS=QRRRUUWWmT3;QRRR]D$7MNNNUUWWmT2:NOOO]D$7KLLL	 	1 1	 	14	' 	' 	' GGG 
6 
6 
6 2   7 7 7(- - -" 8 8 8B B BB B BG G G - - -      + + ++ + +
/ / / / /r$   