
    -Ph                       d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlZddlmZmZ erddlmZmZ dd	lmZ dd
l
mZ ddgZd;dZ ej        d          d<d            Z G d d          Zej        d=d!            Z ed d"          Zej        d>d#            Zej        d?d(            Zej        d@d,            Zej        d@d-            Z ej        dAd/            Z!ej        dBd0            Z" ej        d1d23          dCd4            Z#ej        dDd5            Z$ ej        d          dEd8            Z%ej        dFd:            Z&dS )GzSphinx test fixtures for pytest    )annotationsN)
namedtuple)StringIO)TYPE_CHECKING)SphinxTestApp#SphinxTestAppWrapperForSkipBuilding)CallableIterator)Path)Anyzsphinx(buildername="html", *, testroot="root", srcdir=None, confoverrides=None, freshenv=False, warningiserror=False, tags=None, verbosity=0, parallel=0, builddir=None, docutils_conf=None): arguments to initialize the sphinx test application.z0test_params(shared_result=...): test parameters.configpytest.ConfigreturnNonec                F    t           D ]}|                     d|           dS )zRegister custom markersmarkersN)DEFAULT_ENABLED_MARKERSaddinivalue_line)r   markers     W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/testing/fixtures.pypytest_configurer   &   s4    ) 3 3	622223 3    session)scopePath | Nonec                     d S N r   r   r   rootdirr   ,   s    4r   c                  .    e Zd ZU i Zded<   dd	ZddZdS )SharedResultzdict[str, dict[str, str]]cachekeystrapp_r   r   r   c                    || j         v rd S |j                                        |j                                        d}|| j         |<   d S )Nstatuswarning)r"   r(   getvaluer)   )selfr#   r%   datas       r   storezSharedResult.store4   sS    $*Fk**,,|,,..
 
 
3r   dict[str, StringIO]c                    || j         vri S | j         |         }t          |d                   t          |d                   dS )Nr(   r)   r'   )r"   r   )r+   r#   r,   s      r   restorezSharedResult.restore=   sL    dj  Iz#tH~..Y00
 
 	
r   N)r#   r$   r%   r   r   r   )r#   r$   r   r.   )__name__
__module____qualname__r"   __annotations__r-   r0   r   r   r   r!   r!   1   sO         ')E))))   
 
 
 
 
 
r   r!   requestr   test_paramsdict[str, Any]shared_resultsphinx_test_tempdirr   r   _app_paramsc                n   i i }t          t          | j                            d                              D ]@}t	          t          |j                            z  |                    |j                   Afdt          
                                          D             }|d         rUd|v rd}t          j        |           |d         |d<   |                    |d                   }	|                    |	           |                    dd          }
||                    d|
          z  x|d<   }ddh                    |           }|;|d
|
 z  }|r,|                                rt%          j        ||d           n||d<   |                    d|dz             t+          ||          S )zkParameters that are specified by 'pytest.mark.sphinx' for
    sphinx.application.Sphinx initialization
    sphinxc                     g | ]
}|         S r   r   ).0ipargss     r   
<listcomp>zapp_params.<locals>.<listcomp>\   s    333E!H333r   r8   srcdirz:You can not specify shared_result and srcdir in same time.testrootrootcopy_test_rootNztest-T)dirs_exist_okbuilddir_build)reversedlistnodeiter_markersdict	enumerateargsupdatekwargssortedkeyspytestfailr0   popget
isdisjointis_dirshutilcopytree
setdefaultr:   )r5   r6   r8   r9   r   rQ   inforO   msgr0   	test_rootrB   rE   test_root_pathr@   s                 @r   
app_paramsra   G   s    EF gl77AABBCC # #i	**+++dk""""3333fUZZ\\22333D ?# vNCK&7x''O(DEEg 

:v..I 3fjj96U6U UUF8v"$45@@HHHN  #69#6#66 	.$$&& LdKKKK-F8 j&8"3444tV$$$r   zargs,kwargsc                    | j                             d          }|r|j        ni }ddi}|                    |           |d         r1t	          |d         t
                    sd}t          j        |          |S )ap  Test parameters that are specified by 'pytest.mark.test_params'

    :param Union[str] shared_result:
       If the value is provided, app._status and app._warning objects will be
       shared in the parametrized test functions and/or test functions that
       have same 'shared_result' value.
       **NOTE**: You can not specify both shared_result and srcdir.
    r6   r8   Nz?You can only provide a string type of value for "shared_result")rK   get_closest_markerrQ   rP   
isinstancer$   rT   	Exception)r5   envrQ   resultr^   s        r   r6   r6      s     ,
)
)-
8
8C&SZZBFF MM&o $z&2I3'O'O $Os###Mr   ra   make_appCallable[[], SphinxTestApp]Iterator[SphinxTestApp]c              #    K   |\  }} ||i |}|V  t          d|                    dd                     t          d|j        j                   t          d|j                   t          d|j                   t          dd|j                                        z              t          d	d|j                                        z              | d
         r|	                    | d
         |           dS dS )z/Provides the 'sphinx.application.Sphinx' objectz# testroot:rC   rD   z
# builder:z	# srcdir:z	# outdir:z	# status:
z
# warning:r8   N)
printrW   buildernamerB   outdirr(   r*   r)   r-   )r6   ra   rh   r8   rO   rQ   r%   s          r   apprq      s      LD&8T$V$$D
JJJ	-J77888	,)***	+t{###	+t{###	+tdk22444555	,t|44666777?# @K8$?????@ @r   rq   r   r   c                    | j         S z@Back-compatibility for testing with previous @with_app decorator)r(   rq   s    r   r(   r(      s     :r   c                    | j         S rs   )r)   rt   s    r   r)   r)      s     ;r   %Iterator[Callable[[], SphinxTestApp]]c              #      K   g t           j                                        }d fd}|V  |t           j        dd<   t                    D ]}|                                 dS )	zProvides make_app function to initialize SphinxTestApp instance.
    if you want to initialize 'app' in your test function. please use this
    instead of using SphinxTestApp class directory.
    rO   r   rQ   r   r   c                    t                      t                      }}|                    d|           |                    d|           d         rt          | i |}nt          | i |}                    |           |S )Nr(   r)   r8   )r   r\   r   r   append)rO   rQ   r(   r)   r%   appsr6   s        r   makezmake_app.<locals>.make   s    "**hjj(F+++)W---' 	26GGGDD $1&11DDr   N)rO   r   rQ   r   r   r   )syspathcopyrI   cleanup)r6   syspathr{   r%   rz   s   `   @r   rh   rh      s       DhmmooG
 
 
 
 
 
 
 JJJCHQQQK   r   c                     t                      S r   )r!   r   r   r   r8   r8      s    >>r   moduleT)r   autousec                 B    t           j                                         d S r   )r!   r"   clearr   r   r   _shared_result_cacher      s    r   c                    t          | j        dd          }	 |rt          j        |dgdd           dS n# t          $ r Y nw xY wt          j        d           dS )	zoThe test will be skipped when using 'if_graphviz_found' fixture and graphviz
    dot command is not found.
    graphviz_dot z-VTF)capture_outputcheckNzgraphviz "dot" is not available)getattrr   
subprocessrunOSErrorrT   skip)rq   r   s     r   if_graphviz_foundr      s    
 3:~r::L 	NL$/ERRRRF	     K122222s   6 
AAtmp_path_factorypytest.TempPathFactoryc                *    |                                  S )zTemporary directory.)getbasetemp)r   s    r   r9   r9      s     '')))r   Iterator[None]c               #  L  K   t          t          j                  } 	 dV  t          t          j                  D ]%}|| vrt          j                            |           &dS # t          t          j                  D ]%}|| vrt          j                            |           &w xY w)zRollback sys.modules to its value before testing to unload modules
    during tests.

    For example, used in test_ext_autosummary.py to permit unloading the
    target module to clear its cache.
    N)rJ   r|   modulesrV   )
sysmodulesmodnames     r   rollback_sysmodulesr      s       ck""J)CK(( 	) 	)Gj(((((	) 	)tCK(( 	) 	)Gj(((((	)s   A" "AB#)r   r   r   r   )r   r   )r5   r   r6   r7   r8   r!   r9   r   r   r   r   r:   )r5   r   r   r7   )
r6   r7   ra   r:   rh   ri   r8   r!   r   rj   )rq   r   r   r   )r6   r7   r   rv   )r   r!   )r   r   )rq   r   r   r   )r   r   r   r   )r   r   )'__doc__
__future__r   rZ   r   r|   collectionsr   ior   typingr   rT   sphinx.testing.utilr   r   collections.abcr	   r
   pathlibr   r   r   r   fixturer   r!   ra   r:   r6   rq   r(   r)   rh   r8   r   r   r9   r   r   r   r   <module>r      s   % % " " " " " "      



 " " " " " "                    R R R R R R R R 22222222	B 7 "3 3 3 3 i      ! 
 
 
 
 
 
 
 
, 1% 1% 1% 1%h j66    , @ @ @ @,    
    
    6     h---   .- 3 3 3 3  i   * * * ! *
 ) ) ) ) ) )r   