o
    hg                     @  s  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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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+ d dl)m,Z, d dl-m.Z. d dl/m0Z0 d d l1m2Z2 d d!l3m4Z4 erd d"l5m6Z6 d d#l7m8Z8 d$Z9eej:j;Z<ed%Z=dLd.d/Z>ed0d1d2Z?G d3d4 d4ej@ZAG d5d1 d1ejBeAd6ZCdMd9d:ZDG d;d< d<eCejBZEe
d=d>dNdBdCZFG dDdE dEeEejBZGG dFdG dGeGejBZHG dHdI dIeGejBZIG dJdK dKeCejBZJdS )O    )annotationsN)Callable)Iterable)Iterator)MutableMapping)cached_property)	lru_cache)Path)Any)cast)NoReturn)overload)TYPE_CHECKING)TypeVar)getfslineno)ExceptionInfo)TerminalRepr)	Traceback)TracebackStyle)LEGACY_PATH)	signature)Config)ConftestImportFailure)_check_path)NODE_CTOR_FSPATH_ARG)Mark)MarkDecorator)NodeKeywords)fail)absolutepath)Stash)PytestWarning)Self)Session/_T	node_type
type[Node]pathPath | NonefspathLEGACY_PATH | Nonereturnr	   c                 C  sR   |d urt jtj| jddd |d ur|d urt|| |S |d us%J t|S )N)node_type_name   )
stacklevel)warningswarnr   format__name__r   r	   )r&   r(   r*    r4   N/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/nodes.py_imply_path<   s   
r6   	_NodeTypeNode)boundc                      s,   e Zd ZdZdddZd fd	d
Z  ZS )NodeMetaa  Metaclass used by :class:`Node` to enforce that direct construction raises
    :class:`Failed`.

    This behaviour supports the indirection introduced with :meth:`Node.from_parent`,
    the named constructor to be used instead of direct construction. The design
    decision to enforce indirection with :class:`NodeMeta` was made as a
    temporary aid for refactoring the collection tree, which was diagnosed to
    have :class:`Node` objects whose creational patterns were overly entangled.
    Once the refactoring is complete, this metaclass can be removed.

    See https://github.com/pytest-dev/pytest/projects/3 for an overview of the
    progress on detangling the :class:`Node` classes.
    r,   r   c                 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)r2   
__module__r3   r   )clskkwmsgr4   r4   r5   __call__c   s   zNodeMeta.__call__r@   type[_T]r%   c              
     s   z
t  j|i |W S  tyC   tt| d  fdd| D }ddlm} t	||  dt
| d t  j|i | Y S w )N__init__c                   s    i | ]\}}| j v r||qS r4   )
parameters).0rA   vsigr4   r5   
<dictcomp>q   s     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.)superrD   	TypeErrorr   getattritemswarning_typesrN   r0   r1   set)r@   rA   rB   known_kwrN   	__class__rJ   r5   _createl   s   	zNodeMeta._create)r,   r   )r@   rE   r,   r%   )r3   r?   __qualname____doc__rD   rX   __classcell__r4   r4   rV   r5   r:   T   s    
	r:   c                   @  sB  e Zd ZU dZded< dZ						dbdcddZeddddZe	deddZ
dfddZdgd!d"Ze	dfd#d$Zdhd&d'Zdid(d)Zdid*d+Zdjd-d.Zdkd0d1Zdldmd7d8Zdndod:d;Z	dndpd=d>Zedqd@dAZedrdDdAZdndsdEdAZdtdGdHZdudJdKZdvdNdOZdwdSdTZdxdXdYZ	dndyd]d^Z	dndzd`daZdS ){r8   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.
    r   r*   )__dict___nodeid_storeconfigr=   parentr(   sessionNr=   strr`   Node | Noner_   Config | Nonera   Session | Noner+   r(   r)   nodeid
str | Noner,   Nonec                 C  s   || _ || _|r|| _n
|std|j| _|r|| _n
|s"td|j| _|d u r4|d u r4t|dd }tt| ||d| _t	| | _
g | _t | _|d urXd|vsTJ || _n| js_td| jjd | j  | _t | _| j| _d S )Nz!config or parent must be providedz"session or parent must be providedr(   r*   z::()z!nodeid or parent must be providedz::)r=   r`   r_   rP   ra   rQ   r6   typer(   r   keywordsown_markersrT   extra_keyword_matchesr]   rf   r    stashr^   )selfr=   r`   r_   ra   r*   r(   rf   r4   r4   r5   rF      s4   
zNode.__init__r"   c                 K  s4   d|v rt dd|v rt d| jd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_parentra   z/session is not a valid argument for from_parentr`   Nr4   )rP   rX   )r@   r`   rB   r4   r4   r5   from_parent   s
   zNode.from_parentpluggy.HookRelayc                 C  s   | j | jS )z6fspath-sensitive hook proxy used to call pytest hooks.)ra   gethookproxyr(   ro   r4   r4   r5   ihook   s   z
Node.ihookc                 C  s   d | jjt| dd S )Nz<{} {}>r=   )r2   rW   r3   rQ   rs   r4   r4   r5   __repr__   s   zNode.__repr__warningWarningc                 C  sN   t |tstd|t| \}}|dusJ 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.
        z8warning must be an instance of Warning or subclass, got NrM   )categoryfilenamelineno)
isinstancerw   
ValueErrorget_fslocation_from_itemr0   warn_explicitrb   )ro   rv   r(   rz   r4   r4   r5   r1      s   

z	Node.warnc                 C  s   | j S )z;A ::-separated string denoting its collection tree address.)r]   rs   r4   r4   r5   rf     s   zNode.nodeidintc                 C  s
   t | jS N)hashr]   rs   r4   r4   r5   __hash__  s   
zNode.__hash__c                 C     d S r   r4   rs   r4   r4   r5   setup      z
Node.setupc                 C  r   r   r4   rs   r4   r4   r5   teardown#  r   zNode.teardownIterator[Node]c                 c  s*    | }|dur|V  |j }|dusdS dS )zIterate over all parent collectors starting from and including self
        up to the root of the collection tree.

        .. versionadded:: 8.1
        N)r`   )ro   r`   r4   r4   r5   iter_parents&  s   zNode.iter_parents
list[Node]c                 C  s4   g }| }|dur| | |j}|dus|  |S )zxReturn a list of all parent collectors starting from the root of the
        collection tree down to and including self.N)appendr`   reverse)ro   chainitemr4   r4   r5   	listchain1  s   
zNode.listchainTmarkerstr | MarkDecoratorr   boolc                 C  sp   ddl m} t|tr|}nt|trt||}ntd|| j|j< |r.| j	
|j dS | 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)_pytest.markr   r{   r   rb   rQ   r|   rk   r=   rl   r   markinsert)ro   r   r   r   marker_r4   r4   r5   
add_marker<  s   

zNode.add_markerIterator[Mark]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 )rM   Nr4   rH   xr4   r4   r5   	<genexpr>X  s    z$Node.iter_markers.<locals>.<genexpr>r<   )iter_markers_with_nodero   r=   r4   r4   r5   iter_markersR  s   zNode.iter_markersIterator[tuple[Node, Mark]]c                 c  sB    |   D ]}|jD ]}|du st|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.
        Nr=   )r   rl   rQ   )ro   r=   noder   r4   r4   r5   r   Z  s   

zNode.iter_markers_with_nodeMark | Nonec                 C  r   r   r4   r   r4   r4   r5   get_closest_markerg  r   zNode.get_closest_markerdefaultr   c                 C  r   r   r4   ro   r=   r   r4   r4   r5   r   j  r   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<   )nextr   r   r4   r4   r5   r   m  s   set[str]c                 C  s$   t  }|  D ]}||j q|S )z;Return a set of all extra keywords in self and any parents.)rT   r   updaterm   )ro   extra_keywordsr   r4   r4   r5   listextrakeywordsv  s   zNode.listextrakeywords	list[str]c                 C  s   dd |   D S )Nc                 S  s   g | ]}|j qS r4   r<   r   r4   r4   r5   
<listcomp>~  s    z"Node.listnames.<locals>.<listcomp>)r   rs   r4   r4   r5   	listnames}  s   zNode.listnamesfinCallable[[], object]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)ra   _setupstateaddfinalizer)ro   r   r4   r4   r5   r     s   zNode.addfinalizerr@   type[_NodeType]_NodeType | Nonec                 C  s$   |   D ]}t||r|  S qdS )zGet the closest 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   r{   )ro   r@   r   r4   r4   r5   	getparent  s
   
zNode.getparentexcinfoExceptionInfo[BaseException]r   c                 C  s   |j S r   )	traceback)ro   r   r4   r4   r5   _traceback_filter  s   zNode._traceback_filterstyleTracebackStyle | Noner   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|r+|j S | jddr7d}d}n	| j}|dkr@d}|d u rR| jddd	krPd	}nd}| j d
kr\d}nd}| j dkrgdnd}ztt | jjjk}W n ty   d}Y nw |jd|| jdd||||dS )Nr   )FixtureLookupErrorvalue	fulltraceFlongautotbstyleshortrM   T   
showlocals)funcargsabspathr   r   tbfiltertruncate_localstruncate_args)_pytest.fixturesr   r{   r   r   r   from_exceptioncauser   	Exceptionr>   
formatreprr_   	getoptionr   get_verbosityr	   osgetcwdinvocation_paramsdirOSErrorgetrepr)ro   r   r   r   r   r   r   r   r4   r4   r5   _repr_failure_py  sH   
zNode._repr_failure_pystr | TerminalReprc                 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   )ro   r   r   r4   r4   r5   repr_failure     zNode.repr_failure)NNNNNN)r=   rb   r`   rc   r_   rd   ra   re   r*   r+   r(   r)   rf   rg   r,   rh   )r`   r8   r,   r"   )r,   rq   )r,   rb   )rv   rw   r,   rh   )r,   r   r,   rh   )r,   r   )r,   r   )T)r   r   r   r   r,   rh   r   )r=   rg   r,   r   )r=   rg   r,   r   )r=   rb   r,   r   )r=   rb   r   r   r,   r   )r=   rb   r   r   r,   r   )r,   r   )r,   r   )r   r   r,   rh   )r@   r   r,   r   r   r   r,   r   )r   r   r   r   r,   r   )r   r   r   r   r,   r   )r3   r?   rY   rZ   __annotations__	__slots__rF   classmethodrp   propertyrt   ru   r1   rf   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r4   r4   r4   r5   r8      sT   
 =

%




	
	


	
=)	metaclassr   tuple[str | Path, int | None]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.
    * "path": just a path

    :rtype: A tuple of (str|Path, int) with filename and 0-based line number.
    locationNr   objr(   zunknown location)rQ   r   )r   r   r   r4   r4   r5   r}     s   
r}   c                   @  sD   e Zd ZdZG dd deZejdddZdddZ	dddZ
dS )	CollectorzBase class of all collectors.

    Collector create children through `collect()` and thus iteratively build
    the collection tree.
    c                   @     e Zd ZdZdS )zCollector.CollectErrorz6An error during collection, contains a custom message.Nr3   r?   rY   rZ   r4   r4   r4   r5   CollectError      r   r,   Iterable[Item | Collector]c                 C     t d)z;Collect children (items and collectors) for this collector.abstractNotImplementedErrorrs   r4   r4   r5   collect  s   zCollector.collectr   r   r   c                 C  sX   t |j| jr| jdds|j}t|jd S | jdd}|dkr%d}| 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   r_   r   rb   argsr   )ro   r   excr   r4   r4   r5   r     s   zCollector.repr_failurer   c                 C  sB   t | dr|j}|j| jd}||kr|jtd}||S |jS )Nr(   r(   )excludepath)hasattrr   cutr(   tracebackcutdirfilter)ro   r   r   
ntracebackr4   r4   r5   r     s   

zCollector._traceback_filterN)r,   r   )r   r   r,   r   r   )r3   r?   rY   rZ   r   r   abcabstractmethodr   r   r   r4   r4   r4   r5   r     s    
r   i  )maxsizeinitial_pathsfrozenset[Path]rg   c                 C  s6   || v rdS |j D ]}|| v rt||  S q	d S )N )parentsrb   relative_to)r   r(   r`   r4   r4   r5   _check_initialpaths_for_relpath"  s   
r   c                      sN   e Zd ZdZ								dd fddZedddd fddZ  ZS )FSCollectorz%Base class for filesystem collectors.Nr*   r+   path_or_parentPath | Node | Noner(   r)   r=   rg   r`   rc   r_   rd   ra   re   rf   r,   rh   c	           
        sD  |r t |tr|d u sJ tt|}nt |tr |d u sJ |}tt| ||d}|d u rV|j}|d urV|j|krVz|	|j}	W n	 t
yJ   Y nw t|	}|tjt}|| _|d u rf|d uscJ |j}|d u rzt| j	|jj}W n t
y   t|j|}Y nw |rtjtkr|tjt}t j||||||d d S )Nri   )r=   r`   r_   ra   rf   r(   )r{   r8   r   r  r	   r6   rj   r=   r(   r   r|   rb   replacer   sepSEPra   r_   rootpathr   _initialpathsrO   rF   )
ro   r*   r  r(   r=   r`   r_   ra   rf   relrV   r4   r5   rF   3  sL   


zFSCollector.__init__)r*   r(   r"   c                  s   t  jd|||d|S )zThe public constructor.)r`   r*   r(   Nr4   )rO   rp   )r@   r`   r*   r(   rB   rV   r4   r5   rp   i  s   
zFSCollector.from_parent)NNNNNNNN)r*   r+   r  r  r(   r)   r=   rg   r`   rc   r_   rd   ra   re   rf   rg   r,   rh   )r*   r+   r(   r)   r,   r"   )r3   r?   rY   rZ   rF   r   rp   r[   r4   r4   rV   r5   r  0  s    6r  c                   @  r   )FilezOBase class for collecting tests from a file.

    :ref:`non-python tests`.
    Nr   r4   r4   r4   r5   r
  v  r   r
  c                   @  r   )	Directorya  Base class for collecting files from a directory.

    A basic directory collector does the following: goes over the files and
    sub-directories in the directory and creates collectors for them by calling
    the hooks :hook:`pytest_collect_directory` and :hook:`pytest_collect_file`,
    after checking that they are not ignored using
    :hook:`pytest_ignore_collect`.

    The default directory collectors are :class:`~pytest.Dir` and
    :class:`~pytest.Package`.

    .. versionadded:: 8.0

    :ref:`custom directory collectors`.
    Nr   r4   r4   r4   r5   r  }  r   r  c                      sl   e Zd ZdZdZ				dd fddZdddZejdddZ	d ddZ
d!ddZed"ddZ  ZS )#ItemzBase class of all test invocation items.

    Note that for a single function there might be multiple test invocation items.
    Nr_   rd   ra   re   rf   rg   r,   rh   c                   s6   t  j||f|||d| g | _g | _|   d S )N)r_   ra   rf   )rO   rF   _report_sectionsuser_properties-_check_item_and_collector_diamond_inheritance)ro   r=   r`   r_   ra   rf   rB   rV   r4   r5   rF     s   zItem.__init__c                 C  sd   t | }d}t||drdS t||d ddd |jD }|r0t|j d| d	t dS dS )
z
        Check if the current type inherits from both File and Collector
        at the same time, emitting a warning accordingly (#8447).
        )_pytest_diamond_inheritance_warning_shownFNTz, c                 s  s     | ]}t |tr|jV  qd S r   )
issubclassr   r3   )rH   baser4   r4   r5   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   rQ   setattrjoin	__bases__r0   r1   r3   r!   )ro   r@   	attr_nameproblemsr4   r4   r5   r    s    
z2Item._check_item_and_collector_diamond_inheritancec                 C  r   )zRun the test case for this item.

        Must be implemented by subclasses.

        .. seealso:: :ref:`non-python tests`
        z,runtest must be implemented by Item subclassr   rs   r4   r4   r5   runtest  s   zItem.runtestwhenrb   keycontentc                 C  s   |r| j |||f dS 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   )ro   r  r  r  r4   r4   r5   add_report_section  s   zItem.add_report_section.tuple[os.PathLike[str] | str, int | None, str]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   r4   r4   r5   
reportinfo  r   zItem.reportinfotuple[str, int | None, str]c                 C  sF   |   }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   rM   )r  r   ra   _node_location_to_relpathrj   rb   )ro   r   r(   	relfspathr4   r4   r5   r     s
   zItem.location)NNNN)r_   rd   ra   re   rf   rg   r,   rh   r   )r  rb   r  rb   r  rb   r,   rh   )r,   r  )r,   r  )r3   r?   rY   rZ   nextitemrF   r  r   r   r  r  r  r   r   r[   r4   r4   rV   r5   r    s    

	
r  )r&   r'   r(   r)   r*   r+   r,   r	   )r   r8   r,   r   )r   r   r(   r	   r,   rg   )K
__future__r   r   collections.abcr   r   r   r   	functoolsr   r   r   pathlibr	   typingr
   r   r   r   r   r   r0   pluggy_pytest._code_pytestr   _pytest._code.coder   r   r   r   _pytest.compatr   r   _pytest.configr   r   _pytest.config.compatr   _pytest.deprecatedr   _pytest.mark.structuresr   r   r   _pytest.outcomesr   _pytest.pathlibr   _pytest.stashr    _pytest.warning_typesr!   typing_extensionsr"   _pytest.mainr#   r  __file__r`   r   r%   r6   r7   ABCMetar:   ABCr8   r}   r   r   r  r
  r  r  r4   r4   r4   r5   <module>   st   
,  
b/F