B
    `M                 @   sB  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 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 d dlmZ d dlmZ d dlm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 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" d dl#m$Z$ d dl%m&Z& d dl'm(Z( ervd dl)m*Z* d dlm+Z+ dZ,ej-.ej/0 Z1e2ee2 dd d!Z3ed"d#d$Z4G d%d& d&e5Z6G d'd# d#e6d(Z7d#eee2ej-j.f e	e8 f d)d*d+Z9G d,d- d-e7Z:d.d/ Z;G d0d1 d1e:Z<G d2d3 d3e<Z=G d4d5 d5e7Z>dS )6    N)Path)Callable)Iterable)Iterator)List)Optional)overload)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union)getfslineno)ExceptionInfo)TerminalRepr)cached_property)Config)ConftestImportFailure)#FSCOLLECTOR_GETHOOKPROXY_ISINITPATH)Mark)MarkDecorator)NodeKeywords)fail)absolutepath)Store)Session)_TracebackStyle/)nodeidreturnc             c   sn   d}t }dV  xZ| ||}|dkr2|t kr2d}q|dkrH| rD| V  P q|rZ| d| V  |t| }qW dS )a  Return the parent node IDs of a given node ID, inclusive.

    For the node ID

        "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source"

    the result would be

        ""
        "testing"
        "testing/code"
        "testing/code/test_excinfo.py"
        "testing/code/test_excinfo.py::TestFormattedExcinfo"
        "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source"

    Note that :: parts are only considered at the last / component.
    r    z::N)SEPfindlen)r   possepZat r(   U/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/_pytest/nodes.pyiterparentnodeids-   s    r*   	_NodeTypeNode)boundc                   s$   e Zd Zdd Z fddZ  ZS )NodeMetac             O   s   dj | jd}t|dd d S )NzDirect construction of {name} has been deprecated, please use {name}.from_parent.
See https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent for more details.)nameF)pytrace)format__name__r   )selfkkwmsgr(   r(   r)   __call__T   s    
zNodeMeta.__call__c                s   t  j||S )N)superr7   )r3   r4   r5   )	__class__r(   r)   _create]   s    zNodeMeta._create)r2   
__module____qualname__r7   r:   __classcell__r(   r(   )r9   r)   r.   S   s   	r.   c            	   @   s  e Zd ZdZdZd?edee deej	j
 ee ddddZed d	d
dZedd ZedddZeddddZeedddZedddZddddZddddZed  dddZd@eeef eddd d!ZdAee ee d"d#d$Z dBee ee!d ef  d"d%d&Z"e#eee d"d'd(Z$e#eeed)d*d(Z$dCeee ee d)d+d(Z$e%e dd,d-Z&ee dd.d/Z'e(g e)f dd0d1d2Z*e+e, ee, d3d4d5Z-e.e/ dd6d7d8Z0dDe.e/ d9e1d:d;d<Z2dEe.e/ d9eee1f d:d=d>Z3dS )Fr,   zBase class for Collector and Item, the components of the test
    collection tree.

    Collector subclasses have children; Items are leaf nodes.
    )r/   parentconfigsessionfspath_nodeid_store__dict__NzOptional[Node]zOptional[Session])r/   r>   r?   r@   rA   r   r    c             C   s   || _ || _|r|| _n|s$td|j| _|r8|| _n|sDtd|j| _|pZt|dd | _t| | _g | _	t
 | _|d k	rd|kst|| _n6| jstd| jj| _| j dkr|  jd| j  7  _t | _d S )Nz!config or parent must be providedz"session or parent must be providedrA   z::()z!nodeid or parent must be providedz()z::)r/   r>   r?   	TypeErrorr@   getattrrA   r   keywordsown_markerssetextra_keyword_matchesAssertionErrorrB   r   r   rC   )r3   r/   r>   r?   r@   rA   r   r(   r(   r)   __init__u   s2    



zNode.__init__)r>   c             K   s4   d|krt dd|kr t d| jf d|i|S )a:  Public constructor for Nodes.

        This indirection got introduced in order to enable removing
        the fragile logic from the node constructors.

        Subclasses can use ``super().from_parent(...)`` when overriding the
        construction.

        :param parent: The parent node of this Node.
        r?   z.config is not a valid argument for from_parentr@   z/session is not a valid argument for from_parentr>   )rE   r:   )clsr>   r5   r(   r(   r)   from_parent   s
    zNode.from_parentc             C   s   | j | jS )z6fspath-sensitive hook proxy used to call pytest hooks.)r@   gethookproxyrA   )r3   r(   r(   r)   ihook   s    z
Node.ihook)r    c             C   s   d | jjt| dd S )Nz<{} {}>r/   )r1   r9   r2   rF   )r3   r(   r(   r)   __repr__   s    zNode.__repr__)warningr    c             C   sN   t |tstd|t| \}}|dk	s0ttj|dt||d d dS )aw  Issue a warning for this Node.

        Warnings will be displayed after the test session, unless explicitly suppressed.

        :param Warning warning:
            The warning instance to issue.

        :raises ValueError: If ``warning`` instance is not a subclass of Warning.

        Example usage:

        .. code-block:: python

            node.warn(PytestWarning("some message"))
            node.warn(UserWarning("some message"))

        .. versionchanged:: 6.2
            Any subclass of :class:`Warning` is now accepted, rather than only
            :class:`PytestWarning <pytest.PytestWarning>` subclasses.
        z<warning must be an instance of Warning or subclass, got {!r}N   )categoryfilenamelineno)	
isinstanceWarning
ValueErrorr1   get_fslocation_from_itemrK   warningswarn_explicitstr)r3   rR   pathrV   r(   r(   r)   warn   s    
z	Node.warnc             C   s   | j S )z;A ::-separated string denoting its collection tree address.)rB   )r3   r(   r(   r)   r      s    zNode.nodeidc             C   s
   t | jS )N)hashrB   )r3   r(   r(   r)   __hash__   s    zNode.__hash__c             C   s   d S )Nr(   )r3   r(   r(   r)   setup   s    z
Node.setupc             C   s   d S )Nr(   )r3   r(   r(   r)   teardown   s    zNode.teardownc             C   s2   g }| }x|dk	r$| | |j}q
W |  |S )zcReturn list of all parent collectors up to self, starting from
        the root of collection tree.N)appendr>   reverse)r3   chainitemr(   r(   r)   	listchain   s    


zNode.listchainT)markerrd   r    c             C   sn   ddl m} t|tr|}nt|tr2t||}ntd|| j|j< |rZ| j	
|j n| j	d|j dS )zDynamically add a marker object to the node.

        :param append:
            Whether to append the marker, or prepend it.
        r   )MARK_GENz'is not a string or pytest.mark.* MarkerN)Z_pytest.markrj   rW   r   r]   rF   rY   rG   r/   rH   rd   markinsert)r3   ri   rd   rj   Zmarker_r(   r(   r)   
add_marker  s    

zNode.add_marker)r/   r    c             C   s   dd | j |dD S )zxIterate over all markers of the node.

        :param name: If given, filter the results by the name attribute.
        c             s   s   | ]}|d  V  qdS )rS   Nr(   ).0xr(   r(   r)   	<genexpr>   s    z$Node.iter_markers.<locals>.<genexpr>)r/   )iter_markers_with_node)r3   r/   r(   r(   r)   iter_markers  s    zNode.iter_markersc             c   sL   xFt |  D ]6}x0|jD ]&}|dks6t|dd|kr||fV  qW qW dS )zIterate over all markers of the node.

        :param name: If given, filter the results by the name attribute.
        :returns: An iterator of (node, mark) tuples.
        Nr/   )reversedrh   rH   rF   )r3   r/   noderk   r(   r(   r)   rq   "  s    zNode.iter_markers_with_nodec             C   s   d S )Nr(   )r3   r/   r(   r(   r)   get_closest_marker/  s    zNode.get_closest_marker)r/   defaultr    c             C   s   d S )Nr(   )r3   r/   rv   r(   r(   r)   ru   3  s    c             C   s   t | j|d|S )zReturn the first marker matching the name, from closest (for
        example function) to farther level (for example module level).

        :param default: Fallback return value if no marker was found.
        :param name: Name to filter by.
        )r/   )nextrr   )r3   r/   rv   r(   r(   r)   ru   7  s    	c             C   s(   t  }x|  D ]}||j qW |S )z;Return a set of all extra keywords in self and any parents.)rI   rh   updaterJ   )r3   Zextra_keywordsrg   r(   r(   r)   listextrakeywordsB  s    zNode.listextrakeywordsc             C   s   dd |   D S )Nc             S   s   g | ]
}|j qS r(   )r/   )rn   ro   r(   r(   r)   
<listcomp>J  s    z"Node.listnames.<locals>.<listcomp>)rh   )r3   r(   r(   r)   	listnamesI  s    zNode.listnames)finr    c             C   s   | j j||  dS )zRegister a function to be called when this node is finalized.

        This method can only be called when this node is active
        in a setup chain, for example during self.setup().
        N)r@   Z_setupstateaddfinalizer)r3   r|   r(   r(   r)   r}   L  s    zNode.addfinalizer)rM   r    c             C   s8   | }x|rt ||s|j}qW |dks4t ||s4t|S )zZGet the next parent node (including self) which is an instance of
        the given class.N)rW   r>   rK   )r3   rM   currentr(   r(   r)   	getparentT  s
    
zNode.getparent)excinfor    c             C   s   d S )Nr(   )r3   r   r(   r(   r)   _prunetraceback]  s    zNode._prunetracebackzOptional[_TracebackStyle])r   styler    c             C   s<  ddl m} t|jtr$t|jj}t|jtjr>|jj	s>d}t|j|rT|j
 S | jddrhd}n>tj|jd g}| | t|jdkr||_|dkrd}|d kr| jd	dd
krd
}nd}| jdddkrd}nd}ytt | jjjk}W n tk
r   d}Y nX |jd|| jdd|d|dS )Nr   )FixtureLookupErrorvalue	fulltraceFlongr"   autotbstyleshortverboserS   T
showlocals)Zfuncargsabspathr   r   Ztbfiltertruncate_locals)Z_pytest.fixturesr   rW   r   r   r   r   r   	Exceptionr0   Z
formatreprr?   	getoption_pytest_code	Traceback	tracebackr   r%   r   osgetcwdZinvocation_paramsdirOSErrorZgetrepr)r3   r   r   r   tbr   r   r(   r(   r)   _repr_failure_py`  sD    


zNode._repr_failure_pyc             C   s   |  ||S )zReturn a representation of a collection or test failure.

        :param excinfo: Exception information for the failure.
        )r   )r3   r   r   r(   r(   r)   repr_failure  s    	zNode.repr_failure)NNNNN)T)N)N)N)N)N)4r2   r;   r<   __doc__	__slots__r]   r   r   pyr^   localrL   classmethodrN   propertyrP   rQ   rX   r_   r   intra   rb   rc   r   rh   r   r   boolrm   r   r   rr   r
   rq   r   ru   r	   ry   r{   r   objectr}   r   r+   r   r   BaseExceptionr   r   r   r   r(   r(   r(   r)   r,   a   sN       1$
		
6
)	metaclass)rt   r    c             C   sL   t | dd}|dk	r |dd S t | dd}|dk	r<t|S t | dddfS )a  Try to extract the actual location from a node, depending on available attributes:

    * "location": a pair (path, lineno)
    * "obj": a Python object that the node wraps.
    * "fspath": just a path

    :rtype: A tuple of (str|py.path.local, int) with filename and line number.
    locationN   objrA   zunknown locationr"   )rF   r   )rt   r   r   r(   r(   r)   rZ     s    rZ   c               @   sf   e Zd ZdZG dd deZeed  dddZe	e
 eeef dd	d
Ze	e
 ddddZdS )	Collectorz\Collector instances create children through collect() and thus
    iteratively build a tree.c               @   s   e Zd ZdZdS )zCollector.CollectErrorz6An error during collection, contains a custom message.N)r2   r;   r<   r   r(   r(   r(   r)   CollectError  s   r   )Itemr   )r    c             C   s   t ddS )zRReturn a list of children (items and collectors) for this
        collection node.ZabstractN)NotImplementedError)r3   r(   r(   r)   collect  s    zCollector.collect)r   r    c             C   sX   t |j| jr0| jdds0|j}t|jd S | jdd}|dkrJd}| j||dS )zyReturn a representation of a collection failure.

        :param excinfo: Exception information for the failure.
        r   Fr   r   r   r   )r   )rW   r   r   r?   r   r]   argsr   )r3   r   excr   r(   r(   r)   r     s    zCollector.repr_failureNc             C   s@   t | dr<|j}|j| jd}||kr2|jtd}| |_d S )NrA   )r^   )Zexcludepath)hasattrr   ZcutrA   tracebackcutdirfilter)r3   r   r   Z
ntracebackr(   r(   r)   r     s    
zCollector._prunetraceback)r2   r;   r<   r   r   r   r   r   r   r   r   r]   r   r   r   r(   r(   r(   r)   r     s   r   c             C   s,   x&| j D ]}|||kr||S qW d S )N)Z_initialpathscommonrelto)r@   rA   Zinitial_pathr(   r(   r)   _check_initialpaths_for_relpath  s    r   c                   sr   e Zd Zdejjee ed ee dd fddZ	e
 fddZejjdd	d
ZejjedddZ  ZS )FSCollectorNr   )rA   r?   r@   r   r    c                s   |j }|d k	r0||j}|r"|}|tjt}|| _|p>|j}|d kr| j|jj	}|sft
||}|rtjtkr|tjt}t j||||||d d S )N)r   rA   )basenamer   rA   replacer   r'   r#   r@   r?   rootdirr   r8   rL   )r3   rA   r>   r?   r@   r   r/   rel)r9   r(   r)   rL     s    

zFSCollector.__init__c               s   t  jf ||d|S )zThe public constructor.)r>   rA   )r8   rN   )rM   r>   rA   r5   )r9   r(   r)   rN     s    zFSCollector.from_parent)rA   c             C   s   t jtdd | j|S )Nr   )
stacklevel)r[   r_   r   r@   rO   )r3   rA   r(   r(   r)   rO     s    zFSCollector.gethookproxy)r^   r    c             C   s   t jtdd | j|S )Nr   )r   )r[   r_   r   r@   
isinitpath)r3   r^   r(   r(   r)   r     s    zFSCollector.isinitpath)NNNN)r2   r;   r<   r   r^   r   r   r   r]   rL   r   rN   rO   r   r   r=   r(   r(   )r9   r)   r     s      r   c               @   s   e Zd ZdZdS )FilezOBase class for collecting tests from a file.

    :ref:`non-python tests`.
    N)r2   r;   r<   r   r(   r(   r(   r)   r     s   r   c                   s   e Zd ZdZdZdee ed ee dd fddZdddd	Z	eeedd
ddZ
eeejjef ee ef dddZeeeee ef dddZ  ZS )r   zvA basic test invocation item.

    Note that for a single function there might be multiple test invocation items.
    Nr   )r?   r@   r   r    c                s&   t  j|||||d g | _g | _d S )N)r   )r8   rL   _report_sectionsZuser_properties)r3   r/   r>   r?   r@   r   )r9   r(   r)   rL   #  s    zItem.__init__)r    c             C   s   t dd S )Nz,runtest must be implemented by Item subclass)r   )r3   r(   r(   r)   runtest2  s    zItem.runtest)whenkeycontentr    c             C   s   |r| j |||f dS )a  Add a new report section, similar to what's done internally to add
        stdout and stderr captured output::

            item.add_report_section("call", "stdout", "report section contents")

        :param str when:
            One of the possible capture states, ``"setup"``, ``"call"``, ``"teardown"``.
        :param str key:
            Name of the section, can be customized at will. Pytest uses ``"stdout"`` and
            ``"stderr"`` internally.
        :param str content:
            The full contents as a string.
        N)r   rd   )r3   r   r   r   r(   r(   r)   add_report_section5  s    zItem.add_report_sectionc             C   s   | j d dfS )Nr!   )rA   )r3   r(   r(   r)   
reportinfoF  s    zItem.reportinfoc             C   sJ   |   }tt|d }| j|}t|d tks8t||d |d fS )Nr   r   rS   )r   r   r]   r@   Z_node_location_to_relpathtyperK   )r3   r   rA   Z	relfspathr(   r(   r)   r   I  s
    zItem.location)NNNN)r2   r;   r<   r   nextitemr   r   r]   rL   r   r   r
   r   r   r^   r   r   r   r   r   r=   r(   r(   )r9   r)   r     s      (r   )?r   r[   pathlibr   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   Z_pytest._coder   r   Z_pytest._code.coder   r   Z_pytest.compatr   Z_pytest.configr   r   Z_pytest.deprecatedr   Z_pytest.mark.structuresr   r   r   Z_pytest.outcomesr   Z_pytest.pathlibr   Z_pytest.storer   Z_pytest.mainr   r   r#   r^   r   __file__dirpathr   r]   r*   r+   r   r.   r,   r   rZ   r   r   r   r   r   r(   r(   r(   r)   <module>   s^   #  E&++