
    Fe                       d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZmZ ddlmZmZ dd	lmZ e
rdd
lmZ ddlmZ ddlmZ dZdddZddZ  G d dejB                        Z" G d d      Z#ddZ$y)zSphinx test suite utilities    )annotationsN)IOTYPE_CHECKINGAny)ElementTree)nodes)
directivesroles)applicationlocale)ModuleAnalyzer)StringIO)Path)Node)SphinxTestApp#SphinxTestAppWrapperForSkipBuildingc                @   |rt        |t              rt        | |d   fd|i| |dd  rft        |d   t              rt        | |d   fd|i| n?t        | t        j
                        s
J d|z         t        |       dk(  sJ d|t        |       fz         t        | d   |dd  fd|dz   i| nt        |t              rt        | t        t        j
                  f      s
J d|z         t        |       t        |      k(  sJ d|t        |       t        |      fz         t        |      D ]  \  }}|d	|z  z   }t        | |   |fd|i| ! nAt        |t              r| |k(  s,J d
|d|d|        t        | |      sJ d| d|d|        |rt        | t        j
                        s
J d|z         |j                         D ]S  \  }}|| vr,|j                  dd      x}| vrd| d|d| }	t        |	      | |   |k(  r?J d| d| d|d| |           y y )Nr   xpath   z%The node%s does not have any childrenz&The node%s has %d child nodes, not onez[0]z"The node%s does not have any itemsz%The node%s has %d child nodes, not %rz[%d]z	The node z is not z: zThe nodez is not subclass of z'The node%s does not have any attributes_-z does not have z attribute: [z	] is not )
isinstancelistassert_nodetupler   Elementlen	enumeratestritemsreplaceAssertionError)
nodeclsr   kwargsinodeclspathkeyvaluemsgs
             5/usr/lib/python3/dist-packages/sphinx/testing/util.pyr   r      s   
c4 c!f<E<V<12wc!fe,c!fDEDVD%dEMM: H?%GH:t9> V@E3t9CUUV>QQRPPPU#dT5==$9: =4u<=:t9C( W75#d)SQTX:VVW('n D
7vz)DGWCDCFCD S!3;N)E9HSG2dX NN;dC( H5'!5cWBthGH( $. 	>5=	>. !,,. 	JJC$;;sC00C=$UG?3'dXVC(--9% J5'3%y	DI=IJ%	J	     c                    t        j                  d      5  t        j                  dt               t	        j
                  |       cd d d        S # 1 sw Y   y xY w)NF)recordignore)category)warningscatch_warningsfilterwarningsDeprecationWarningr   parse)r)   s    r-   etree_parser8   C   sD    		 	 	. '3EF  &' ' 's   0AAc                       e Zd ZU dZded<   ded<   	 	 	 	 	 	 	 	 	 	 d		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
 fdZdddZddZdd fdZ xZ	S )r   z
    A subclass of :class:`Sphinx` that runs on the test root, with some
    better default values for the initialization parameters.
    r   _status_warningc                   |J |dz  | _         |	| j                   j                  |	d       ||dz  }|}|j                  |      }|j                  dd       |j                  d      }|j                  dd       |i }d}t        j
                  d d  | _        t        j                  j                         | _
        t        j                  j                         | _        t        t        j                         D ch c]  }|j#                  d	      r| c}| _        	 t&        | Q  ||||||||||||

       y c c}w # t*        $ r | j-                           w xY w)Nzdocutils.confutf8)encoding_buildT)parentsexist_okdoctreesFvisit_)parallel)docutils_conf_path
write_textjoinpathmkdirsysr)   _saved_pathr	   _directivescopy_saved_directivesr
   _roles_saved_rolesdirr   GenericNodeVisitor
startswith_saved_nodeclassessuper__init__	Exceptioncleanup)selfbuildernamesrcdirbuilddirfreshenvconfoverridesstatuswarningtagsdocutilsconfrD   confdiroutdir
doctreedirwarningiserrorv	__class__s                   r-   rU   zSphinxTestApp.__init__Q   sf    !!!"(?":###..|f.M(H"";/TD1&&z2
5 M88A;!+!7!7!<!<!>!LL--/.1%2J2J.K #>&'ll8&< $% #>	GVWfj(-%~th  P	#>  	LLN	s   ?D>"E Ec                   t         j                  j                          t        j                  j                          | j
                  t        j                  d d  t        j                  j                  dd        | j                  t        _        | j                  t        _        t!        t"        j$                        D ]c  }|j'                  d      s|| j(                  vs$t+        t"        j$                  d|dd  z          t+        t"        j$                  d|dd  z          e t-        j.                  t0              5  t3        j4                  | j6                         d d d        y # 1 sw Y   y xY w)Nautodoc_fodderrC      depart_)r   cacheclearr   translatorsrJ   rI   r)   modulespoprM   r	   rK   rO   r
   rN   rP   r   rQ   rR   rS   delattr
contextlibsuppressFileNotFoundErrorosremoverE   )rX   rB   methods      r-   rW   zSphinxTestApp.cleanup   s   ""$  "&&($/!%!7!7
((%223 	JF  *T44400(VABZ2GH00)fQRj2HI		J
   !23 	/IId--.	/ 	/ 	/s   < E%%E.c                d    d| j                   j                   d| j                  j                  dS )N<z buildername=>)rg   __name__buildername)rX   s    r-   __repr__zSphinxTestApp.__repr__   s-    4>>**+=9J9J8MQOOr.   c                n    | j                   j                  j                          t        |   ||       y N)env_pickled_doctree_cacherm   rT   build)rX   	force_all	filenamesrg   s      r-   r   zSphinxTestApp.build   s'    ''--/i+r.   )
htmlNNFNNNNNr   )rY   r    rZ   Path | Noner[   r   r\   boolr]   zdict | Noner^   	IO | Noner_   r   r`   list[str] | Nonera   z
str | NonerD   intreturnNone)F)rB   r   r   r   )r   r    )FN)r   r   r   r   r   r   )
r{   
__module____qualname____doc____annotations__rU   rW   r~   r   __classcell__)rg   s   @r-   r   r   I   s      "" $%) !!%#',, , 	,
 , #, , , , !, , 
,\/P, ,r.   r   c                  (    e Zd ZdZddZddZddZy)	r   z
    This class is a wrapper for SphinxTestApp to speed up the test by skipping
    `app.build` process if it is already built and there is even one output
    file.
    c                    || _         y r   )app)rX   app_s     r-   rU   z,SphinxTestAppWrapperForSkipBuilding.__init__   s	    r.   c                .    t        | j                  |      S r   )getattrr   )rX   r}   s     r-   __getattr__z/SphinxTestAppWrapperForSkipBuilding.__getattr__   s    txx&&r.   c                    t        j                  | j                  j                        s | j                  j                  |i | y y r   )ru   listdirr   rc   r   )rX   argsr&   s      r-   r   z)SphinxTestAppWrapperForSkipBuilding.build   s2    zz$((//*DHHNND+F+ +r.   N)r   r   r   r   )r}   r    r   r   )r   r   r&   r   r   r   )r{   r   r   r   rU   r   r    r.   r-   r   r      s    ',r.   r   c                0    t        j                  dd|       S )Nz.*?m )resub)texts    r-   strip_escseqr      s    66*b$''r.   )Nr   )
r$   r   r%   r   r   r    r&   r   r   r   )r)   r    r   r   )r   r    r   r    )%r   
__future__r   rr   ru   r   rI   r3   typingr   r   r   	xml.etreer   docutilsr   docutils.parsers.rstr	   r
   sphinxr   r   sphinx.pycoder   ior   pathlibr   docutils.nodesr   __all__r   r8   Sphinxr   r   r   r   r.   r-   <module>r      sp    ! "  	 	 
  ) ) !  2 & (#
@%JP'J,K&& J,Z, ,((r.   