a
    !f?h                     @   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#l/m0Z0 d d$l1m2Z2 erd d%l3m4Z4 d d&lm5Z5 d'Z6eej7j8Z9e:ee: d(d)d*Z;eedd+d,d-Z<ed. ee ee ed/d0d1Z=ed2d.d3Z>G d4d5 d5e?Z@G d6d. d.e@d7ZAd.eee:ef eeB f d8d9d:ZCG d;d< d<eAZDd=eee: d>d?d@ZEG dAdB dBeDZFG dCdD dDeFZGG dEdF dFeAZHdS )G    N)	signature)Path)Any)Callable)cast)Iterable)Iterator)List)MutableMapping)Optional)overload)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union)getfslineno)ExceptionInfo)TerminalRepr)	Traceback)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 r2   N/var/www/html/python-backend/venv/lib/python3.9/site-packages/_pytest/nodes.pyiterparentnodeids4   s&    
r4   )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)r5   r6   r2   r2   r3   _check_patha   s    r8   Node)	node_typer5   r6   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__r8   r   )r:   r5   r6   r2   r2   r3   _imply_pathi   s    
rB   	_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__rA   r    )selfkkwmsgr2   r2   r3   __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 r2   )
parameters).0rL   vsigr2   r3   
<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.)superrO   	TypeErrorr   getattritemsZwarning_typesrY   r>   r?   set)rK   rL   rM   Zknown_kwrY   	__class__rT   r3   _create   s    	zNodeMeta._create)rA   rJ   __qualname__rO   ra   __classcell__r2   r2   r_   r3   rE      s   	rE   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/ e0d7d8d9Z1dEe.e/ d:e2d;d<d=Z3dFe.e/ d:eee2f d;d>d?Z4dS )Gr9   zBase class of :class:`Collector` and :class:`Item`, the components of
    the test collection tree.

    ``Collector``\'s are the internal nodes of the tree, and ``Item``\'s are the
    leaf nodes.
    r6   )rH   parentconfigsessionr5   _nodeid_store__dict__NzOptional[Node]zOptional[Session])rH   rd   re   rf   r6   r5   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 providedr5   r6   z::()z!nodeid or parent must be providedr*   )rH   rd   re   r[   rf   r\   rB   typer5   r   keywordsown_markersr^   extra_keyword_matchesrg   r(   r#   stashrh   )rK   rH   rd   re   rf   r6   r5   r(   r2   r2   r3   rP      s4    
zNode.__init__)rd   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.
        re   z.config is not a valid argument for from_parentrf   z/session is not a valid argument for from_parentrd   )r[   ra   )clsrd   rM   r2   r2   r3   from_parent   s
    zNode.from_parentc                 C   s   | j | jS )z6fspath-sensitive hook proxy used to call pytest hooks.)rf   gethookproxyr5   rK   r2   r2   r3   ihook
  s    z
Node.ihookr)   c                 C   s   d | jjt| dd S )Nz<{} {}>rH   )r@   r`   rA   r\   rs   r2   r2   r3   __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}NrX   )categoryfilenamelineno)
isinstanceWarningr7   r@   get_fslocation_from_itemr>   warn_explicitstr)rK   rw   r5   rz   r2   r2   r3   r?     s    
z	Node.warnc                 C   s   | j S )z;A ::-separated string denoting its collection tree address.)rg   rs   r2   r2   r3   r(   9  s    zNode.nodeidc                 C   s
   t | jS N)hashrg   rs   r2   r2   r3   __hash__>  s    zNode.__hash__c                 C   s   d S r   r2   rs   r2   r2   r3   setupA  s    z
Node.setupc                 C   s   d S r   r2   rs   r2   r2   r3   teardownD  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)appendrd   reverse)rK   chainitemr2   r2   r3   	listchainG  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   r{   r   r   r\   r7   rl   rH   rm   r   markinsert)rK   r   r   r   Zmarker_r2   r2   r3   
add_markerU  s    


zNode.add_marker)rH   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 )rX   Nr2   rR   xr2   r2   r3   	<genexpr>s  rW   z$Node.iter_markers.<locals>.<genexpr>rG   )iter_markers_with_noderK   rH   r2   r2   r3   iter_markersm  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.
        NrH   )reversedr   rm   r\   )rK   rH   noder   r2   r2   r3   r   u  s    
zNode.iter_markers_with_nodec                 C   s   d S r   r2   r   r2   r2   r3   get_closest_marker  s    zNode.get_closest_marker)rH   defaultr)   c                 C   s   d S r   r2   rK   rH   r   r2   r2   r3   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.
        rG   )nextr   r   r2   r2   r3   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   updatern   )rK   Zextra_keywordsr   r2   r2   r3   listextrakeywords  s    zNode.listextrakeywordsc                 C   s   dd |   D S )Nc                 S   s   g | ]
}|j qS r2   rG   r   r2   r2   r3   
<listcomp>  rW   z"Node.listnames.<locals>.<listcomp>)r   rs   r2   r2   r3   	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)rf   Z_setupstateaddfinalizer)rK   r   r2   r2   r3   r     s    zNode.addfinalizer)rp   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)r{   rd   )rK   rp   currentr2   r2   r3   	getparent  s
    zNode.getparentexcinfor)   c                 C   s   |j S r   )	traceback)rK   r   r2   r2   r3   _traceback_filter  s    zNode._traceback_filterz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rnd}d}n| j}|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S )Nr   )FixtureLookupErrorvalue	fulltraceFlongautotbstyleshortverboserX   T
showlocals)Zfuncargsabspathr   r   tbfiltertruncate_locals)Z_pytest.fixturesr   r{   r   r   r   Zfrom_exc_infor   r    	ExceptionrI   Z
formatreprre   	getoptionr   r   osgetcwdZinvocation_paramsdirOSErrorZgetrepr)rK   r   r   r   r   r   r   r2   r2   r3   _repr_failure_py  sB    

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   )rK   r   r   r2   r2   r3   repr_failure  s    zNode.repr_failure)NNNNNN)T)N)N)N)N)N)5rA   rJ   rb   __doc__r   __annotations__	__slots__r   r   r   r   rP   classmethodrq   propertyrt   rv   r|   r?   r(   intr   r   r   r	   r   r   r   boolr   r   r   r   r   r   r   r   r   r   r   r   objectr   r   rC   r   r   BaseExceptionr   r   r   r   r   r2   r2   r2   r3   r9      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   objr6   zunknown locationr+   )r\   r   )r   r   r   r2   r2   r3   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
 edddZdS )	CollectorzBase class of all collectors.

    Collector create children through `collect()` and thus iteratively build
    the collection tree.
    c                   @   s   e Zd ZdZdS )zCollector.CollectErrorz6An error during collection, contains a custom message.NrA   rJ   rb   r   r2   r2   r2   r3   CollectError  s   r   )Itemr   ru   c                 C   s   t ddS )z;Collect children (items and collectors) for this collector.ZabstractNNotImplementedErrorrs   r2   r2   r3   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   re   r   r   argsr   )rK   r   excr   r2   r2   r3   r     s    zCollector.repr_failurec                 C   sB   t | dr<|j}|j| jd}||kr2|jtd}||S |jS )Nr5   r5   )Zexcludepath)hasattrr   cutr5   tracebackcutdirfilter)rK   r   r   Z
ntracebackr2   r2   r3   r   4  s    

zCollector._traceback_filterN)rA   rJ   rb   r   r   r   r   r   r   r   r   r   r   r   r   r   r2   r2   r2   r3   r     s   
r   r%   )rf   r5   r)   c                 C   s@   | j D ]4}t|||krt||}|dkr2dn|  S qd S )NrF   r,   )Z_initialpathsr"   r   relative_to)rf   r5   Zinitial_pathrelr2   r2   r3   _check_initialpaths_for_relpath>  s
    
r   c                       s   e Zd 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 )FSCollectorz%Base class for filesystem collectors.Nr%   )	r6   path_or_parentr5   rH   rd   re   rf   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 )Nrj   )rH   rd   re   rf   r(   r5   )r{   r9   r   r   r   rB   rk   rH   r5   r   r7   r   replacer   sepr.   rf   re   Zrootpathr   rZ   rP   )
rK   r6   r   r5   rH   rd   re   rf   r(   r   r_   r2   r3   rP   I  sH    


zFSCollector.__init__)r6   r5   c                   s   t  jf |||d|S )zThe public constructor.)rd   r6   r5   )rZ   rq   )rp   rd   r6   r5   rM   r_   r2   r3   rq     s    
zFSCollector.from_parentos.PathLike[str]rj   c                 C   s   t jtdd | j|S Nr   r<   )r>   r?   r   rf   rr   )rK   r6   r2   r2   r3   rr     s    zFSCollector.gethookproxy)r5   r)   c                 C   s   t jtdd | j|S r   )r>   r?   r   rf   
isinitpath)rK   r5   r2   r2   r3   r     s    zFSCollector.isinitpath)NNNNNNNN)rA   rJ   rb   r   r   r   r   r   r9   r   r   rP   r   rq   rr   r   r   rc   r2   r2   r_   r3   r   F  s:           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   r2   r2   r2   r3   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   zBase class of all test invocation items.

    Note that for a single function there might be multiple test invocation items.
    Nr%   )re   rf   r(   r)   c                    s6   t  j||f|||d| g | _g | _|   d S )N)re   rf   r(   )rZ   rP   _report_sectionsZuser_properties-_check_item_and_collector_diamond_inheritance)rK   rH   rd   re   rf   r(   rM   r_   r2   r3   rP     s    zItem.__init__ru   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   rA   )rR   baser2   r2   r3   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/)	rk   r\   setattrjoin	__bases__r>   r?   rA   r$   )rK   rp   	attr_nameproblemsr2   r2   r3   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   rs   r2   r2   r3   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   )rK   r   r   r   r2   r2   r3   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   rs   r2   r2   r3   
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   rX   )r   r!   r   r6   rf   Z_node_location_to_relpathrk   r   )rK   r   r5   Z	relfspathr2   r2   r3   r     s
    zItem.location)NNNN)rA   rJ   rb   r   Znextitemr   r   r   rP   r   r   r   r   r   r   r   r   r   rc   r2   r2   r_   r3   r     s$       	$r   )Ir   r>   inspectr   pathlibr   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   Z_pytest._codeZ_pytestr   Z_pytest._code.coder   r   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__rd   r   r   r4   r8   rB   rC   rk   rE   r9   r   r}   r   r   r   r   r   r2   r2   r2   r3   <module>   sx   -	  `$.N