
    -Ph^                        d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
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mZmZ ddlmZ ddlmZ dZdZdZddZe
j        d             Z e
j        d             Z!e
j        d             Z"e
j        dd            Z# e
j        d          d             Z$ e
j        d          d             Z%e
j        d             Z&e
j        d             Z' G d d          Z(e
j        d             Z)dS ) zPytest fixtures.    N)contextmanager)StringIO)Path)Mock)Sphinx)ExtensionError)docutils_namespace)docs_resolvgen_gallerygen_rstpy_source_parser)_import_matplotlib)
_get_imagezp
=============
Own index.rst
=============

Own index.rst file.

.. toctree::

    plot_1
    plot_2
    plot_3
z$"""
Header
======

Text.
"""

a = 1
z+
Gallery header
==============

Some text.
c                 <    dt           j         dt           j         dS )z)Add information to the pytest run header.z	Sphinx:  z ())sphinx__version____file__)configstartdirs     ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx_gallery/tests/conftest.pypytest_report_headerr   3   s     ?v)??V_????    c                 (   t          t          t          ddid          g           }t          j        i |          }t          j        |t          |                      |                    t          |           t          |                      |S )z+Set up a test sphinx-gallery configuration.z.rstN)source_suffixdefault_role)specr   
extensions)app)examples_dirgallery_dir)r   r   dictr   _fill_gallery_conf_defaults#_update_gallery_conf_builder_initedstrupdate)tmpdirr   gallery_confs      r   r(   r(   8   s     64.tDDD  C
 :23GGGL3L#f++NNNS[[c&kkJJJr   c              #   .  K    t          t          d                      }|                     t          d|           |                     t          d|           |                     t
          d|           |                     t          d|           |V  d S )NFakeSphinxApp)r   namelogger)r   r   setattrr
   r   r   r   )monkeypatchr   s     r   log_collectorr/   F   s      
1$F
1
1
1
3
3CXs333Xs333((C8883///
IIIIIr   c                 j    d}|                      d          }|                    |d           |j        S )zCReturn temporary python source file with Unicode in various places.s+  # -*- coding: utf-8 -*-
'''
Únicode in header
=================

Uñicode in description
'''

# Code source: Óscar Nájera
# License: BSD 3 clause

import os
path = os.path.join('a','b')

a = 'heiß'  # Unicode string

import sphinx_gallery.back_references as br
br.identify_names

from sphinx_gallery.back_references import identify_names
identify_names

from sphinx_gallery._dummy import DummyClass
DummyClass().prop

from sphinx_gallery._dummy.nested import NestedDummyClass
NestedDummyClass().prop

import matplotlib.pyplot as plt
_ = plt.figure()

zunicode_sample.pywb)joinwritestrpath)r'   code_strfnames      r   unicode_sampler7   P   s:    HB KK+,,E	KK$=r   sessionc                    ddl m} |                                \  }}|                    t	          d                     	 |                    t          |                     d                               n.# t          $ r!}t          j
        d|            Y d}~nd}~ww xY w|                    |           dS # |                    |           w xY w)z0Raise SkipTest if JPEG support is not available.r   N
   ztestplot.jpgzMatplotlib jpeg saving failed: )matplotlib.pyplotpyplotsubplotsplotrangesavefigr%   r2   	Exceptionpytestskipclose)r'   req_mplscopepltfigaxexps          r   req_mpl_jpgrK   y   s    
 $#####llnnGCGGE"IICN33445555 = = =;c;;<<<<<<<<= 			#		#s0   5A7 6B< 7
B"BB< B""B< <C)rF   c                  |    	 t                       d S # t          t          f$ r t          j        d           Y d S w xY w)NzTest requires matplotlib)r   ImportError
ValueErrorrB   rC    r   r   rE   rE      sS    0$ 0 0 0.//////0s    %;;c                  n    	 t                       d S # t          $ r t          j        d           Y d S w xY w)NzTest requires pillow)r   r   rB   rC   rO   r   r   req_pilrQ      sI    , , , ,*++++++,s    44c                     	 | j                             d          }n*# t          $ r | j                             d          }Y nw xY w|r|j        ni }ddgd}|                    |           |S )Nadd_conf zsphinx_gallery.gen_gallery)contentr   )nodeget_closest_markerAttributeError
get_markerkwargsr&   )requestenvrZ   results       r   	conf_filer^      s    2l--j99 2 2 2l%%j112&SZZBF34 F MM&M    $AAc                     	 | j                             d          }n*# t          $ r | j                             d          }Y nw xY w|r|j        d         nd}|S )Nadd_rstfilerT   )rV   rW   rX   rY   rZ   )r[   r\   rb   s      r   rst_filerc      sm    1l--i88 1 1 1l%%i001!$,3:f"DKr_   c                   :    e Zd ZdZd Zd Zed             Zd ZdS )SphinxAppWrappera#  Wrapper for sphinx.application.Application.

    This allows control over when the sphinx application is initialized, since
    part of the sphinx-gallery build is done in
    sphinx.application.Application.__init__ and the remainder is done in
    sphinx.application.Application.build.
    c                 Z    || _         || _        || _        || _        || _        || _        d S N)srcdirconfdiroutdir
doctreedirbuildernamerZ   )selfrh   ri   rj   rk   rl   rZ   s          r   __init__zSphinxAppWrapper.__init__   s1    $&r   c                 `    |                                  5 }	 ddd           n# 1 swxY w Y   |S )zCreate Sphinx app.N)create_sphinx_app_contextrm   r   s     r   create_sphinx_appz"SphinxAppWrapper.create_sphinx_app   sp     ++-- 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	
s   #''c              #      K   t                      5  t          | j        | j        | j        | j        | j        fi | j        }|V  ddd           dS # 1 swxY w Y   dS )z!Create Sphinx app inside context.N)r	   r   rh   ri   rj   rk   rl   rZ   rq   s     r   rp   z*SphinxAppWrapper.create_sphinx_app_context   s        !! 		 		   + C III		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		s   4AAAc                 x    |                                  5 } |j        |i | ddd           n# 1 swxY w Y   |S )zBuild Sphinx app.N)rp   build)rm   argsrZ   r   s       r   build_sphinx_appz!SphinxAppWrapper.build_sphinx_app   s    ++-- 	'CIt&v&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 
s   /33N)	__name__
__module____qualname____doc__rn   rr   r   rp   rw   rO   r   r   re   re      sf                ^    r   re   c           
      p   t          t                    j        dz  }t          |           dz  }t          j        ||           t          j        |dz  t          |           dz             |dk    rIt          |dz  dz  d          5 }|                    t                     d d d            n# 1 swxY w Y   n|rt          |dz  d          5 }|                    |           d d d            n# 1 swxY w Y   d	|v r|dz  d
z  dz  }|                    d           t          |dz  d          5 }|                    t                     d d d            n# 1 swxY w Y   t          |dz  d          5 }|                    t                     d d d            n# 1 swxY w Y   d|d         d}	t          |dz  d          5 }
|
                    |	|d         z              d d d            n# 1 swxY w Y   t          |||dz  |dz  dz  dt                      t                                S )N	testconfsconfig_testsrcexampleszown index.rstz	index.rstwzminigallery_test.rstzsub_folder/sub_sub_folder
sub_foldersub_sub_folderT)parentszplot_nested.pyzGALLERY_HEADER.rstz.
import os
import sphinx_gallery
extensions = r   z
exclude_patterns = ['_build', 'src']
source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = 'Sphinx-Gallery <Tests>'


zconf.pyrU   _buildtoctreehtml)warningstatus)r   r   parentshutilcopytreeopenr3   	INDEX_RSTmkdir	NESTED_PYGALLERY_HEADERre   r   )r'   r^   rc   rE   rQ   _fixturedirrh   rb   dir_pathbase_configconffiles              r   sphinx_app_wrapperr      sy   x..'+5K&\\M)F
OK((( O[5(DLL:,EGGG?""6E>K/#66 	"$JJy!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"	 
+622S99 	!TJJx   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! '(22~47GGHNN4N(((x"22S99 &T

9%%%& & & & & & & & & & & & & & &x"66== +

>***+ + + + + + + + + + + + + + +	 %	 	 	K 
v	!C	(	( ;H{Yy%99:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 	(		(	Y	&

zz   sZ   B//B36B3C22C69C65EE #E :F!!F%(F%G66G:=G:rg   )r8   )*r{   r   
contextlibr   ior   pathlibr   unittest.mockr   rB   r   sphinx.applicationr   sphinx.errorsr   sphinx.util.docutilsr	   sphinx_galleryr
   r   r   r   sphinx_gallery.scrapersr   sphinx_gallery.utilsr   r   r   r   r   fixturer(   r/   r7   rK   rE   rQ   r^   rc   re   r   rO   r   r   <module>r      ss      % % % % % %                     % % % % % % ( ( ( ( ( ( 3 3 3 3 3 3 N N N N N N N N N N N N 6 6 6 6 6 6 + + + + + +		@ @ @ @
 
 
 
    % % %P      i   0 0 ! 0 i   , , ! ,      , , , , , , , ,^ + + + + +r   