o
    Ni)                     @  sJ  U d Z ddlmZ d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mZ dd	lmZmZ ddlZddlZddlZdd
lmZ ddlmZ erqddlmZmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# d0d1ddZ$d2d d!Z%G d"d# d#ej&j'Z(G d$d% d%e(Z)d3d&d'Z*d(ed)d*fiZ+d+e,d,< d4d.d/Z-dS )5zSphinx test suite utilities    )annotations)SphinxTestApp#SphinxTestAppWrapperForSkipBuildingN)StringIO)MappingProxyType)TYPE_CHECKING)nodes)
directivesroles)strip_colors)additional_nodes)MappingSequence)Path)Any)ElementTree)Node noder   clsr   xpathstrkwargsreturnNonec           
      K  s`  |rt |trdt| |d fd|i| |dd  rct |d tr/t| |d fd|i| nt | tjs=J d| dt| dksPJ d| dt|  dt| d |dd  fd|d i| nvt |trt | ttjB syJ d| d	t| t|ksJ d| dt|  d
t|t|D ]\}}|d| d }t| | |fd|i| qn)t |tr| |ksJ d|d|d| nt | |sJ d| d|d| |r,t | tjsJ d| d|	 D ]>\}}|| vr|
dd }| vrd| d|d| }	t|	| | |ks+J d| d| d|d| | qd S d S )Nr   r      zThe nodez does not have any childrenz has z child nodes, not onez[0]z does not have any itemsz child nodes, not []z	The node z is not z: z is not subclass of z does not have any attributes_-z does not have z attribute: z	] is not )
isinstancelistassert_nodetupler   Elementlen	enumerater   itemsreplaceAssertionError)
r   r   r   r   inodeclspathkeyvaluemsg r0   G/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/testing/util.pyr"       s`   


&


$


r"   r,   str | os.PathLike[str]r   c                 C  s   ddl m} || S )z,Parse a file into a (safe) XML element tree.r   )parse)defusedxml.ElementTreer3   )r,   	xml_parser0   r0   r1   etree_parseP   s   r6   c                      s   e Zd ZdZ														d4d5 fd!d"Zd6 fd#d$Zed7d&d'Zed7d(d)Zd8d9d+d,Z	d:d-d.Z
	d;d< fd2d3Z  ZS )=r   ah  A subclass of :class:`~sphinx.application.Sphinx` for tests.

    The constructor uses some better default values for the initialization
    parameters and supports arbitrary keywords stored in the :attr:`extras`
    read-only mapping.

    It is recommended to use::

        @pytest.mark.sphinx('html', testroot='root')
        def test(app):
            app = ...

    instead of::

        def test():
            app = SphinxTestApp('html', srcdir=srcdir)

    In the former case, the 'app' fixture takes care of setting the source
    directory, whereas in the latter, the user must provide it themselves.
    htmlNFr0   r   buildernamer   srcdirPath | Nonebuilddirfreshenvboolconfoverridesdict[str, Any] | NonestatusStringIO | NonewarningtagsSequence[str]docutils_conf
str | Noneparallelint	verbositywarningiserrorpdbexception_on_warningextrasr   r   r   c                  sl  || _ |d us	J |dkrd}d}nd}|d u r |rd nt }nt|ts0dt| }t||d u r<|r8d nt }nt|tsLdt| }t||d | _|	d ur]| jj|	dd	 |d u re|d
 }|}||}|jddd |d}|jddd |d u ri }t	j
 | _t|| _	 zt j|||||||||||||
||d W d S  ty   |    w )NTr   Fz-'status' must be an io.StringIO object, got: z.'warning' must be an io.StringIO object, got: zdocutils.confutf8)encoding_build)parentsexist_okdoctrees)
r>   r@   rB   r<   rJ   rC   rI   rG   rK   rL   )_builder_namer   r    type	TypeErrordocutils_conf_path
write_textjoinpathmkdirsysr,   copy_saved_pathr   rM   super__init__	Exceptioncleanup)selfr8   r9   r;   r<   r>   r@   rB   rC   rE   rG   rI   rJ   rK   rL   rM   quieterrconfdiroutdir
doctreedir	__class__r0   r1   r`   p   sj   





zSphinxTestApp.__init__c                   sF   d| j jv rnd| j v r| j jdkr| j jdd| j _t   d S )N
html_theme	alabasterbasic)config
_overridesrk   getr_   _init_builderrc   ri   r0   r1   rq      s
   zSphinxTestApp._init_builderr   c                 C     t | jtsJ | jS )z;The in-memory text I/O for the application status messages.)r    _statusr   rr   r0   r0   r1   r@         zSphinxTestApp.statusc                 C  rs   )z<The in-memory text I/O for the application warning messages.)r    _warningr   rr   r0   r0   r1   rB      ru   zSphinxTestApp.warningrT   c                 C  sR   | j tjd d < t  tt t| j	 W d    d S 1 s"w   Y  d S N)
r^   r\   r,   _clean_up_global_state
contextlibsuppressFileNotFoundErrorosremoverX   )rc   rT   r0   r0   r1   rb      s
   "zSphinxTestApp.cleanupc                 C  s   d| j j d| jdS )N<z buildername=>)rj   __name__rU   rr   r0   r0   r1   __repr__   s   zSphinxTestApp.__repr__	force_all	filenameslist[str] | Nonec                   s   | j j  t || d S rw   )env_pickled_doctree_cacheclearr_   buildrc   r   r   ri   r0   r1   r      s   zSphinxTestApp.build)r7   NNFNNNr0   Nr   r   FFF) r8   r   r9   r:   r;   r:   r<   r=   r>   r?   r@   rA   rB   rA   rC   rD   rE   rF   rG   rH   rI   rH   rJ   r=   rK   r=   rL   r=   rM   r   r   r   r   r   )r   r   )F)rT   r=   r   r   )r   r   FNr   r=   r   r   r   r   )r   
__module____qualname____doc__r`   rq   propertyr@   rB   rb   r   r   __classcell__r0   r0   ri   r1   r   W   s4    X

r   c                      s&   e Zd ZdZ	dd fd
dZ  ZS )r   zA wrapper for SphinxTestApp.

    This class is used to speed up the test by skipping ``app.build()``
    if it has already been built and there are any output files.
    FNr   r=   r   r   r   r   c                   s"   t | jst || d S d S rw   )r|   listdirrg   r_   r   r   ri   r0   r1   r      s   z)SphinxTestAppWrapperForSkipBuilding.buildr   r   )r   r   r   r   r   r   r0   r0   ri   r1   r      s    r   c                  C  s   t j  tj  tD ]*} ttjd| j	  ttjd| j	  ttj
d| j	  ttj
d| j	  qt  tjj  tjjj  d S )Nvisit_depart_)r	   _directivesr   r
   _rolesr   delattrr   GenericNodeVisitorr   SparseNodeVisitorsphinxlocaletranslatorspycodeModuleAnalyzercache)r   r0   r0   r1   rx      s   

rx   strip_escseqz sphinx.util.console.strip_colors)	   r   z+dict[str, tuple[Any, str, tuple[int, int]]]_DEPRECATED_OBJECTSnamec                 C  sN   | t vrdtd| }t|ddlm} t |  \}}}|t| ||d |S )Nzmodule z has no attribute r   )_deprecation_warning)r}   )r   r   AttributeErrorsphinx.deprecationr   )r   r/   r   deprecated_objectcanonical_namer}   r0   r0   r1   __getattr__  s   r   )Nr   )
r   r   r   r   r   r   r   r   r   r   )r,   r2   r   r   r   )r   r   r   r   ).r   
__future__r   __all__ry   r|   r\   ior   typesr   typingr   docutilsr   docutils.parsers.rstr	   r
   sphinx.applicationr   sphinx.localesphinx.pycodesphinx.util.consoler   sphinx.util.docutilsr   collections.abcr   r   pathlibr   r   xml.etree.ElementTreer   docutils.nodesr   r"   r6   applicationSphinxr   r   rx   r   __annotations__r   r0   r0   r0   r1   <module>   s>    
0 

