
    O&iE                        d 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mZmZ ddlZddlmZ ddlmZmZ d	d
gZd Z ej        d          dee         fd            Z G d d          Zej        de	dededededeeef         fd            Zej        de	defd            Z ej        d          dedeeef         de
dedeeddf         f
d            Z ej        d          dedefd            Z ej        d          dedefd            Z ej                    ded e	dee
ddf         fd!            Z ej        defd"            Z! ej        d#d$%          d.d&            Z"ej        deddfd'            Z# ej        d          d(e	dd)fd*            Z$ej        d+edd)fd,            Z%ej        d-             Z&dS )/zSphinx test fixtures for pytest    N)
namedtuple)StringIO)PIPE)AnyCallableDict	GeneratorOptionalTuple)util)SphinxTestApp#SphinxTestAppWrapperForSkipBuildingzsphinx(builder, testroot=None, freshenv=False, confoverrides=None, tags=None, docutilsconf=None, parallel=0): arguments to initialize the sphinx test application.z0test_params(shared_result=...): test parameters.c                 F    t           D ]}|                     d|           dS )zRegister custom markersmarkersN)DEFAULT_ENABLED_MARKERSaddinivalue_line)configmarkers     d/home/geonatureadmin/si_en_reseau/tutos/venv/lib/python3.11/site-packages/sphinx/testing/fixtures.pypytest_configurer      s4    ) 3 3	622223 3    session)scopereturnc                      d S N r   r   r   rootdirr      s    4r   c                   r    e Zd ZU i Zeeeeef         f         ed<   dededefdZ	dedeee
f         fdZdS )SharedResultcachekeyapp_r   c                     || j         v rd S |j                                        |j                                        d}|| j         |<   d S )Nstatuswarning)r!   _statusgetvalue_warning)selfr"   r#   datas       r   storezSharedResult.store&   sS    $*Fl++--}--//
 
 
3r   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)__name__
__module____qualname__r!   r   str__annotations__r   r   r-   r   r/   r   r   r   r    r    #   s         ')E4T#s(^#$))) M c    
3 
4X#6 
 
 
 
 
 
r   r    requesttest_paramsshared_resultsphinx_test_tempdirr   c                    i i }t          t          | j                            d                              D ];}t	          |j                  D ]
\  }}||<   |                    |j                   <fdt          	                                          D             }	|d         rSd|v rt          j        d          |d         |d<   |                    |d                   }
|                    |
           |                    dd          }||                    d|          z  x|d<   }|r1|                                s|d|z   z  }|                    |            t#          d	d
          |	|          S )zp
    Parameters 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>L   s    333E!H333r   r7   srcdirz:You can not specify shared_result and srcdir in same time.testrootrootztest-
app_paramszargs,kwargs)reversedlistnodeiter_markers	enumerateargsupdatekwargssortedkeyspytest	Exceptionr/   popgetexistscopytreer   )r5   r6   r7   r8   r   rK   infor=   arI   r/   rA   r@   testroot_pathr>   s                 @r   rC   rC   9   s    EF gl77AABBCC # #di(( 	 	DAqE!HHdk""""3333fUZZ\\22333D ?# v" $: ; ; ;&7x''O(DEEg zz*f--H 3fjj86T6T TTF8v  'v}} '7X#56v&&&2:lM224@@@r   c                     | j                             d          }|r|j        ni }ddi}|                    |           |d         r/t	          |d         t
                    st          j        d          |S )au  
    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   r7   Nz@You can only provide a string type of value for "shared_result" )rF   get_closest_markerrK   rJ   
isinstancer3   rN   rO   )r5   envrK   results       r   r6   r6   d   s     ,
)
)-
8
8C&SZZBFF MM& 7
6/3JC(P(P 7  6 7 7 	7Mr   functionrC   make_appc              #     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 )z9
    Provides the 'sphinx.application.Sphinx' object
    z# testroot:rA   rB   z
# builder:z	# srcdir:z	# outdir:z	# status:
z
# warning:r7   N)
printrQ   buildernamer@   outdirr(   r)   r*   r-   )r6   rC   r]   r7   rI   rK   r#   s          r   apprd   |   s      LD&8T$V$$D
JJJ	-J77888	,)***	+t{###	+t{###	+tdl33555666	,t}55777888?# @K8$?????@ @r   rd   c                     | j         S zJ
    Back-compatibility for testing with previous @with_app decorator
    )r(   rd   s    r   r&   r&      s    
 ;r   c                     | j         S rf   )r*   rg   s    r   r'   r'      s    
 <r   monkeypatchc              #       K   |                     dd            g t          j        dd         } fd}|V  |t          j        dd<   t                    D ]}|                                 dS )z
    Provides 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.
    zsphinx.application.abspathc                     | S r   r   )xs    r   <lambda>zmake_app.<locals>.<lambda>   s     r   Nc                     t                      t                      }}|                    d|           |                    d|           t          | i |}                    |           d         rt	          |          }|S )Nr&   r'   r7   )r   
setdefaultr   appendr   )rI   rK   r&   r'   r#   appsr6   s        r   makezmake_app.<locals>.make   s    "**hjj(F+++)W---!42622D' 	=6t<<Dr   )setattrsyspathrD   cleanup)r6   ri   syspathrr   r#   rq   s   `    @r   r]   r]      s       4kkBBBDhqqqkG      JJJCHQQQK   r   c                      t                      S r   )r    r   r   r   r7   r7      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t          t                     dS n# t
          $ r Y nw xY wt          j        d           dS )zt
    The test will be skipped when using 'if_graphviz_found' fixture and graphviz
    dot command is not found.
    graphviz_dot z-V)stdoutstderrNzgraphviz "dot" is not available)getattrr   
subprocessrunr   OSErrorrN   skip)rd   r   s     r   if_graphviz_foundr      s     3:~r::L 	NL$/TJJJJF	     K122222s   %A   
AAtmpdir_factoryz	util.pathc                 v    |                                  }t          j        |                                          S )z8
    Temporary directory wrapped with `path` class.
    )getbasetempr   ru   abspath)r   tmpdirs     r   r8   r8      s1    
 ''))F9V$$&&&r   r   c                 *    t          j        |           S )z
    Temporary directory wrapped with `path` class.
    This fixture is for back-compatibility with old test implementation.
    )r   ru   )r   s    r   tempdirr      s     9Vr   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)z
    Rollback 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)rE   rt   modulesrP   )
sysmodulesmodnames     r   rollback_sysmodulesr      s      )#+&&
CK(( 	) 	)Gj(((((	) 	)tCK(( 	) 	)Gj(((((	)s   A" "AB#)r   N)'__doc__r   rt   collectionsr   ior   r   typingr   r   r   r	   r
   r   rN   sphinx.testingr   sphinx.testing.utilr   r   r   r   fixturer3   r   r    rC   r6   rd   r&   r'   r]   r7   r}   r   r8   r   r   r   r   r   <module>r      s,   % %     



 " " " " " "             B B B B B B B B B B B B B B B B        R R R R R R R R	` 7 3 3 3 i   #    ! 
 
 
 
 
 
 
 
, 'A 'A$ 'A| 'A$''A25'A:?d
:K'A 'A 'A 'AT      . j!!!@T @uT4Z'8 @H @#@(1-t2K(L@ @ @ "!@( j!!! (    "! j!!! 8    "! $ S Yxt?S5T    6 |     h---   .- 3= 3T 3 3 3 3  i   ' ' ' ' ' ! ' C K     ) ) ) ) )r   