
    -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m	Z	 ddl
mZ ddlmZmZmZ ddlmZmZmZmZ ddlmZ dd	lmZmZmZmZ d
Zd Zd Zd Zej         !                    d          d             Z"ej         !                    d          d             Z#ej         $                    d ej%        eddej         !                    d                     ej%        eddej         !                    d                    g          d             Z&ej         $                    d ej%        eddej         !                    d                     ej%        eddej         !                    d                     g          d!             Z'ej         $                    d ej%        ed"d#ej         !                    d$                     ej%        ed%d&ej         !                    d'                    g          d(             Z(d) Z)ej         !                    d*          d+             Z*d, Z+d- Z,dd.Z-d/Z. e/d0d1d2d34          Z0d5 e01                                D             Z2d6Z3ej         !                    e34                    d7d8d9:                    Z5ej         !                    e34                    d;d<d=:                    Z6ej         !                    e34                    d;d>d?:                    Z7ej         !                    e34                    d;d@d?:                    Z8dAZ9ej         !                    e34                    e9d@dB:                    Z:ej         !                    e34                    e9d>dB:                    Z;ej         $                    dC ej%        dD e<dE          dFe5           ej%        dD e<dE          dGe6           ej%        d e<dH          dIe8           ej%        d e<dJ          dKe7           ej%        d e<dL          dMe:           ej%        d e<dN          dOe;          ge2R           dP             Z=dQ Z>dR Z?ej         !                    dS          ej         @                    dTU          dV                         ZAej         !                    dW          dX             ZBej         !                    d          dY             ZCej         !                    dZ          d[             ZDej         !                    d\          d]             ZEej         !                    d\          d^             ZFej         !                    d_          d`             ZGej         !                    da          db             ZHej         $                    d; ej%        dcej         !                    dd                     ej%        deej         !                    df                    g          dg             ZIej         !                    dh          di             ZJej         !                    d          dj             ZKej         !                    dk          dl             ZLej         !                    d          ej         @                    dmU          dn                         ZMej         !                    do          ej         @                    dpU          dq                         ZNdr ZOej         !                    ds          ej         @                    dtU          du                         ZPej         !                    d          ej         @                    dvU          dw                         ZQej         !                    dx          ej         @                    dyU          dz                         ZRd{ ZSd| ZTej         !                    d}          d~             ZUej         !                    d          d             ZVej         !                    d          d             ZWej         !                    d          d             ZXej         !                    d          d             ZYej         !                    d          d             ZZej         !                    d          d             Z[dS )z'Test Sphinx-Gallery gallery generation.    N)Path)Sphinx)is_serializable)ConfigErrorExtensionErrorSphinxWarning)_fill_gallery_conf_defaultsfill_gallery_conf_defaultswrite_api_entry_usagewrite_computation_times)create_jupyterlite_contents)_collect_gallery_files_escape_ansicheck_duplicate_filenamescheck_spaces_in_filenamesz#
'''
Title
-----
Description.
'''

c                  F   t          d          } t          j        t          d          5  t	          |            ddd           n# 1 swxY w Y   t          d          } t          j        t          d          5  t	          |            ddd           n# 1 swxY w Y   t          d	          } t          j        t          d
          5  t	          |            ddd           n# 1 swxY w Y   t          d	          } t          j        t          d          5  t	          |            ddd           n# 1 swxY w Y   t          t
                    } t          j        t          d          5  t	          |            ddd           dS # 1 swxY w Y   dS )z'Test that bad config values are caught. )example_dirz,example_dir.*did you mean 'examples_dirs'?.*matchN)n_subsection_orderz4did you mean one of \['subsection_order', 'within_.*zsphinx_gallery.a.b.Key)within_subsection_orderz%Unknown string option.*when importingg      ?zmust be callable)minigallery_sort_orderz'Got class rather than callable instance)dictpytestraisesr   r	   intsphinx_gallery_confs    e/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx_gallery/tests/test_gen_gallery.pytest_bad_configr!   (   s   2...	I
 
 
 9 9 	$$78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 "555	R
 
 
 9 9 	$$78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 7OPPP	{*R	S	S	S 9 9#$78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9s;;;	{*<	=	=	= 9 9#$78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9c:::	{*S	T	T	T 9 9#$78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9sY   AAA>BB!BC,,C03C0"D>>EE9FFFc                    |                                  }|j        }|j        dk    sJ t          j        t
                    5 }|                    ddd           ddd           n# 1 swxY w Y   dt          |j                  v sJ dS )zITest default Sphinx-Gallery config loaded when extension added to Sphinx.Sphinx-Gallery <Tests>r   xTNzalready present)	create_sphinx_appconfigprojectr   r   r   add_config_valuestrvalue)sphinx_app_wrapper
sphinx_appcfgexcinfos       r    test_default_configr/   ?   s    #5577J

C;22222	~	&	& F'##$93EEEF F F F F F F F F F F F F F FGM 2 2222222s   A&&A*-A*c                 >   t                      }t          i                                           D ]H\  }}t          |          s4|                    t          |           dt          |                      Id                    |          }|rJ d|             dS )z-Test that the default config is serializable.z: 
zNon-serializable values found:
N)listr	   itemsr   appendreprjoin)r+   badkeyvals       r    test_serializabler:   J   s    
&&C/3399;; 4 4Ss## 	4JJ$s))22tCyy22333
))C..C<<<s<<<<<<<    zP
sphinx_gallery_conf = {
    'examples_dirs': 'src',
    'gallery_dirs': 'ex',
}contentc                     |                                  }|j        }|j        dk    sJ |j                                        }|dk    sJ dS )zTesting that no warning is issued with a simple config.

    The simple config only specifies input (examples_dirs) and output
    (gallery_dirs) directories.
    r#   r   N)r%   r&   r'   _warninggetvaluer+   r,   r-   
build_warns       r    test_no_warning_simple_configrC   U   s\     $5577J

C;22222$--//Jr;   z\
sphinx_gallery_conf = {
    'examples_dirs': ['src', 'excess'],
    'gallery_dirs': 'ex',
}c                 l    |                                  }|j                                        }d|v sJ dS )zFCheck warning when 'examples_dirs' and 'gallery_dirs' unequal lengths.z;'examples_dirs' and 'gallery_dirs' are of different lengthsN)r%   r?   r@   r+   r,   rB   s      r    "test_unequal_examples_gallery_dirsrF   i   s@     $5577J$--//JHJVVVVVVr;   zerr_class, err_matchz'Unknown string option for reset_moduleszResetter unknownz-sphinx_gallery_conf={'reset_modules': ('f',)}idmarksz reset_modules.* must be callablezResetter not callablez-sphinx_gallery_conf={'reset_modules': (1.,),}c                     t          j        ||          5  |                                  d d d            d S # 1 swxY w Y   d S Nr   r   r   r%   r+   	err_class	err_matchs      r    test_bad_resetrP   y       , 
y		2	2	2 / /,,.../ / / / / / / / / / / / / / / / / /   9= =z*'reset_modules_order' config allowed typesz/sphinx_gallery_conf={'reset_modules_order': 1,}zreset_modules_order must be inzreset_modules_order not validz7sphinx_gallery_conf={'reset_modules_order': 'invalid',}c                     t          j        ||          5  |                                  d d d            d S # 1 swxY w Y   d S rK   rL   rM   s      r    test_bad_reset_modules_orderrT      rQ   rR   zUnknown csszCSS str errorz%sphinx_gallery_conf={'css': ('foo',)}zconfig allowed types:zCSS type errorzsphinx_gallery_conf={'css': 1.}c                     t          j        ||          5  |                                  ddd           dS # 1 swxY w Y   dS )z/Test 'css' configuration validation is correct.r   NrL   rM   s      r    test_bad_cssrV      s    & 
y		2	2	2 / /,,.../ / / / / / / / / / / / / / / / / /rR   c                  P   t          d          } t          j        t          d          5  t	          |            ddd           n# 1 swxY w Y   t          d          } t          j        t          d          5  t	          |            ddd           dS # 1 swxY w Y   dS )	z8Test that we raise an error for bad API usage arguments.)foo)api_usage_ignorez!'api_usage_ignore' config allowedr   NrX   )show_api_usagez#.*must be True, False or "unused".*)r   r   r   r   r	   r   s    r    test_bad_apir[      s'   999	{*M	N	N	N 9 9#$78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9e444	{*O	P	P	P 9 9#$78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9s#   AAA>BB"Bz
sphinx_gallery_conf = {
    'backreferences_dir': os.path.join('gen_modules', 'backreferences'),
    'examples_dirs': 'src',
    'gallery_dirs': 'ex',
}c                     |                                  }|j        }|j        dk    sJ |j        d         t          j                            dd          k    sJ |j                                        }|dk    sJ dS )z6Test no warning is issued under the new configuration.r#   backreferences_dirgen_modulesbackreferencesr   N)	r%   r&   r'   r   ospathr6   r?   r@   rA   s       r    test_config_backreferencesrb      s     $5577J

C;22222"#78BGLL'= =     $--//Jr;   c                 0   |                                  }g d}d}d}t          |dd                    |j                                        }|dk    sJ t          |           |j                                        }|                    |          |v sJ dS )z?Test for a warning when two files with the same filename exist.)./a/file1.py./a/file2.pyz
a/file3.pyz./b/file1.pyzjDuplicate example file name(s) found. Having duplicate file names will break some links. List of files: {}z['./b/file1.py']Nr   )r%   r   r?   r@   formatr+   r,   filesmsgmrB   s         r    test_duplicate_files_warnrl      s    #5577JJJJE	3  	A eCRCj)))$--//J e$$$$--//J::a==J&&&&&&r;   c                 0   |                                  }g d}d}d}t          |dd                    |j                                        }|dk    sJ t          |           |j                                        }|                    |          |v sJ dS )z@Test for a exception when an example filename has a space in it.)rd   re   z./a/file 3.pyzlExample file name(s) with spaces found. Having spaces in file names will break some links. List of files: {}z['./a/file 3.py']Nrf   r   )r%   r   r?   r@   rg   rh   s         r    test_spaces_in_files_warnrn      s    #5577J===E	 
 	A eCRCj)))$--//J e$$$$--//J::a==J&&&&&&r;   c                 ~   t          | j        ddd          }t                      }|d}d}nd| d}d	}t          |d
d          5 }|D ]A}||v r;|                    t          j        ||                              d                     B	 ddd           n# 1 swxY w Y   |pt          d          }||k    sJ dS )a  Iterates through sphx-glr-thumbcontainer divs and reads key from the tooltip.

    Used to test that these keys (in index.rst) appear in a specific order. The `.py`
    files include a source-of-truth line indicating the position in the sort order that
    the thumbnail for that file should occur, for the various built-in sorters.

    The regex below extracts info from that source-of-truth line to check that the
    thumbnail ordering was correct --- unless `expected_order` is provided, in which
    case an alternative regex extracts the digit-part of the filename from the crossref,
    and compares the order of crossrefs to `expected_order`.
    z..exz	index.rstNzC.*:ref:`sphx_glr_ex_(?:(?:first|second)-subsection_)?plot_(\d)\.py`z:ref:z.*:z=(\d):.*sphx-glr-thumbcontainerrutf-8encoding   	123456789)r   outdirr2   openr4   rer   group)	r,   r8   expected_orderindex_fnameorderregexlocatorfidlines	            r    _check_orderr     s%    z($kBBKFFE
{V$s$$$+	k3	1	1	1 =S 	= 	=D$RXeT2288;;<<<	== = = = = = = = = = = = = = = $8tK'8'8NN""""""s   ABB Bzw
sphinx_gallery_conf = {{
    "examples_dirs": "src",
    "gallery_dirs": "ex",
    "within_subsection_order": "{}",
}}NumberOfCodeLinesSortKeyFileSizeSortKeyFileNameSortKeyExampleTitleSortKey)linesfilesizefilenametitlec              #      K   | ]X\  }}t          j        |d d| t           j                            t                              |                              V  Yd S )Nwithin_subsection_sort_by_r<   rG   )r   parammarkadd_conf"_template_conf_for_builtin_sortersrg   ).0kindsorters      r    	<genexpr>r   ;  s       
' 
' 	f L...k""6==fEE # 
 
	  
' 
' 
' 
' 
' 
'r;   z
{imports}
sphinx_gallery_conf = {{
    "examples_dirs": "src",
    "gallery_dirs": "ex",
    "subsection_order": {subsection_order},
    "within_subsection_order": {within_subsection_order},
}}z0from sphinx_gallery.sorting import ExplicitOrderz@ExplicitOrder(["src/second-subsection", "src/first-subsection"])z"NumberOfCodeLinesSortKey")importssubsection_orderr   r   z1["src/second-subsection", "src/first-subsection"]z/sphinx_gallery.sorting.NumberOfCodeLinesSortKeyz0"sphinx_gallery.utils._custom_subsection_sorter"z-"sphinx_gallery.utils._custom_example_sorter"NoneaD  
from sphinx_gallery.sorting import FunctionSortKey

def custom_sorter(filename):
    ORDER = [
        "plot_3.py",
        "plot_2.py",
        "plot_1.py",
        "plot_6.py",
        "plot_5.py",
        "plot_4.py",
        "plot_9.py",
        "plot_7.py",
        "plot_8.py",
    ]
    return ORDER.index(filename)
zFunctionSortKey(custom_sorter)zsort_key,expected_orderr   	123789456 subsection_sort_by_ExplicitOrdersubsection_sort_by_list	132564879$within_subsection_sort_by_custom_FQN	1328795648subsection_and_within_subsection_both_sort_by_custom_FQN	321654978%within_subsection_sort_by_custom_func	321978654@subsection_sort_by_FQN_and_within_subsection_sort_by_custom_funcc                 R    |                                  }t          |||           dS )zMTest sorting of examples with fully qualified name of a custom sort function.)r|   N)r%   r   )r+   sort_keyr|   r,   s       r    test_example_sortingr     s1    h $5577JXnEEEEEEr;   c                     g d} fd|D             }|D ]}|                                                       d          }|j        g}t          t	          ||d                    }d |D             }||k    sJ                      d          }	|j        |	j        g}t          t	          ||d                    }d |D             }||k    sJ d	S )
z/Test that example files are collected properly.)examples/file1.pyzexamples/test.rstzexamples/GALLERY_HEADER.rstzexamples/folder1/file1.pyexamples/folder1/file2.pyzexamples/folder2/file1.pyztutorials/folder1/file1.pyztutorials/folder2/file1.pyc                 :    g | ]}                     |          S  r6   r   rptmpdirs     r    
<listcomp>z.test_collect_gallery_files.<locals>.<listcomp>  #    999RR999r;   examplesTcheck_filenamesc                 P    h | ]#}t          j        d |j                  |j        $S )zexamples.*\.py$rz   searchstrpathr   aps     r    	<setcomp>z-test_collect_gallery_files.<locals>.<setcomp>  s>       ")4F
*S*S

  r;   	tutorialsc                 P    h | ]#}t          j        d |j                  |j        $S )z.*\.py$r   r   s     r    r   z-test_collect_gallery_files.<locals>.<setcomp>  s=       ")J
*K*K

  r;   Nensurer6   r   setr   )
r   gallery_confrel_filepaths	abs_pathsr   examples_pathdirscollected_filesexpected_filestutorials_paths
   `         r    test_collect_gallery_filesr     s4   	 	 	M :999=999I  
		KK
++M!"Dt\4HHH O &  N n,,,,[[--N!>#9:Dt\4HHH O &  N n,,,,,,r;   c                     g d} fd|D             }|D ]}|                                  d|d<                        d          }|j        g}t          t	          ||d                    }d |D             }||k    sJ d	S )
z9Test that ignore pattern example files are not collected.)r   zexamples/folder1/fileone.pyr   zexamples/folder2/fileone.pyc                 :    g | ]}                     |          S r   r   r   s     r    r   z=test_collect_gallery_files_ignore_pattern.<locals>.<listcomp>  r   r;   oneignore_patternr   Tr   c                 t    h | ]5}t          j        d t          |j                  j                  .|j        6S )r   )rz   r   r   r   namer   s     r    r   z<test_collect_gallery_files_ignore_pattern.<locals>.<setcomp>  sC       9VT"*--233; 	
;;;r;   Nr   )	r   r   r   r   r   r   r   r   r   s	   `        r    )test_collect_gallery_files_ignore_patternr     s      M :999=999I  
		%+L!"KK
++M!"Dt\4HHH O   N n,,,,,,r;   zr
sphinx_gallery_conf = {
    'examples_dirs': 'src',
    'gallery_dirs': 'ex',
    'copyfile_regex': r'.*\.rst',
}zown index.rst)filec                 .    |                                   dS )zMTest `generate_gallery_rst` works when own index gallery is first (and only).Nbuild_sphinx_appr+   s    r    test_own_index_firstr   
  s     '')))))r;   ad  
sphinx_gallery_conf = {
    'backreferences_dir' : os.path.join('modules', 'gen'),
    'examples_dirs': 'src',
    'gallery_dirs': ['ex'],
    'binder': {'binderhub_url': 'http://test1.com', 'org': 'org',
               'repo': 'repo', 'branch': 'branch',
               'notebooks_dir': 'ntbk_folder',
               'dependencies': 'requirements.txt'}
}c                 `   ddl m} |                                 }|j        j        }t          t          |j        d          d          5  	 ddd           n# 1 swxY w Y    ||d           dD ]<}t          |j        d|d         d         |d	z             	                                sJ =dS )
z(Test that notebooks are copied properly.r   )copy_binder_fileszrequirements.txtwNplot_1plot_2plot_3ntbk_foldergallery_dirs.ipynb)
"sphinx_gallery.interactive_exampler   r%   r&   r   ry   r   srcdirrx   exists)r+   r   r,   r   i_files        r    test_binder_copy_filesr     s    EDDDDD#5577J$8L	d:$&8993	?	?                j$'''0  (+X	
 

 &((	 	 	 	 s   
AAAc                    t          | j        d          }d}d| d}|                    d                              |          dz   }t	          t          |d          dd	          5 }|                    |           d d d            n# 1 swxY w Y   t          j        t                    5 }| 	                                 d d d            n# 1 swxY w Y   t          |j                  }d
|v sJ d| |v sJ ||v sJ d S )Nsrczprint(f'{a[}')zq'''
Failing example
---------------
Should emit a syntax error in the second code block.
'''
1 + 2

# %%
# More

r1   rv   	plot_3.pyr   rs   rt   zUnexpected failing exampleszline )r   r   splitindexry   writer   r   r   r   r)   r*   )r+   r   bad_linebad_codebad_line_nor   r.   tbs           r    %test_failing_examples_raise_exceptionr   9  s    )0%88KH 
  H ..&&,,X66:K	d;,,cG	D	D	D 		(              	~	&	& .'++---. . . . . . . . . . . . . . .	W]		B(B.... ;  B&&&&r>>>>>>s$   )BBB/CCCzu
sphinx_gallery_conf = {
    'examples_dirs': 'src',
    'gallery_dirs': 'ex',
    'filename_pattern': 'plot_1.py',
}c                 .    |                                   dS )zjTesting that no exception is issued when broken example is not built.

    See #335 for more details.
    Nr   r   s    r    ,test_expected_failing_examples_were_executedr   \  s     '')))))r;   zx
sphinx_gallery_conf = {
    'examples_dirs': 'src',
    'gallery_dirs': 'ex',
    'only_warn_on_example_error': True,
}c                 T   t          | j                  dz  }t          |dz  dd          5 }|                    t           d           ddd           n# 1 swxY w Y   |                                 }t          |j                                                  }d|v sJ d	|v sJ dS )
2Test behaviour of only_warn_on_example_error flag.r   r   r   rs   rt   raise ValueErrorNz2plot_3.py unexpectedly failed to execute correctlyz*WARNING: Here is a summary of the problems)	r   r   ry   r   MINIMAL_HEADERr   r   r?   r@   )r+   r   r   r,   rB   s        r    test_only_warn_on_example_errorr   l  s     )011E9K	kK'w	?	?	? 73		^5556667 7 7 7 7 7 7 7 7 7 7 7 7 7 7#4466Jj1::<<==J?:MMMM7:EEEEEEs   AAAc                    dD ],}|t          j        t                    j        v r
d| j        |<   -t          | j                  dz  }t          |dz  dd          5 }|                    t           d           d	d	d	           n# 1 swxY w Y   t          j        t                    5 }|                                  d	d	d	           n# 1 swxY w Y   t          t          |j                            }d
|v sJ d	S )r   )warningiserrorexception_on_warningTr   r   r   rs   rt   r   Nz(plot_3.py unexpectedly failed to execute)inspectgetfullargspecr   argskwargsr   r   ry   r   r   r   r   r   r   r   r)   r*   )r+   r8   r   r   r.   excs         r    .test_only_warn_on_example_error_sphinx_warningr     sz    : 2 2'(00555-1%c*)011E9K	kK'w	?	?	? 73		^5556667 7 7 7 7 7 7 7 7 7 7 7 7 7 7	}	%	% .++---. . . . . . . . . . . . . . .
s7=))
*
*C5<<<<<<s$   BB
B
*CCCz
sphinx_gallery_conf = {
    'examples_dirs': 'src',
    'gallery_dirs': 'ex',
    'expected_failing_examples' :['src/plot_2.py'],
}c                     t          j        t                    5 }|                                  d d d            n# 1 swxY w Y   t	          t          |j                            }d|v sJ d S )Nz!expected to fail, but not failing)r   r   r   r   r   r)   r*   )r+   r.   r   s      r    "test_examples_not_expected_to_passr    s     
~	&	& .'++---. . . . . . . . . . . . . . .
s7=))
*
*C.#555555s   ;??z
from sphinx_gallery.gen_rst import _sg_call_memory_noop

sphinx_gallery_conf = {
    'show_memory': _sg_call_memory_noop,
    'examples_dirs': 'src',
    'gallery_dirs': 'ex',
}c                 |    |                                  }|j                                        }d|v s
J |            d S )Nz0.0 MB)r   _statusr@   )r+   r,   statuss      r    test_show_memory_callabler    sH     $4466J((**Fvvr;   zfirst notebook cellz1sphinx_gallery_conf = {'first_notebook_cell': 2,}zlast notebook cellz0sphinx_gallery_conf = {'last_notebook_cell': 2,}c                     t          j        t                    5  |                                 }t	          ||j        d           ddd           dS # 1 swxY w Y   dS )z7Tests that first and last cell configuration validated.F
check_keysNr   r   r   r%   r
   r&   r+   apps     r    test_notebook_cell_configr    s    & 
{	#	# F F 2244"3
uEEEEF F F F F F F F F F F F F F F F F Fs   ,AAAz;
sphinx_gallery_conf = {
    'backreferences_dir': False,
}c                     t          j        t          d          5  |                                 }t	          ||j        d           ddd           dS # 1 swxY w Y   dS )z)Tests 'backreferences_dir' type checking.z)'backreferences_dir' config allowed typesr   Fr  Nr
  r  s     r    test_backreferences_dir_configr    s     
{*U	V	V	V F F 2244"3
uEEEEF F F F F F F F F F F F F F F F F F   ,AAAc                 l    |                                  }|j                                        }d|v sJ dS )zLCheck warning when no backreferences_dir set but minigallery directive used.z0'backreferences_dir' config is None, minigalleryN)r   r?   r@   rE   s      r    &test_minigallery_no_backreferences_dirr    s@     $4466J$--//J=KKKKKKr;   zW
import pathlib

sphinx_gallery_conf = {
    'backreferences_dir': pathlib.Path('.'),
}c                 \    |                                  }t          ||j        d           dS )z,Tests pathlib.Path does not raise exception.Fr  N)r%   r
   r&   r  s     r    &test_backreferences_dir_pathlib_configr    s2     
.
.
0
0CsCJ5AAAAAAr;   z+
Header
======

.. minigallery:: index.rst
c                     d}t          j        t          |          5  |                                  ddd           dS # 1 swxY w Y   dS )zKCheck error when minigallery directive's path input not in `examples_dirs`.z3minigallery directive error: path input 'index.rst'r   N)r   r   r   r   )r+   rj   s     r    %test_minigallery_not_in_examples_dirsr    s    " @C	~S	1	1	1 . .++---. . . . . . . . . . . . . . . . . .s   A  AAz
sphinx_gallery_conf = {
    'examples_dirs': ['src', 'src/sub_folder/sub_sub_folder'],
    'gallery_dirs': ['ex', 'ex/sub_folder/sub_sub_folder'],
}zN
Header
======

.. minigallery:: src/sub_folder/sub_sub_folder/plot_nested.py
c                     |                                  }t          |j                  dz  }t          |d          5 }|                                }ddd           n# 1 swxY w Y   d|v sJ d|v sJ dS )zCheck minigallery directive's path input resolution in nested `examples_dirs`.

    When a examples gallery is nested inside another examples gallery, path inputs
    from the nested gallery should resolve to the nested gallery.
    minigallery_test.htmlrr   Nz&_images/sphx_glr_plot_nested_thumb.pngz4sphx-glr-ex-sub-folder-sub-sub-folder-plot-nested-py)r   r   rx   ry   read)r+   r,   minigallery_htmlr   mg_htmls        r    test_minigallery_multi_matchr    s    * $4466JJ-..1HH		$	$ ((**               4w>>>>AWLLLLLLs   AA!$A!c                    d}d}t                      }t          | dd          5 }|D ]A}||v r;|                    t          j        ||                              d                     B	 ddd           n# 1 swxY w Y   |S )zCheck the minigallery example file number present in a rst file.

    Note this should only be used for examples in the root
    `sphinx_gallery/tests/testconfs` directory.
    rq   z5.+sphx-glr-thumbcontainer.+sphx_glr_plot_(\d)_thumb.+rr   rs   rt   rv   N)r2   ry   r4   rz   r   r{   )	rst_fnamer   r   example_numbersr   r   s         r    _get_minigallery_thumbnailsr   ,  s     (GDEffO	iw	/	/	/ G3 	G 	GD$&&rxt'<'<'B'B1'E'EFFF	GG G G G G G G G G G G G G G G s   AA77A;>A;a  
from sphinx_gallery.sorting import FunctionSortKey
from sphinx_gallery.utils import custom_minigallery_sort_order_sorter

sphinx_gallery_conf = {
    'examples_dirs': 'src',
    'gallery_dirs': 'ex',
    'minigallery_sort_order': FunctionSortKey(custom_minigallery_sort_order_sorter),
}zK
Header
======

.. minigallery:: src/plot_1.py src/plot_2.py src/plot_3.py
c                     |                                  }t          |j        d          }t          |          }|g dk    sJ dS )z5Check `minigallery_sort_order` works when a callable.r  )321Nr   r   rx   r   r+   r,   r  file_numberss       r    $test_minigallery_sort_order_callabler(  <  sP    * $4466JZ&(?@@I.y99L???******r;   z=
Header
======

.. minigallery:: src/plot_1.py src/plot_1.py
c                     |                                  }t          |j        d          }t          |          }|dgk    sJ dS )z;Check minigallery duplicate input paths are de-deuplicated.r  r$  Nr%  r&  s       r    %test_minigallery_duplicate_path_inputr*  X  sN    " $4466JZ&(?@@I.y99LC5      r;   z
sphinx_gallery_conf = {
    'examples_dirs': 'src',
    'gallery_dirs': 'ex',
    'backreferences_dir': 'gen_modules/backreferences',
    'doc_module': ('numpy',),
}zU
Header
======

.. minigallery:: sphinx_gallery.py_source_parser.Block src/plot_1.py
c                     |                                  }t          |j        d          }t          |          }|dgk    sJ dS )zxCheck object and path input de-deplication works in minigallery directive.

    `Block` is used in `src/plot_1.py`.
    r  r$  Nr%  r&  s       r    ,test_minigallery_duplicate_object_path_inputr,  p  sN    , $4466JZ&(?@@I.y99LC5      r;   c                 d    |                                  }t          |j        j        d g            d S N)r%   r   r&   r   r  s     r    !test_write_computation_times_noopr/    s0    

.
.
0
0CCJ:D"EEEEEr;   c                 d    t          |                                 t                      d            d S r.  )r   r%   r2   r   s    r    test_write_api_usage_noopr1    s+    ,>>@@$&&$OOOOOr;   z5
sphinx_gallery_conf = {
    'pypandoc': ['list',],
}c                     t          j        t          d          5  |                                 }t	          ||j        d           ddd           dS # 1 swxY w Y   dS )zTests 'pypandoc' type checking.z4'pypandoc' config allowed types: \['dict', 'bool'\].r   Fr  Nr
  r  s     r    test_pypandoc_config_listr3    s     
E
 
 
 F F !2244"3
uEEEEF F F F F F F F F F F F F F F F F Fr  z:
sphinx_gallery_conf = {
    'pypandoc': {'bad key': 1},
}c                     t          j        t          d          5  |                                 }t	          ||j        d           ddd           dS # 1 swxY w Y   dS )z)Tests 'pypandoc' dictionary key checking.z1'pypandoc' only accepts the following key values:r   Fr  Nr
  r  s     r    test_pypandoc_config_keysr5    s     
N
 
 
 F F !2244"3
uEEEE	F F F F F F F F F F F F F F F F F Fr  z
extensions += ['jupyterlite_sphinx']

sphinx_gallery_conf = {
    'backreferences_dir' : os.path.join('modules', 'gen'),
    'examples_dirs': 'src',
    'gallery_dirs': ['ex'],
}c                    t          j        d           |                                 }|j        j        }t          |d           dD ]<}t          |j        d|d         d         |dz                                             sJ =dS )	4Test that JupyterLite contents are created properly.jupyterlite_sphinxN	exceptionr   jupyterlite_contentsr   r   r   	r   importorskipr%   r&   r   r   r   r   r   r+   r,   r   r   s       r     test_create_jupyterlite_contentsr?    s     ,---#5577J$8L
d;;;;0  "(+X	
 

 &((	 	 	 	 r;   z
extensions += ['jupyterlite_sphinx']

sphinx_gallery_conf = {
    'backreferences_dir' : os.path.join('modules', 'gen'),
    'examples_dirs': 'src',
    'gallery_dirs': ['ex'],
    'jupyterlite': {'jupyterlite_contents': 'this_is_the_contents_dir'}
}c                    t          j        d           |                                 }|j        j        }t          |d           dD ]<}t          |j        d|d         d         |dz                                             sJ =dS )	r7  r8  Nr9  r   this_is_the_contents_dirr   r   r   r<  r>  s       r    5test_create_jupyterlite_contents_non_default_contentsrB    s     ,---#5577J$8L
d;;;;0  &(+X	
 

 &((	 	 	 	 r;   z
sphinx_gallery_conf = {
    'backreferences_dir' : os.path.join('modules', 'gen'),
    'examples_dirs': 'src',
    'gallery_dirs': ['ex'],
}c                     t          j        d           |                                 }t          |d           t	          |j        d                                          rJ dS )zETest JupyterLite contents creation without jupyterlite_sphinx loaded.r8  Nr9  r;  )r   r=  r%   r   r   r   r   r+   r,   s     r    Btest_create_jupyterlite_contents_without_jupyterlite_sphinx_loadedrE    sf     ,---#5577J
d;;;;J%'=>>EEGGGGGGGr;   z
extensions += ['jupyterlite_sphinx']

sphinx_gallery_conf = {
    'backreferences_dir' : os.path.join('modules', 'gen'),
    'examples_dirs': 'src',
    'gallery_dirs': ['ex'],
    'jupyterlite': None,
}c                     t          j        d           |                                 }t          |d           t	          |j        d                                          rJ dS )zyTest JupyterLite contents created with jupyterlite_sphinx loaded but disabled.

    JupyterLite disabled via config.
    r8  Nr9  r;  )r   r=  r%   r   r   rx   r   rD  s     r    Etest_create_jupyterlite_contents_with_jupyterlite_disabled_via_configrG    sf    $ ,---#5577J
d;;;;J%'=>>EEGGGGGGGr;   a`  
extensions += ['jupyterlite_sphinx']

def notebook_modification_function(notebook_content, notebook_filename):
    source = f'JupyterLite-specific change for {notebook_filename}'
    markdown_cell = {
        'cell_type': 'markdown',
        'metadata': {},
        'source': source
    }
    notebook_content['cells'] = [markdown_cell] + notebook_content['cells']


sphinx_gallery_conf = {
    'backreferences_dir' : os.path.join('modules', 'gen'),
    'examples_dirs': 'src',
    'gallery_dirs': ['ex'],
    'jupyterlite': {
        'notebook_modification_function': notebook_modification_function
    }
}c                    t          j        d           |                                 }|j        j        }t          |d            dD ]}t          |j        d|d         d         |dz             }|                                sJ 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 d S )Nr8  r9  r   r;  r   r   r   cells	cell_typemarkdownz JupyterLite-specific change for source)r   r=  r%   r&   r   r   r   r   r   ry   jsonload)r+   r,   r   r   notebook_filenamefnotebook_content
first_cells           r    2test_create_jupyterlite_contents_with_modificationrS    si   0 ,---#5577J$8L
d;;;;0 
 
 "(+X	
 
 !'')))))#$$ 	,#y||	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, &g.q1
+&*4444B/@BB(#$ $ $ $ $
 
s   B66B:	=B:	r.  )\__doc__r   rM  r`   rz   pathlibr   r   sphinx.applicationr   sphinx.configr   sphinx.errorsr   r   r   sphinx_gallery.gen_galleryr	   r
   r   r   r   r   sphinx_gallery.utilsr   r   r   r   r   r!   r/   r:   r   r   rC   rF   parametrizer   rP   rT   rV   r[   rb   rl   rn   r   r   r   _builtin_sortersr3   #_params_for_testing_builtin_sorters_template_confrg   _subsection_explicit_order_subsection_explicit_order_list_both_custom_fqn_within_subsection_custom_fqn_custom_func_within_subsection_custom_func-_subsection_fqn_within_subsection_custom_funcr2   r   r   r   add_rstr   r   r   r   r   r   r  r  r  r  r  r  r  r  r   r(  r*  r,  r/  r1  r3  r5  r?  rB  rE  rG  rS  r   r;   r    <module>rg     s   / .   				 				        % % % % % % ) ) ) ) ) ) D D D D D D D D D D            K J J J J J           9 9 9.3 3 3= = =    
 
 
    W W W 5!+&&G '  		
 	
 	
 	.&+&&G '  		
 	
 	
 */ /+ */
 8!+&&J '  		
 	
 	
 	,.+&&R '  		
 	
 	
 */ /+ */
 +&&/V&WW		
 	
 	
 	#+&&/P&QQ		
 	
 	
 "/ /# "/9 9 9    	 	 	' ' ',' ' '.# # # #@& " 4
$
	   
' 
' )..00
' 
' 
' # $[11!!B[ < "   2    #)+"6"6!!L Q "   #7 # #  ;''!!K O "   (    !' 4 4!! O "   !5 ! ! " "(!5!5!! @ "   "6 " "  170D0D!!K @ "   1E 1 1 - D1,	
 	
 	
 	D(1	
 	
 	
 	D5/	
 	
 	
 	 DI"	
 	
 	
 	D60	
 	
 	
 	 DQ?	
 	
 	
K.Z 
-[. .1 1dF Fe1 1dF%- %- %-P- - -8     /*** * +* * 	     (      8    * * *    	F 	F 	F    = = =    6 6 6   	 	& &	 	& $+&&O '  	
 	
 	
 	#+&&N '  	
 	
 	
 "F F# "F    F F F    L L L    B B B     
   . .  .     
   M M  M       
 
 
   + + 
 
&+     
   ! !  !     
   	! 	!  "	!F F F
P P P    F F F    F F F   	 	 	 	"   
 
 
 
"    H H H   
 
H H
 
H    .
 
/ .
 
 
r;   