a
    /§»a¨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   sj   d}t }dV  |  ||¡}|dkr0|t kr0d}q|dkrF| rf| V  qfq|rX| d|… V  |t|ƒ }q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   Ú éÿÿÿÿú::N)ÚSEPÚfindÚlen)r   ÚposÚsepÚat© r*   úG/home/yuhw/wc/pochoir/venv/lib/python3.9/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 )NzÉDirect 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|i |¤ŽS ©N)Úsuperr:   )r6   r7   r8   ©Ú	__class__r*   r+   Ú_create]   s    zNodeMeta._create)r5   Ú
__module__Ú__qualname__r:   r?   Ú__classcell__r*   r*   r=   r+   r0   S   s   	r0   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.   z–Base class for Collector and Item, the components of the test
    collection tree.

    Collector subclasses have children; Items are leaf nodes.
    )r2   ÚparentÚconfigÚsessionÚfspathÚ_nodeidÚ_storeÚ__dict__NzOptional[Node]zOptional[Session])r2   rC   rD   rE   rF   r   r    c                 C   sÔ   || _ || _|r|| _n|s$tdƒ‚|j| _|r8|| _n|sDtdƒ‚|j| _|pZt|dd ƒ| _t| ƒ| _g | _	t
ƒ | _|d ur’d|vsŠJ ‚|| _n6| js t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 providedrF   z::()z!nodeid or parent must be providedz()r#   )r2   rC   rD   Ú	TypeErrorrE   ÚgetattrrF   r   ÚkeywordsÚown_markersÚsetÚextra_keyword_matchesrG   r   r   rH   )r6   r2   rC   rD   rE   rF   r   r*   r*   r+   Ú__init__u   s2    



zNode.__init__)rC   c                 K   s4   d|v rt dƒ‚d|v 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.
        rD   z.config is not a valid argument for from_parentrE   z/session is not a valid argument for from_parentrC   )rJ   r?   )ÚclsrC   r8   r*   r*   r+   Úfrom_parent®   s
    zNode.from_parentc                 C   s   | j  | j¡S )z6fspath-sensitive hook proxy used to call pytest hooks.)rE   ÚgethookproxyrF   ©r6   r*   r*   r+   ÚihookÀ   s    z
Node.ihook©r    c                 C   s   d  | jjt| dd ƒ¡S )Nz<{} {}>r2   )r4   r>   r5   rK   rT   r*   r*   r+   Ú__repr__Å   s    zNode.__repr__)Úwarningr    c                 C   sN   t |tƒstd |¡ƒ‚t| ƒ\}}|dus0J ‚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Ú
ValueErrorr4   Úget_fslocation_from_itemÚwarningsÚwarn_explicitÚstr)r6   rX   Úpathr\   r*   r*   r+   ÚwarnÈ   s    
ÿÿÿz	Node.warnc                 C   s   | j S )z;A ::-separated string denoting its collection tree address.)rG   rT   r*   r*   r+   r   ì   s    zNode.nodeidc                 C   s
   t | jƒS r;   )ÚhashrG   rT   r*   r*   r+   Ú__hash__ñ   s    zNode.__hash__c                 C   s   d S r;   r*   rT   r*   r*   r+   Úsetupô   s    z
Node.setupc                 C   s   d S r;   r*   rT   r*   r*   r+   Úteardown÷   s    zNode.teardownc                 C   s.   g }| }|dur"|  |¡ |j}q| ¡  |S )zcReturn list of all parent collectors up to self, starting from
        the root of collection tree.N)ÚappendrC   Úreverse)r6   ÚchainÚitemr*   r*   r+   Ú	listchainú   s    
zNode.listchainT)Úmarkerrj   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 )z†Dynamically 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.markrp   r]   r   rc   rK   r_   rL   r2   rM   rj   ÚmarkÚinsert)r6   ro   rj   rp   Zmarker_r*   r*   r+   Ú
add_marker  s    

zNode.add_marker)r2   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 )rY   Nr*   ©Ú.0Úxr*   r*   r+   Ú	<genexpr>   ó    z$Node.iter_markers.<locals>.<genexpr>r1   )Úiter_markers_with_node©r6   r2   r*   r*   r+   Úiter_markers  s    zNode.iter_markersc                 c   sD   t |  ¡ ƒD ]2}|jD ]&}|du s2t|ddƒ|kr||fV  qqdS )z®Iterate over all markers of the node.

        :param name: If given, filter the results by the name attribute.
        :returns: An iterator of (node, mark) tuples.
        Nr2   )Úreversedrn   rM   rK   )r6   r2   Únoderq   r*   r*   r+   ry   "  s    
zNode.iter_markers_with_nodec                 C   s   d S r;   r*   rz   r*   r*   r+   Úget_closest_marker/  s    zNode.get_closest_marker)r2   Údefaultr    c                 C   s   d S r;   r*   ©r6   r2   r   r*   r*   r+   r~   3  s    c                 C   s   t | j|d�|ƒS )zûReturn 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.
        r1   )Únextr{   r€   r*   r*   r+   r~   7  s    	c                 C   s$   t ƒ }|  ¡ D ]}| |j¡ q|S )z;Return a set of all extra keywords in self and any parents.)rN   rn   ÚupdaterO   )r6   Zextra_keywordsrm   r*   r*   r+   ÚlistextrakeywordsB  s    zNode.listextrakeywordsc                 C   s   dd„ |   ¡ D ƒS )Nc                 S   s   g | ]
}|j ‘qS r*   r1   rt   r*   r*   r+   Ú
<listcomp>J  rx   z"Node.listnames.<locals>.<listcomp>)rn   rT   r*   r*   r+   Ú	listnamesI  s    zNode.listnames)Úfinr    c                 C   s   | j j || ¡ dS )zÂRegister 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)rE   Z_setupstateÚaddfinalizer)r6   r†   r*   r*   r+   r‡   L  s    zNode.addfinalizer)rQ   r    c                 C   s4   | }|rt ||ƒs|j}q|du s0t ||ƒs0J ‚|S )zZGet the next parent node (including self) which is an instance of
        the given class.N)r]   rC   )r6   rQ   Úcurrentr*   r*   r+   Ú	getparentT  s
    zNode.getparent©Úexcinfor    c                 C   s   d S r;   r*   )r6   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r¦d}|d u rÊ| j d	d¡d
krÆd
}nd}| j dd¡dkrâd}nd}ztt ¡ ƒ| jjjk}W n t�y   d}Y n0 |jd|| j dd¡|d|d�S )Nr   )ÚFixtureLookupErrorÚvalueÚ	fulltraceFÚlongr"   ÚautoÚtbstyleÚshortÚverboserY   TÚ
showlocals)ZfuncargsÚabspathr–   r�   ZtbfilterÚtruncate_locals)Z_pytest.fixturesrŽ   r]   r�   r   r   r‹   r   Ú	Exceptionr3   Z
formatreprrD   Ú	getoptionÚ_pytestÚ_codeÚ	TracebackÚ	tracebackrŒ   r&   r   ÚosÚgetcwdZinvocation_paramsÚdirÚOSErrorZgetrepr)r6   r‹   r�   rŽ   Útbr˜   r—   r*   r*   r+   Ú_repr_failure_py`  sF    


úzNode._repr_failure_pyc                 C   s   |   ||¡S )z�Return a representation of a collection or test failure.

        :param excinfo: Exception information for the failure.
        )r¤   )r6   r‹   r�   r*   r*   r+   Úrepr_failure—  s    	zNode.repr_failure)NNNNN)T)N)N)N)N)N)4r5   r@   rA   Ú__doc__Ú	__slots__rc   r   r   Úpyrd   ÚlocalrP   ÚclassmethodrR   ÚpropertyrU   rW   r^   re   r   Úintrg   rh   ri   r   rn   r   r   Úboolrs   r   r   r{   r
   ry   r   r~   r	   rƒ   r…   r   Úobjectr‡   r   r-   r‰   r   ÚBaseExceptionrŒ   r   r¤   r¥   r*   r*   r*   r+   r.   a   s‚        ù
ø9
$ ÿþ ÿþ ÿþ	 ýü: ý
ü)Ú	metaclass)r}   r    c                 C   sL   t | ddƒ}|dur |dd… S t | ddƒ}|du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é   ÚobjrF   zunknown locationr"   )rK   r   )r}   r±   r³   r*   r*   r+   r`   £  s    r`   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©r5   r@   rA   r¦   r*   r*   r*   r+   ÚCollectError¼  s   r¶   )ÚItemr´   rV   c                 C   s   t dƒ‚dS )zRReturn a list of children (items and collectors) for this
        collection node.ZabstractN©ÚNotImplementedErrorrT   r*   r*   r+   Úcollect¿  s    zCollector.collectrŠ   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�   )r]   r�   r¶   rD   rš   rc   Úargsr¤   )r6   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 )NrF   )rd   )Zexcludepath)Úhasattrrž   ZcutrF   ÚtracebackcutdirÚfilter)r6   r‹   rž   Z
ntracebackr*   r*   r+   rŒ   Ú  s    
zCollector._prunetraceback)r5   r@   rA   r¦   r™   r¶   r   r   rº   r   r¯   rc   r   r¥   rŒ   r*   r*   r*   r+   r´   ¸  s   
þr´   c                 C   s,   | j D ] }| |¡|kr| |¡  S qd S r;   )Z_initialpathsÚcommonÚrelto)rE   rF   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   )rF   rD   rE   r   r    c                    sž   |j }|d ur0| |j¡}|r"|}| tjt¡}|| _|p>|j}|d u r‚| j |jj	¡}|sft
||ƒ}|r‚tjtkr‚| tjt¡}tƒ j||||||d� d S )N)r   rF   )ÚbasenamerÁ   rF   ÚreplacerŸ   r(   r$   rE   rD   ÚrootdirrÂ   r<   rP   )r6   rF   rC   rD   rE   r   r2   Úrelr=   r*   r+   rP   ê  s    

zFSCollector.__init__c                   s   t ƒ jf ||dœ|¤ŽS )zThe public constructor.)rC   rF   )r<   rR   )rQ   rC   rF   r8   r=   r*   r+   rR     s    zFSCollector.from_parent©rF   c                 C   s   t jtdd� | j |¡S ©Nr²   )Ú
stacklevel)ra   re   r   rE   rS   )r6   rF   r*   r*   r+   rS     s    zFSCollector.gethookproxy)rd   r    c                 C   s   t jtdd� | j |¡S rÉ   )ra   re   r   rE   Ú
isinitpath)r6   rd   r*   r*   r+   rË     s    zFSCollector.isinitpath)NNNN)r5   r@   rA   r¨   rd   r©   r   r   rc   rP   rª   rR   rS   r­   rË   rB   r*   r*   r=   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`.
    Nrµ   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   )rD   rE   r   r    c                    s&   t ƒ j|||||d� g | _g | _d S )N)r   )r<   rP   Ú_report_sectionsZuser_properties)r6   r2   rC   rD   rE   r   r=   r*   r+   rP   #  s    zItem.__init__rV   c                 C   s   t dƒ‚d S )Nz,runtest must be implemented by Item subclassr¸   rT   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Í   rj   )r6   rÏ   rÐ   rÑ   r*   r*   r+   Úadd_report_section5  s    zItem.add_report_sectionc                 C   s   | j d dfS )Nr!   rÈ   rT   r*   r*   r+   Ú
reportinfoF  s    zItem.reportinfoc                 C   sJ   |   ¡ }tt|d ƒƒ}| j |¡}t|d ƒtu s8J ‚||d |d fS )Nr   r²   rY   )rÓ   r   rc   rE   Z_node_location_to_relpathÚtype)r6   r±   rF   Z	relfspathr*   r*   r+   r±   I  s
    zItem.location)NNNN)r5   r@   rA   r¦   Únextitemr   r   rc   rP   rÎ   rÒ   r
   r   r¨   rd   r©   r¬   rÓ   r   r±   rB   r*   r*   r=   r+   r·     s"       úù(r·   )?rŸ   ra   Ú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$   rd   r©   Ú__file__Údirpathr¾   rc   r,   r-   rÔ   r0   r.   r¬   r`   r´   rÂ   rÃ   rÌ   r·   r*   r*   r*   r+   Ú<module>   s`   #  Eþ++