
    -Ph!                        d Z ddlZddlmZ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Zej                            dg d	          d
             Zd Zej                            dddg          d             Zd Z eddddd          Zej                            ddddefdddefdddefddddefddd d!g	g d"#          d$             ZdS )%z Testing the rst files generator.    N)	MagicMockpatch)ExtensionError)_sanitize_rst)Blocksplit_code_and_text_blocksa)  
.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="{0}">

.. only:: html

  .. image:: /fake_dir/images/thumb/sphx_glr_test_file_thumb.png
    :alt:

  :ref:`sphx_glr_fake_dir_test_file.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">test title</div>
    </div>

{1}zcontent, tooltip, is_backref))<"test">z&lt;&quot;test&quot;&gt;F)test formattingr
   T)z?1 :class:`~a.b`. 2 :class:`a.b` 3 :ref:`whatever <better name>`z1 b. 2 a.b 3 better nameF)z"use :meth:`mne.io.Raw.plot_psd` tozuse mne.io.Raw.plot_psd toF)z<`this` and ``that``; and `these things` and ``those things``z0this and that; and these things and those thingsF)z$See `.MyClass` and `~.MyClass.close`zSee MyClass and closeFc           	      H   t          j        t          d          5  t          j        ddddd          }ddd           n# 1 swxY w Y   t          |           } d	}t          j        ddd| ||d
          }|rd}nd}t                              ||          }||k    sJ dS )z7Test if the thumbnail div generates the correct string.zinternal Sphinx-Gallery thumb)matchfake_dir ztest_file.pyr	   z	<"title">Nz
test titleF)
is_backrefcheckz>
.. only:: not html

 * :ref:`sphx_glr_fake_dir_test_file.py`
)pytestraisesr   sg_thumbnail_divr   	REFERENCEformat)contenttooltipr   html_divtitleextra	references          h/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx_gallery/tests/test_backreferences.pytest_thumbnail_divr   #   s   8 
~-L	M	M	M 
 
$NJ
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G$$GE 
  H     %00Iy      s   AAAc                     ddddddgddddddgddddddgddddddgd	d
d
dddgddd
dddgd}t          |           \  }}t          j                    }t          j        ||          }||k    sJ dS )zTest name identification.joinzos.pathFnamemodulemodule_shortis_classis_explicitidentify_nameszsphinx_gallery.back_referencesfigurezmatplotlib.pyplot
DummyClasszsphinx_gallery._dummyNestedDummyClasszsphinx_gallery._dummy.nested)zos.path.joinzbr.identify_namesr'   z
plt.figurer)   r*   N)r   r   _make_ref_regexr'   )unicode_samplegallery_confexpected_script_blocks	ref_regexress          r   test_identify_namesr3   Z   s   
 # )!$ 
 ): @!$ 
 ): @!$ 
 !- 3!$ 
 %1 7!$ 
 +8 7!$ 
e; ;Hx 2.AAA}"$$I

M9
5
5Cs??????    )mockshort_module)sameA)diffA.Bc                    | dk    rt                      x}}nt                      }t                      }t          j        t          j        ||d          5  t          j        dd          }t          j        dd          }||cxk    r|k    sn J |j        `t          j        dd          }|J 	 ddd           dS # 1 swxY w Y   dS )z?Check `_get_short_module_name` correctly finds shortest module.r7   )r8   r:   r:   CzC.DN)	r   r   dictsysmodulesr   _get_short_module_namer<   D)r5   r6   
mock_mod_1
mock_mod_2	short_modshort_mod_with_attrshort_mod_no_attrs          r   test_get_short_module_namerG      s'    v~~"+++-
ZZ[[
[[

 
CKz*!E!E	F	F ) )-eS99	 7uEE/????<?????? LN5eUCC (((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )s   AC  CCc                 $   d}ddddddgddddddgdd	d	dddgd
}|                      d          }|                    |d           t          |j                  \  }}t	          j                    }t	          j        ||          }||k    sJ dS )z"Test implicit name identification.s   
'''
Title
-----

This is an example.
'''
# -*- coding: utf-8 -*-
# ß
from a.b import c
import d as e
import h.i
print(c)
e.HelloWorld().f.g
h.i.j()
cza.bFr!   
HelloWorlddjzh.i)rI   ze.HelloWorldzh.i.jzidentify_names.pywbN)r    writer   strpathr   r+   r'   )	tmpdirr-   code_strr.   fnamer/   r0   r1   r2   s	            r   test_identify_names_implicitrS      s    H&  %!$ 
 % #!$ 
  %!$ 
' H< KK+,,E	KK$1%-@@A}"$$I

M9
5
5Cs??????r4   mnFT)r#   r$   r"   r%   r&   ztext, default_role, ref, cobjz:func:`m.n`zm.nz:func:`~m.n`objz:func:`Title <m.n>`)z:func:`!m.n` or `!t <~m.n>`NNN`m.n`)rW   NNN)z
:ref:`m.n`NNN)rW   refNN)z``literal``rV   NN)	regularzshow only last componentz
with titlezno link for !zdefault_role objzno default_roleznon-python roleznon-python default_roleliteral)idsc                     |dn|}t          d| d          g}|r||gini }t          j        |          }t          j        ||          }||k    sJ dS )z"Test explicit name identification.Nr   text   )r   r   r+   r'   )	r]   default_rolerX   cobjr-   r0   r.   r1   actuals	            r   test_identify_names_explicitrb      ss    > &-22<L64++,M #+dV}}H"<00I}i88Fvr4   )__doc__r>   unittest.mockr   r   r   sphinx.errorsr   sphinx_gallery.backreferencesbackreferencesr   sphinx_gallery.gen_rstr   sphinx_gallery.py_source_parserr   r   r   markparametrizer   r3   rG   rS   r=   r`   rb    r4   r   <module>rm      s   ' & 



 * * * * * * * *  ( ( ( ( ( ( * * * * * * 0 0 0 0 0 0 M M M M M M M M	( "   4! !5 4!:A A AH 1M?3STT) ) UT),7 7 7t t3SsUPTUUU #	eT*	t,	eT29	%%#($*

	 
	 
	   : ; :  r4   