B
    \Y                 @   sH  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
Z
ddlmZmZ ddlmZ e
jd	d
dd Ze
jdd Ze
jdd Ze
jdd
dd Ze
jdd
dd Ze
jdd
dd Ze
 dd ZG dd deZe
jdd Ze
jddd d!d" Ze
jd#d$ Ze
jd	d
d%d& Ze
jd'd( ZdS ))z
    sphinx.testing.fixtures
    ~~~~~~~~~~~~~~~~~~~~~~~

    Sphinx test fixtures for pytest

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    )print_functionN)
namedtuple)
gettempdir)StringIOstring_types   )utilZsession)scopec               C   s   d S )N r
   r
   r
   6lib/python3.7/site-packages/sphinx/testing/fixtures.pyrootdir   s    r   c                s*  t | jdr| jd}n| jd}i  i }|dk	rxx@tt|D ]0}xt|jD ]\}}	|	 |< qTW ||j	 qDW  fddt
  D }
|d rd|krtd|d |d< ||d }|| |d	d
}||d|  |d< }|r| s|d|  }|| tdd|
|S )zo
    parameters that is specified by 'pytest.mark.sphinx' for
    sphinx.application.Sphinx initialization
    iter_markersZsphinxNc                s   g | ]} | qS r
   r
   ).0i)pargsr
   r   
<listcomp>;   s    zapp_params.<locals>.<listcomp>shared_resultsrcdirz9You can not spcify shared_result and srcdir in same time.testrootrootztest-
app_paramszargs,kwargs)hasattrnoder   
get_markerreversedlist	enumerateargsupdatekwargssortedkeyspytest	ExceptionrestorepopgetexistsZcopytreer   )requesttest_paramsr   sphinx_test_tempdirr   Zmarkersr   infor   ar   r$   r   r   Ztestroot_pathr
   )r   r   r   #   s.    



r   c             C   sj   t | jdr| jd}n| jd}|r0|jni }ddi}|| |d rft|d tsft	d|S )a|  
    test parameters that is 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 shared_result and srcdir in same time.
    get_closest_markerr)   r   Nz@You can only provide a string type of value for "shared_result" )
r   r   r-   r   r   r   
isinstancer   r"   r#   )r(   envr   resultr
   r
   r   r)   T   s    

r)   Zfunctionc             c   s   |\}}|||}|V  t d|dd t d|jj t d|j t d|j t dd|j   t d	d|j   | d
 r|	| d
 | dS )z3
    provides sphinx.application.Sphinx object
    z# testroot:r   r   z
# builder:z	# srcdir:z	# outdir:z	# status:
z
# warning:r   N)
printr&   Zbuildernamer   Zoutdir_statusgetvalue_warningstore)r)   r   make_appr   r   r   app_r
   r
   r   appp   s    
r:   c             C   s   | j S )z>
    compat for testing with previous @with_app decorator
    )r4   )r:   r
   r
   r   status   s    r;   c             C   s   | j S )z>
    compat for testing with previous @with_app decorator
    )r6   )r:   r
   r
   r   warning   s    r<   c             #   sb   | ddd  g  tjdd } fdd}|V  |tjdd< xt D ]}|  qNW 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   s   | S )Nr
   )xr
   r
   r   <lambda>   s    zmake_app.<locals>.<lambda>Nc                 sR   t  t   }}|d| |d| tj| |} | d rNt|}|S )Nr;   r<   r   )r   
setdefaultr   ZSphinxTestAppappendZ#SphinxTestAppWrapperForSkipBuilding)r   r   r;   r<   r9   )appsr)   r
   r   make   s    

zmake_app.<locals>.make)setattrsyspathr   Zcleanup)r)   ZmonkeypatchZsyspathrB   r9   r
   )rA   r)   r   r8      s    	r8   c               @   s    e Zd Zi Zdd Zdd ZdS )SharedResultc             C   s2   || j krd S |j |j d}|| j |< d S )N)r;   r<   )cacher4   r5   r6   )selfkeyr9   datar
   r
   r   r7      s
    
zSharedResult.storec             C   s2   || j kri S | j | }t|d t|d dS )Nr;   r<   )r;   r<   )rG   r   )rH   rI   rJ   r
   r
   r   r$      s
    


zSharedResult.restoreN)__name__
__module____qualname__rG   r7   r$   r
   r
   r
   r   rF      s   	rF   c               C   s   t  S )N)rF   r
   r
   r
   r   r      s    r   moduleT)r	   Zautousec               C   s   t j  d S )N)rF   rG   clearr
   r
   r
   r   _shared_result_cache   s    rP   c             C   s^   t | jdd}y,|r8tj|dgtjtjd}|  dS W n tk
rN   Y nX t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)	getattrZconfig
subprocessPopenPIPEZcommunicateOSErrorr"   skip)r:   rQ   dotr
   r
   r   if_graphviz_found   s    

r\   c               C   s   t tjdt  S )z=
    temporary directory that wrapped with `path` class.
    ZSPHINX_TEST_TEMPDIR)r   rE   osenvironr&   r   abspathr
   r
   r
   r   r*      s    r*   c             C   s
   t | S )zz
    temporary directory that wrapped with `path` class.
    this fixture is for compat with old test implementation.
    )r   rE   )Ztmpdirr
   r
   r   tempdir   s    r`   )__doc__Z
__future__r   r]   rV   rD   collectionsr   Ztempfiler   r"   Zsixr   r   rR   r   Zfixturer   r   r)   r:   r;   r<   r8   objectrF   r   rP   r\   r*   r`   r
   r
   r
   r   <module>
   s,   1