o
    h!B                  	   @   s  d 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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	rddl,m-Z- ddl.Z.eG dd dZ/G d d! d!Z0eej1G d"d# d#Z2G d$d% d%Z3d&ed'e4d(efd)d*Z5d&ed(efd+d,Z6d&e)d(efd-d.Z7d&ed(efd/d0Z8d&ed(efd1d2Z9d&ed(ee fd3d4Z:d&ed(efd5d6Z;d'e4d7e4d8e
e4ee4 f fd9d:Z<d&e#d(efd;d<Z=d&e#d8ed(dfd=d>Z>ed?d@dAed(dfdBdCZ?edDed(dfdEdFZ@edGeAdHed(dfdIdJZBdS )Kz?Add backward compatibility support for the legacy py path type.    N)Path)List)Optional)TYPE_CHECKING)Union)SectionWrapper)Cache)final)LEGACY_PATHlegacy_path)Config)hookimpl)PytestPluginManager)check_ispytest)fixture)FixtureRequest)Session)MonkeyPatch)	Collector)Item)Node)HookRecorder)Pytester)	RunResult)TerminalReporter)TempPathFactory)Finalc                	   @   s  e Zd ZU dZdZejZded< ejZded< dddede	d	d
fddZ
ed	efddZed	efddZedd Zedd Zejdd Zed	efddZd	efddZdtddZdtddZd	efddZd	efd d!Zd	efd"d#Zd$ed	efd%d&Zd	efd'd(Zd	efd)d*Zd	efd+d,Z dudtd-d.Z!d	efd/d0Z"d	efd1d2Z#dud	efd3d4Z$d5e%d	e&e'e(e)f  fd6d7Z*d8d9 Z+d:e,e'e(e)f  d	e,e( fd;d<Z-d=d> Z.d?d@ Z/dAdB Z0dCddDdEe	fdFdGZ1d	e2fdHdIZ3d	e2fdJdKZ4d	e%fdLdMZ5d	e%fdNdOZ6dvdQdRZ7dSdT Z8dwdUdVZ9dWe)dXed	e&e'e(e)f  fdYdZZ:e;j<e;j<efd[d\Z=d
ed]d	e2fd^d_Z>d	e2fd`daZ?dbdc Z@d
ddd	e2fdedfZA	gdxdhedieBd	djfdkdlZCdxdmedieBd	djfdndoZDd	efdpdqZEd	efdrdsZFd
S )yTestdirz
    Similar to :class:`Pytester`, but this class works with legacy legacy_path objects instead.

    All methods just forward to an internal :class:`Pytester` instance, converting results
    to `legacy_path` objects as necessary.
    Fr   CLOSE_STDINTimeoutExpired	_ispytestpytesterr"   returnNc                C      t | || _d S N)r   	_pytester)selfr#   r"    r)   H/var/www/html/ai/venv/lib/python3.10/site-packages/_pytest/legacypath.py__init__6   s   
zTestdir.__init__c                 C      t | jjS )z-Temporary directory where tests are executed.)r   r'   pathr(   r)   r)   r*   tmpdir:   s   zTestdir.tmpdirc                 C   r,   r&   )r   r'   _test_tmprootr.   r)   r)   r*   test_tmproot?      zTestdir.test_tmprootc                 C      | j jS r&   )r'   _requestr.   r)   r)   r*   requestC      zTestdir.requestc                 C   r3   r&   r'   pluginsr.   r)   r)   r*   r8   G   r6   zTestdir.pluginsc                 C   s   || j _d S r&   r7   )r(   r8   r)   r)   r*   r8   K   r2   c                 C   r3   r&   )r'   _monkeypatchr.   r)   r)   r*   monkeypatchO   r6   zTestdir.monkeypatchc                 C      | j |S )z(See :meth:`Pytester.make_hook_recorder`.)r'   make_hook_recorder)r(   pluginmanagerr)   r)   r*   r<   S   r2   zTestdir.make_hook_recorderc                 C   
   | j  S )zSee :meth:`Pytester.chdir`.)r'   chdirr.   r)   r)   r*   r?   W      
zTestdir.chdirc                 C   r>   )zSee :meth:`Pytester._finalize`.)r'   	_finalizer.   r)   r)   r*   finalize[   r@   zTestdir.finalizec                 O   s4   |r| dsd| }t| jj|g|R i |S )zSee :meth:`Pytester.makefile`..)
startswithr   r'   makefile)r(   extargskwargsr)   r)   r*   rE   _   s   zTestdir.makefilec                 C      t | j|S )z"See :meth:`Pytester.makeconftest`.)r   r'   makeconftestr(   sourcer)   r)   r*   rJ   k      zTestdir.makeconftestc                 C   rI   )zSee :meth:`Pytester.makeini`.)r   r'   makeinirK   r)   r)   r*   rN   o   rM   zTestdir.makeinirL   c                 C   r;   )zSee :meth:`Pytester.getinicfg`.)r'   	getinicfgrK   r)   r)   r*   rO   s   r2   zTestdir.getinicfgc                 C   rI   )z'See :meth:`Pytester.makepyprojecttoml`.)r   r'   makepyprojecttomlrK   r)   r)   r*   rP   w   rM   zTestdir.makepyprojecttomlc                 O      t | jj|i |S )z See :meth:`Pytester.makepyfile`.)r   r'   
makepyfiler(   rG   rH   r)   r)   r*   rR   {      zTestdir.makepyfilec                 O   rQ   )z!See :meth:`Pytester.maketxtfile`.)r   r'   maketxtfilerS   r)   r)   r*   rU      rT   zTestdir.maketxtfilec                 C   r;   )z#See :meth:`Pytester.syspathinsert`.)r'   syspathinsertr(   r-   r)   r)   r*   rV      r2   zTestdir.syspathinsertc                 C   rI   )zSee :meth:`Pytester.mkdir`.)r   r'   mkdirr(   namer)   r)   r*   rX      rM   zTestdir.mkdirc                 C   rI   )zSee :meth:`Pytester.mkpydir`.)r   r'   mkpydirrY   r)   r)   r*   r[      rM   zTestdir.mkpydirc                 C   rI   )z"See :meth:`Pytester.copy_example`.)r   r'   copy_examplerY   r)   r)   r*   r\      rM   zTestdir.copy_exampleconfigc                 C      | j ||S )zSee :meth:`Pytester.getnode`.)r'   getnode)r(   r]   argr)   r)   r*   r_         zTestdir.getnodec                 C   r;   )z!See :meth:`Pytester.getpathnode`.)r'   getpathnoderW   r)   r)   r*   rb      r2   zTestdir.getpathnodecolitemsc                 C   r;   )zSee :meth:`Pytester.genitems`.)r'   genitems)r(   rc   r)   r)   r*   rd      r2   zTestdir.genitemsc                 C   r;   )zSee :meth:`Pytester.runitem`.)r'   runitemrK   r)   r)   r*   re      r2   zTestdir.runitemc                 G   s   | j j|g|R  S )z&See :meth:`Pytester.inline_runsource`.)r'   inline_runsource)r(   rL   cmdlineargsr)   r)   r*   rf         zTestdir.inline_runsourcec                 G      | j j| S )z%See :meth:`Pytester.inline_genitems`.)r'   inline_genitemsr(   rG   r)   r)   r*   rj      r2   zTestdir.inline_genitemsr)   r8   no_reraise_ctrlcrm   c                G      | j j|||dS )z See :meth:`Pytester.inline_run`.rl   )r'   
inline_run)r(   r8   rm   rG   r)   r)   r*   ro      s   zTestdir.inline_runc                 O      | j j|i |S )z)See :meth:`Pytester.runpytest_inprocess`.)r'   runpytest_inprocessrS   r)   r)   r*   rq         zTestdir.runpytest_inprocessc                 O   rp   )zSee :meth:`Pytester.runpytest`.)r'   	runpytestrS   r)   r)   r*   rs      rr   zTestdir.runpytestc                 G   ri   )z!See :meth:`Pytester.parseconfig`.)r'   parseconfigrk   r)   r)   r*   rt      r2   zTestdir.parseconfigc                 G   ri   )z$See :meth:`Pytester.parseconfigure`.)r'   parseconfigurerk   r)   r)   r*   ru      r2   zTestdir.parseconfigure	test_funcc                 C   r^   )zSee :meth:`Pytester.getitem`.)r'   getitem)r(   rL   funcnamer)   r)   r*   rw      ra   zTestdir.getitemc                 C   r;   )zSee :meth:`Pytester.getitems`.)r'   getitemsrK   r)   r)   r*   ry      r2   zTestdir.getitemsc                 C   s   | j j|||dS )z"See :meth:`Pytester.getmodulecol`.)
configargswithinit)r'   getmodulecol)r(   rL   rz   r{   r)   r)   r*   r|      s   zTestdir.getmodulecolmodcolrZ   c                 C   r^   )z%See :meth:`Pytester.collect_by_name`.)r'   collect_by_name)r(   r}   rZ   r)   r)   r*   r~      s   zTestdir.collect_by_namec                 K   s   | j j||||fi |S )zSee :meth:`Pytester.popen`.)r'   popen)r(   cmdargsstdoutstderrstdinkwr)   r)   r*   r      s   	zTestdir.popentimeoutr   c                G   rn   )zSee :meth:`Pytester.run`.r   )r'   run)r(   r   r   r   r)   r)   r*   r      rh   zTestdir.runc                 C   r;   )zSee :meth:`Pytester.runpython`.)r'   	runpython)r(   scriptr)   r)   r*   r      r2   zTestdir.runpythonc                 C   r;   )z!See :meth:`Pytester.runpython_c`.)r'   runpython_c)r(   commandr)   r)   r*   r      r2   zTestdir.runpython_c)r   c                G   s   | j j|d|iS )z*See :meth:`Pytester.runpytest_subprocess`.r   )r'   runpytest_subprocess)r(   r   rG   r)   r)   r*   r      rr   zTestdir.runpytest_subprocess      $@stringexpect_timeoutzpexpect.spawnc                 C      | j j||dS )z"See :meth:`Pytester.spawn_pytest`.r   )r'   spawn_pytest)r(   r   r   r)   r)   r*   r      s   zTestdir.spawn_pytestcmdc                 C   r   )zSee :meth:`Pytester.spawn`.r   )r'   spawn)r(   r   r   r)   r)   r*   r      rM   zTestdir.spawnc                 C   s   d| j dS )Nz	<Testdir >)r/   r.   r)   r)   r*   __repr__      zTestdir.__repr__c                 C   
   t | jS r&   )strr/   r.   r)   r)   r*   __str__   s   
zTestdir.__str__)r$   Nr&   )rv   )r)   F)r   )G__name__
__module____qualname____doc____test__r   r   __annotations__r    boolr+   propertyr
   r/   r1   r5   r8   setterr   r:   r   r<   r?   rB   rE   rJ   rN   r   r   rO   rP   rR   rU   rV   rX   r[   r\   r   r   r   r   r   r_   rb   r   rd   re   rf   rj   ro   r   rq   rs   rt   ru   rw   ry   r|   r~   
subprocessPIPEr   r   r   r   r   floatr   r   r   r   r)   r)   r)   r*   r   (   s   
 




"


	

r   c                   @   s&   e Zd ZeededefddZdS )LegacyTestdirPluginr#   r$   c                 C   s   t | ddS )z
        Identical to :fixture:`pytester`, and provides an instance whose methods return
        legacy ``LEGACY_PATH`` objects instead when applicable.

        New code should avoid using :fixture:`testdir` in favor of :fixture:`pytester`.
        Tr!   )r   )r#   r)   r)   r*   testdir  s   	zLegacyTestdirPlugin.testdirN)r   r   r   staticmethodr   r   r   r   r)   r)   r)   r*   r     s    r   c                   @   s\   e Zd ZU dZeed< dddededdfd	d
Zddedede	fddZ
de	fddZdS )TempdirFactorya  Backward compatibility wrapper that implements :class:`py.path.local`
    for :class:`TempPathFactory`.

    .. note::
        These days, it is preferred to use ``tmp_path_factory``.

        :ref:`About the tmpdir and tmpdir_factory fixtures<tmpdir and tmpdir_factory>`.

    _tmppath_factoryFr!   tmppath_factoryr"   r$   Nc                C   r%   r&   )r   r   )r(   r   r"   r)   r)   r*   r+     s   
zTempdirFactory.__init__Tbasenamenumberedc                 C   s   t | j|| S )zTSame as :meth:`TempPathFactory.mktemp`, but returns a :class:`py.path.local` object.)r   r   mktempresolve)r(   r   r   r)   r)   r*   r   #  rT   zTempdirFactory.mktempc                 C   s   t | j  S )zYSame as :meth:`TempPathFactory.getbasetemp`, but returns a :class:`py.path.local` object.)r   r   getbasetempr   r.   r)   r)   r*   r   '  rr   zTempdirFactory.getbasetemp)T)r   r   r   r   r   r   r   r+   r   r
   r   r   r)   r)   r)   r*   r     s   
 

r   c                   @   sF   e Zd ZeedddedefddZeedede	fdd	Z
d
S )LegacyTmpdirPluginsession)scoper5   r$   c                 C   r3   )zFReturn a :class:`pytest.TempdirFactory` instance for the test session.)r]   _tmpdirhandler)r5   r)   r)   r*   tmpdir_factory-  s   z!LegacyTmpdirPlugin.tmpdir_factorytmp_pathc                 C   s   t | S )a  Return a temporary directory path object which is unique to each test
        function invocation, created as a sub directory of the base temporary
        directory.

        By default, a new base temporary directory is created each test session,
        and old bases are removed after 3 sessions, to aid in debugging. If
        ``--basetemp`` is used then it is cleared each session. See :ref:`base
        temporary directory`.

        The returned object is a `legacy_path`_ object.

        .. note::
            These days, it is preferred to use ``tmp_path``.

            :ref:`About the tmpdir and tmpdir_factory fixtures<tmpdir and tmpdir_factory>`.

        .. _legacy_path: https://py.readthedocs.io/en/latest/path.html
        r   )r   r)   r)   r*   r/   4  s   zLegacyTmpdirPlugin.tmpdirN)r   r   r   r   r   r   r   r   r   r
   r/   r)   r)   r)   r*   r   ,  s    r   r(   rZ   r$   c                 C   s   t | |S )z{Return a directory path object with the given name.

    Same as :func:`mkdir`, but returns a legacy py path instance.
    )r   rX   rY   r)   r)   r*   Cache_makedirL  s   r   c                 C   r   )zO(deprecated) The file system path of the test module which collected this test.r   r-   r.   r)   r)   r*   FixtureRequest_fspathT  r@   r   c                 C   r   )zThe directory from which pytest was invoked.

    Prefer to use ``startpath`` which is a :class:`pathlib.Path`.

    :type: LEGACY_PATH
    r   	startpathr.   r)   r)   r*   TerminalReporter_startdirY     
r   c                 C   s   t t| jjS )zThe directory from which pytest was invoked.

    Prefer to use :attr:`invocation_params.dir <InvocationParams.dir>`,
    which is a :class:`pathlib.Path`.

    :type: LEGACY_PATH
    )r   r   invocation_paramsdirr.   r)   r)   r*   Config_invocation_dirc  s   r   c                 C   s   t t| jS )zThe path to the :ref:`rootdir <rootdir>`.

    Prefer to use :attr:`rootpath`, which is a :class:`pathlib.Path`.

    :type: LEGACY_PATH
    )r   r   rootpathr.   r)   r)   r*   Config_rootdirn  s   r   c                 C   s   | j r
tt| j S dS )zThe path to the :ref:`configfile <configfiles>`.

    Prefer to use :attr:`inipath`, which is a :class:`pathlib.Path`.

    :type: Optional[LEGACY_PATH]
    N)inipathr   r   r.   r)   r)   r*   Config_inifilex  s   r   c                 C   r   )zThe path from which pytest was invoked.

    Prefer to use ``startpath`` which is a :class:`pathlib.Path`.

    :type: LEGACY_PATH
    r   r.   r)   r)   r*   Session_stardir  r   r   typevaluec                    sX   |dkr$| j d usJ | j j t|trt|n|} fdd|D S td| |)Npathlistc                    s   g | ]
}t t | qS r)   )r   r   ).0xdpr)   r*   
<listcomp>  s    z/Config__getini_unknown_type.<locals>.<listcomp>zunknown configuration type: )r   parent
isinstancer   shlexsplit
ValueError)r(   rZ   r   r   input_valuesr)   r   r*   Config__getini_unknown_type  s   r   c                 C   r   )z4(deprecated) returns a legacy_path copy of self.pathr   r.   r)   r)   r*   Node_fspath  r@   r   c                 C   s   t || _d S r&   )r   r-   )r(   r   r)   r)   r*   Node_fspath_set  r   r   T)tryfirstearly_configc                 C   s   t  }| |j |jtdtdd |jtdttdd |jt	dtt
dd |jtdttdd |jtdttdd |jtdttdd |jtdttdd |td	t |jtdtttdd d
S )zLMonkeypatch legacy path attributes in several classes, as early as possible.makedirFraisingfspathstartdirinvocation_dirrootdirinifile_getini_unknown_typeN)r   add_cleanupundosetattrr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   mpr)   r)   r*   pytest_load_initial_conftests  s   r   r]   c                 C   sp   | j dr6t }| |j z| j}W n	 ty   Y nw t|dd}|j| d|dd | j 	t
d dS dS )	zKInstalls the LegacyTmpdirPlugin if the ``tmpdir`` plugin is also installed.r/   Tr!   r   Fr   zlegacypath-tmpdirN)r=   
has_pluginr   r   r   _tmp_path_factoryAttributeErrorr   r   registerr   )r]   r   tmp_path_factoryr   r)   r)   r*   pytest_configure  s   
r   pluginmanagerc                 C   s4   | | du }|r|ts|td d S d S d S )Nr#   zlegacypath-pytester)
get_pluginis_registeredr   r   )r   r   is_pytesterr)   r)   r*   pytest_plugin_registered  s   r   )Cr   dataclassesr   r   pathlibr   typingr   r   r   r   	iniconfigr   _pytest.cacheproviderr   _pytest.compatr	   r
   r   _pytest.configr   r   r   _pytest.deprecatedr   _pytest.fixturesr   r   _pytest.mainr   _pytest.monkeypatchr   _pytest.nodesr   r   r   _pytest.pytesterr   r   r   _pytest.terminalr   _pytest.tmpdirr   typing_extensionsr   pexpectr   r   	dataclassr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   objectr   r)   r)   r)   r*   <module>   s~     Y 




