a
    ܌xdg                     @   s  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mZ d dlmZ d dlmZ d dlm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+m,Z, d d!l+m-Z- d d"l.m/Z/ d d#l0m1Z1 erd d$l2m3Z3 d d%lm4Z4 d&Z5eej6j7Z8e9ee9 d'd(d)Z:eedd*d+d,Z;ed- ee ee ed.d/d0Z<ed1d-d2Z=G d3d4 d4e>Z?G d5d- d-e?d6Z@d-eee9ef eeA f d7d8d9ZBG d:d; d;e@ZCd<eee9 d=d>d?ZDG d@dA dAeCZEG dBdC dCeEZFG dDdE dEe@ZGdS )F    N)	signature)Path)Any)Callable)cast)Iterable)Iterator)List)MutableMapping)Optional)overload)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union)getfslineno)ExceptionInfo)TerminalRepr)cached_property)LEGACY_PATH)Config)ConftestImportFailure)#FSCOLLECTOR_GETHOOKPROXY_ISINITPATH)NODE_CTOR_FSPATH_ARG)Mark)MarkDecorator)NodeKeywords)fail)absolutepath)
commonpath)Stash)PytestWarning)Session)_TracebackStyle/)nodeidreturnc                 c   s   d}|  d}|dkrd}dV  |  t||}|dkr8q\|dkrN| d| V  |tt }q |  d|}|dkrrq|dkr| d| V  |td }q\| r| V  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 / components are only considered until the first ::.
    r   ::N )findSEPlen)r'   posZfirst_colonsat r1   E/var/www/html/Ranjet/env/lib/python3.9/site-packages/_pytest/nodes.pyiterparentnodeids3   s&    
r3   )pathfspathr(   c                 C   s&   t || kr"td|d| dd S )NzPath(z) != z8
if both path and fspath are given they need to be equal)r   
ValueError)r4   r5   r1   r1   r2   _check_path`   s    r7   Node)	node_typer4   r5   r(   c                 C   sV   |d ur t jtj| jddd |d ur>|d ur:t|| |S |d usJJ t|S d S )N)Znode_type_name   
stacklevel)warningswarnr   format__name__r7   r   )r9   r4   r5   r1   r1   r2   _imply_pathh   s    
rA   	_NodeType)boundc                       s$   e Zd Zdd Z fddZ  ZS )NodeMetac                 O   s*   dj | j d| 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)r?   
__module__r@   r   )selfkkwmsgr1   r1   r2   __call__   s
    zNodeMeta.__call__c              
      s   zt  j|i |W S  ty   tt| d  fdd| D }ddlm} t	||  dt
| d t  j|i | Y S 0 d S )N__init__c                    s    i | ]\}}| j v r||qS r1   )
parameters).0rK   vsigr1   r2   
<dictcomp>       z$NodeMeta._create.<locals>.<dictcomp>   )PytestDeprecationWarningz7 is not using a cooperative constructor and only takes z.
See https://docs.pytest.org/en/stable/deprecations.html#constructors-of-custom-pytest-node-subclasses-should-take-kwargs for more details.)superrN   	TypeErrorr   getattritemsZwarning_typesrX   r=   r>   set)rJ   rK   rL   Zknown_kwrX   	__class__rS   r2   _create   s    	zNodeMeta._create)r@   rI   __qualname__rN   r`   __classcell__r1   r1   r^   r2   rD      s   	rD   c                
   @   s  e Zd ZU dZeed< dZd@edee	 dee ee
 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dAeeef edd d!d"ZdBee ee d#d$d%Z dCe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$dDeee ee d*d,d)Z$e%e dd-d.Z&ee dd/d0Z'e(g e)f dd1d2d3Z*e+e, ee, d4d5d6Z-e.e/ dd7d8d9Z0dEe.e/ d:e1d;d<d=Z2dFe.e/ d:eee1f d;d>d?Z3dS )Gr8   zBase class for Collector and Item, the components of the test
    collection tree.

    Collector subclasses have children; Items are leaf nodes.
    r5   )rG   parentconfigsessionr4   _nodeid_store__dict__NzOptional[Node]zOptional[Session])rG   rc   rd   re   r5   r4   r'   r(   c                 C   s   || _ || _|r|| _n|s$td|j| _|r8|| _n|sDtd|j| _|d u rh|d u rht|dd }tt| ||d| _t	| | _
g | _t | _|d urd|vsJ || _n"| jstd| jjd | j  | _t | _| j| _d S )Nz!config or parent must be providedz"session or parent must be providedr4   r5   z::()z!nodeid or parent must be providedr)   )rG   rc   rd   rZ   re   r[   rA   typer4   r   keywordsown_markersr]   extra_keyword_matchesrf   r'   r"   stashrg   )rJ   rG   rc   rd   re   r5   r4   r'   r1   r1   r2   rO      s4    
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   )rZ   r`   )clsrc   rL   r1   r1   r2   from_parent   s
    zNode.from_parentc                 C   s   | j | jS )z6fspath-sensitive hook proxy used to call pytest hooks.)re   gethookproxyr4   rJ   r1   r1   r2   ihook  s    z
Node.ihookr(   c                 C   s   d | jjt| dd S )Nz<{} {}>rG   )r?   r_   r@   r[   rr   r1   r1   r2   __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}NrW   )categoryfilenamelineno)
isinstanceWarningr6   r?   get_fslocation_from_itemr=   warn_explicitstr)rJ   rv   r4   ry   r1   r1   r2   r>     s    
z	Node.warnc                 C   s   | j S )z;A ::-separated string denoting its collection tree address.)rf   rr   r1   r1   r2   r'   7  s    zNode.nodeidc                 C   s
   t | jS N)hashrf   rr   r1   r1   r2   __hash__<  s    zNode.__hash__c                 C   s   d S r   r1   rr   r1   r1   r2   setup?  s    z
Node.setupc                 C   s   d S r   r1   rr   r1   r1   r2   teardownB  s    zNode.teardownc                 C   s.   g }| }|dur"| | |j}q|  |S )zReturn list of all parent collectors up to self, starting from
        the root of collection tree.

        :returns: The nodes.
        N)appendrc   reverse)rJ   chainitemr1   r1   r2   	listchainE  s    
zNode.listchainT)markerr   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 marker:
            The marker.
        :param append:
            Whether to append the marker, or prepend it.
        r   )MARK_GENz'is not a string or pytest.mark.* MarkerN)Z_pytest.markr   rz   r   r~   r[   r6   rk   rG   rl   r   markinsert)rJ   r   r   r   Zmarker_r1   r1   r2   
add_markerS  s    


zNode.add_marker)rG   r(   c                 C   s   dd | j |dD S )zIterate over all markers of the node.

        :param name: If given, filter the results by the name attribute.
        :returns: An iterator of the markers of the node.
        c                 s   s   | ]}|d  V  qdS )rW   Nr1   rQ   xr1   r1   r2   	<genexpr>q  rV   z$Node.iter_markers.<locals>.<genexpr>rF   )iter_markers_with_noderJ   rG   r1   r1   r2   iter_markersk  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 )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.
        NrG   )reversedr   rl   r[   )rJ   rG   noder   r1   r1   r2   r   s  s    
zNode.iter_markers_with_nodec                 C   s   d S r   r1   r   r1   r1   r2   get_closest_marker  s    zNode.get_closest_marker)rG   defaultr(   c                 C   s   d S r   r1   rJ   rG   r   r1   r1   r2   r     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.
        rF   )nextr   r   r1   r1   r2   r     s    	c                 C   s$   t  }|  D ]}||j q|S )z;Return a set of all extra keywords in self and any parents.)r]   r   updaterm   )rJ   Zextra_keywordsr   r1   r1   r2   listextrakeywords  s    zNode.listextrakeywordsc                 C   s   dd |   D S )Nc                 S   s   g | ]
}|j qS r1   rF   r   r1   r1   r2   
<listcomp>  rV   z"Node.listnames.<locals>.<listcomp>)r   rr   r1   r1   r2   	listnames  s    zNode.listnames)finr(   c                 C   s   | j j||  dS )zRegister a function to be called without arguments 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)rJ   r   r1   r1   r2   r     s    zNode.addfinalizer)ro   r(   c                 C   s4   | }|rt ||s|j}q|du s0t ||s0J |S )zGet the next parent node (including self) which is an instance of
        the given class.

        :param cls: The node class to search for.
        :returns: The node, if found.
        N)rz   rc   )rJ   ro   currentr1   r1   r2   	getparent  s
    zNode.getparentexcinfor(   c                 C   s   d S r   r1   )rJ   r   r1   r1   r2   _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|rV|j S | jddrjd}n>tj|jd g}| | t|jdkr||_|dkrd}|d u r| jd	dd
krd
}nd}| jdddkrd}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verboserW   T
showlocals)Zfuncargsabspathr   r   Ztbfiltertruncate_locals)Z_pytest.fixturesr   rz   r   r   r   Zfrom_exc_infor   r   	ExceptionrH   Z
formatreprrd   	getoption_pytest_code	Traceback	tracebackr   r.   r   osgetcwdZinvocation_paramsdirOSErrorZgetrepr)rJ   r   r   r   tbr   r   r1   r1   r2   _repr_failure_py  sF    


zNode._repr_failure_pyc                 C   s   |  ||S )zReturn a representation of a collection or test failure.

        .. seealso:: :ref:`non-python tests`

        :param excinfo: Exception information for the failure.
        )r   )rJ   r   r   r1   r1   r2   repr_failure  s    zNode.repr_failure)NNNNNN)T)N)N)N)N)N)4r@   rI   ra   __doc__r   __annotations__	__slots__r~   r   r   r   rO   classmethodrp   propertyrs   ru   r{   r>   r'   intr   r   r   r	   r   r   r   boolr   r   r   r   r   r   r   r   r   r   r   r   objectr   r   rB   r   r   BaseExceptionr   r   r   r   r1   r1   r1   r2   r8      s   
      =
' 	  	 : 
)	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|Path, int) with filename and 0-based line number.
    locationN   objr5   zunknown locationr*   )r[   r   )r   r   r   r1   r1   r2   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r@   rI   ra   r   r1   r1   r1   r2   CollectError  s   r   )Itemr   rt   c                 C   s   t ddS )zRReturn a list of children (items and collectors) for this
        collection node.ZabstractNNotImplementedErrorrr   r1   r1   r2   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   )rz   r   r   rd   r   r~   argsr   )rJ   r   excr   r1   r1   r2   r     s    zCollector.repr_failureNc                 C   s@   t | dr<|j}|j| jd}||kr2|jtd}| |_d S )Nr4   r4   )Zexcludepath)hasattrr   cutr4   tracebackcutdirfilter)rJ   r   r   Z
ntracebackr1   r1   r2   r   0  s    
zCollector._prunetraceback)r@   rI   ra   r   r   r   r   r   r   r   r   r~   r   r   r   r1   r1   r1   r2   r     s   
r   r$   )re   r4   r(   c                 C   s@   | j D ]4}t|||krt||}|dkr2dn|  S qd S )NrE   r+   )Z_initialpathsr!   r~   relative_to)re   r4   Zinitial_pathrelr1   r1   r2   _check_initialpaths_for_relpath9  s
    
r   c                       s   e Zd Zdee eeeef  ee ee ee ee	 ed ee dd	 fddZ
edddee ee d fddZd	d
ddZeed	f edddZ  ZS )FSCollectorNr$   )	r5   path_or_parentr4   rG   rc   rd   re   r'   r(   c	           
         sJ  |r@t |tr&|d u sJ tt|}nt |tr@|d u s<J |}tt| ||d}|d u r|j}|d ur|j|krz|	|j}	W n t
y   Y n
0 t|	}|tjt}|| _|d u r|d usJ |j}|d u r.zt| j	|jj}W n t
y   t||}Y n0 |r.tjtkr.|tjt}t j||||||d d S )Nri   )rG   rc   rd   re   r'   r4   )rz   r8   r   r   r   rA   rj   rG   r4   r   r6   r~   replacer   sepr-   re   rd   Zrootpathr   rY   rO   )
rJ   r5   r   r4   rG   rc   rd   re   r'   r   r^   r1   r2   rO   B  sH    


zFSCollector.__init__)r5   r4   c                   s   t  jf |||d|S )zThe public constructor.)rc   r5   r4   )rY   rp   )ro   rc   r5   r4   rL   r^   r1   r2   rp   x  s    
zFSCollector.from_parentos.PathLike[str]ri   c                 C   s   t jtdd | j|S Nr   r;   )r=   r>   r   re   rq   )rJ   r5   r1   r1   r2   rq     s    zFSCollector.gethookproxy)r4   r(   c                 C   s   t jtdd | j|S r   )r=   r>   r   re   
isinitpath)rJ   r4   r1   r1   r2   r     s    zFSCollector.isinitpath)NNNNNNNN)r@   rI   ra   r   r   r   r   r8   r~   r   rO   r   rp   rq   r   r   rb   r1   r1   r^   r2   r   A  s8           6r   c                   @   s   e Zd ZdZdS )FilezOBase class for collecting tests from a file.

    :ref:`non-python tests`.
    Nr   r1   r1   r1   r2   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	ddd
dZ
eeeddddZeed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                    s6   t  j||f|||d| g | _g | _|   d S )N)rd   re   r'   )rY   rO   _report_sectionsZuser_properties-_check_item_and_collector_diamond_inheritance)rJ   rG   rc   rd   re   r'   rL   r^   r1   r2   rO     s    zItem.__init__rt   c                 C   s`   t | }d}t||drdS t||d ddd |jD }|r\t|j d| d	t dS )
z
        Check if the current type inherits from both File and Collector
        at the same time, emitting a warning accordingly (#8447).
        Z)_pytest_diamond_inheritance_warning_shownFNTz, c                 s   s   | ]}t |tr|jV  qd S r   )
issubclassr   r@   )rQ   baser1   r1   r2   r     s   zEItem._check_item_and_collector_diamond_inheritance.<locals>.<genexpr>zF is an Item subclass and should not be a collector, however its bases z are collectors.
Please split the Collectors and the Item into separate node types.
Pytest Doc example: https://docs.pytest.org/en/latest/example/nonpython.html
example pull request on a plugin: https://github.com/asmeurer/pytest-flakes/pull/40/)	rj   r[   setattrjoin	__bases__r=   r>   r@   r#   )rJ   ro   	attr_nameproblemsr1   r1   r2   r     s    
z2Item._check_item_and_collector_diamond_inheritancec                 C   s   t ddS )zRun the test case for this item.

        Must be implemented by subclasses.

        .. seealso:: :ref:`non-python tests`
        z,runtest must be implemented by Item subclassNr   rr   r1   r1   r2   runtest  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   r   )rJ   r   r   r   r1   r1   r2   add_report_section  s    zItem.add_report_sectionr   c                 C   s   | j ddfS )aP  Get location information for this item for test reports.

        Returns a tuple with three elements:

        - The path of the test (default ``self.path``)
        - The 0-based line number of the test (default ``None``)
        - A name of the test to be shown (default ``""``)

        .. seealso:: :ref:`non-python tests`
        Nr+   r   rr   r1   r1   r2   
reportinfo  s    zItem.reportinfoc                 C   sL   |   }tt|d }| j|}t|d tu s:J ||d |d fS )z
        Returns a tuple of ``(relfspath, lineno, testname)`` for this item
        where ``relfspath`` is file path relative to ``config.rootpath``
        and lineno is a 0-based line number.
        r   r   rW   )r   r    r   r5   re   Z_node_location_to_relpathrj   r~   )rJ   r   r4   Z	relfspathr1   r1   r2   r     s
    zItem.location)NNNN)r@   rI   ra   r   Znextitemr   r   r~   rO   r   r   r   r   r   r   r   r   r   rb   r1   r1   r^   r2   r     s$       	$r   )Hr   r=   inspectr   pathlibr   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   Z_pytest._coder   r   Z_pytest._code.coder   r   Z_pytest.compatr   r   Z_pytest.configr   r   Z_pytest.deprecatedr   r   Z_pytest.mark.structuresr   r   r   Z_pytest.outcomesr   Z_pytest.pathlibr    r!   Z_pytest.stashr"   Z_pytest.warning_typesr#   Z_pytest.mainr$   r%   r-   __file__rc   r   r~   r3   r7   rA   rB   rj   rD   r8   r   r|   r   r   r   r   r   r1   r1   r1   r2   <module>   sv   -	  _$+L