U
    42i@                     @  s  d Z ddlmZ ddl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 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,Z,e
G dd dZ-G dd dZ.e
ej/G d d! d!Z0G d"d# d#Z1d$d%d&d'd(d)Z2d*d&d+d,d-Z3d.d&d+d/d0Z4d1d&d+d2d3Z5d1d&d+d4d5Z6d1d6d+d7d8Z7d9d&d+d:d;Z8d%d%d<d=d>d?Z9d@d&d+dAdBZ:d@d&dCdDdEdFZ;edGdHd1dCdIdJdKZ<ed1dCdLdMdNZ=edOdPdCdQdRdSZ>dS )Tz?Add backward compatibility support for the legacy py path type.    )annotationsN)Path)Final)final)TYPE_CHECKING)SectionWrapper)Cache)LEGACY_PATHlegacy_path)Config)hookimpl)PytestPluginManager)check_ispytest)fixture)FixtureRequest)Session)MonkeyPatch)	Collector)Item)Node)HookRecorder)Pytester)	RunResult)TerminalReporter)TempPathFactoryc                   @  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dd	d
ddZ	e
ddddZe
ddddZe
dd Ze
dd Zejdd Ze
ddddZddddZd	dddZd	dd d!Zddd"d#Zddd$d%Zddd&d'Zd(d)d*d+d,Zddd-d.Zddd/d0Zddd1d2Zdd	dd4d5Zddd6d7Zddd8d9Zdddd:d;Zd<d=d>d?d@ZdAdB Z dCdDdEdFdGZ!dHdI Z"dJdK Z#dLdM Z$dNddOddPdQdRZ%dSddTdUZ&dSddVdWZ'd<ddXdYZ(d<ddZd[Z)dd]d^Z*d_d` Z+ddadbZ,dcd(d=dddedfZ-e.j/e.j/efdgdhZ0d3edidSddjdkZ1dSddldmZ2dndo Z3d3dpdSddqdrZ4dd(dtdudvdwdxZ5dd(dtdudydzd{Z6d(dd|d}Z7d(dd~dZ8d3S )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	_ispytestr   boolNone)pytesterr    returnc                C  s   t | || _d S N)r   	_pytester)selfr#   r     r(   6/tmp/pip-unpacked-wheel-7n2p7kht/_pytest/legacypath.py__init__7   s    zTestdir.__init__r	   r$   c                 C  s   t | jjS )z-Temporary directory where tests are executed.)r   r&   pathr'   r(   r(   r)   tmpdir;   s    zTestdir.tmpdirc                 C  s   t | jjS r%   )r   r&   Z_test_tmprootr-   r(   r(   r)   test_tmproot@   s    zTestdir.test_tmprootc                 C  s   | j jS r%   )r&   _requestr-   r(   r(   r)   requestD   s    zTestdir.requestc                 C  s   | j jS r%   r&   pluginsr-   r(   r(   r)   r3   H   s    zTestdir.pluginsc                 C  s   || j _d S r%   r2   )r'   r3   r(   r(   r)   r3   L   s    r   c                 C  s   | j jS r%   )r&   Z_monkeypatchr-   r(   r(   r)   monkeypatchP   s    zTestdir.monkeypatchr   c                 C  s   | j |S )z(See :meth:`Pytester.make_hook_recorder`.)r&   make_hook_recorder)r'   pluginmanagerr(   r(   r)   r5   T   s    zTestdir.make_hook_recorderc                 C  s
   | j  S )zSee :meth:`Pytester.chdir`.)r&   chdirr-   r(   r(   r)   r7   X   s    zTestdir.chdirc                 C  s
   | j  S r%   )r&   Z	_finalizer-   r(   r(   r)   finalize\   s    zTestdir.finalizec                 O  s.   |r| dsd| }t| jj|f||S )zSee :meth:`Pytester.makefile`..)
startswithr   r&   makefile)r'   extargskwargsr(   r(   r)   r;   _   s    zTestdir.makefilec                 C  s   t | j|S )z"See :meth:`Pytester.makeconftest`.)r   r&   makeconftestr'   sourcer(   r(   r)   r?   k   s    zTestdir.makeconftestc                 C  s   t | j|S )zSee :meth:`Pytester.makeini`.)r   r&   makeinir@   r(   r(   r)   rB   o   s    zTestdir.makeinistrr   )rA   r$   c                 C  s   | j |S )zSee :meth:`Pytester.getinicfg`.)r&   	getinicfgr@   r(   r(   r)   rD   s   s    zTestdir.getinicfgc                 C  s   t | j|S )z'See :meth:`Pytester.makepyprojecttoml`.)r   r&   makepyprojecttomlr@   r(   r(   r)   rE   w   s    zTestdir.makepyprojecttomlc                 O  s   t | jj||S )z See :meth:`Pytester.makepyfile`.)r   r&   
makepyfiler'   r=   r>   r(   r(   r)   rF   {   s    zTestdir.makepyfilec                 O  s   t | jj||S )z!See :meth:`Pytester.maketxtfile`.)r   r&   maketxtfilerG   r(   r(   r)   rH      s    zTestdir.maketxtfileNc                 C  s   | j |S )z#See :meth:`Pytester.syspathinsert`.)r&   syspathinsertr'   r,   r(   r(   r)   rI      s    zTestdir.syspathinsertc                 C  s   t | j|S )zSee :meth:`Pytester.mkdir`.)r   r&   mkdirr'   namer(   r(   r)   rK      s    zTestdir.mkdirc                 C  s   t | j|S )zSee :meth:`Pytester.mkpydir`.)r   r&   mkpydirrL   r(   r(   r)   rN      s    zTestdir.mkpydirc                 C  s   t | j|S )z"See :meth:`Pytester.copy_example`.)r   r&   copy_examplerL   r(   r(   r)   rO      s    zTestdir.copy_exampler   zItem | Collector | Noneconfigr$   c                 C  s   | j ||S )zSee :meth:`Pytester.getnode`.)r&   getnode)r'   rQ   argr(   r(   r)   rR      s    zTestdir.getnodec                 C  s   | j |S )z!See :meth:`Pytester.getpathnode`.)r&   getpathnoderJ   r(   r(   r)   rT      s    zTestdir.getpathnodezlist[Item | Collector]z
list[Item])colitemsr$   c                 C  s   | j |S )zSee :meth:`Pytester.genitems`.)r&   genitems)r'   rU   r(   r(   r)   rV      s    zTestdir.genitemsc                 C  s   | j |S )zSee :meth:`Pytester.runitem`.)r&   runitemr@   r(   r(   r)   rW      s    zTestdir.runitemc                 G  s   | j j|f| S )z&See :meth:`Pytester.inline_runsource`.)r&   inline_runsource)r'   rA   Zcmdlineargsr(   r(   r)   rX      s    zTestdir.inline_runsourcec                 G  s   | j j| S )z%See :meth:`Pytester.inline_genitems`.)r&   inline_genitemsr'   r=   r(   r(   r)   rY      s    zTestdir.inline_genitemsr(   r3   no_reraise_ctrlc)r\   c                G  s   | j j|||dS )z See :meth:`Pytester.inline_run`.r[   )r&   
inline_run)r'   r3   r\   r=   r(   r(   r)   r]      s
      zTestdir.inline_runr   c                 O  s   | j j||S )z)See :meth:`Pytester.runpytest_inprocess`.)r&   runpytest_inprocessrG   r(   r(   r)   r^      s    zTestdir.runpytest_inprocessc                 O  s   | j j||S )zSee :meth:`Pytester.runpytest`.)r&   	runpytestrG   r(   r(   r)   r_      s    zTestdir.runpytestc                 G  s   | j j| S )z!See :meth:`Pytester.parseconfig`.)r&   parseconfigrZ   r(   r(   r)   r`      s    zTestdir.parseconfigc                 G  s   | j j| S )z$See :meth:`Pytester.parseconfigure`.)r&   parseconfigurerZ   r(   r(   r)   ra      s    zTestdir.parseconfigure	test_funcc                 C  s   | j ||S )zSee :meth:`Pytester.getitem`.)r&   getitem)r'   rA   funcnamer(   r(   r)   rc      s    zTestdir.getitemc                 C  s   | j |S )zSee :meth:`Pytester.getitems`.)r&   getitemsr@   r(   r(   r)   re      s    zTestdir.getitemsc                 C  s   | j j|||dS )z"See :meth:`Pytester.getmodulecol`.)
configargswithinit)r&   getmodulecol)r'   rA   rf   rg   r(   r(   r)   rh      s
      zTestdir.getmodulecolr   )modcolrM   r$   c                 C  s   | j ||S )z%See :meth:`Pytester.collect_by_name`.)r&   collect_by_name)r'   ri   rM   r(   r(   r)   rj      s    zTestdir.collect_by_namec                 K  s   | j j||||f|S )zSee :meth:`Pytester.popen`.)r&   popen)r'   cmdargsstdoutstderrstdinkwr(   r(   r)   rk      s    	zTestdir.popentimeoutro   c                G  s   | j j|||dS )zSee :meth:`Pytester.run`.rq   )r&   run)r'   rr   ro   rl   r(   r(   r)   rs      s    zTestdir.runc                 C  s   | j |S )zSee :meth:`Pytester.runpython`.)r&   	runpython)r'   scriptr(   r(   r)   rt      s    zTestdir.runpythonc                 C  s   | j |S )z!See :meth:`Pytester.runpython_c`.)r&   runpython_c)r'   commandr(   r(   r)   rv      s    zTestdir.runpython_c)rr   c                G  s   | j j|d|iS )z*See :meth:`Pytester.runpytest_subprocess`.rr   )r&   runpytest_subprocess)r'   rr   r=   r(   r(   r)   rx      s    zTestdir.runpytest_subprocess      $@floatzpexpect.spawn)stringexpect_timeoutr$   c                 C  s   | 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)cmdr|   r$   c                 C  s   | j j||dS )zSee :meth:`Pytester.spawn`.r}   )r&   spawn)r'   r   r|   r(   r(   r)   r      s    zTestdir.spawnc                 C  s   d| j dS )Nz	<Testdir >)r.   r-   r(   r(   r)   __repr__   s    zTestdir.__repr__c                 C  s
   t | jS r%   )rC   r.   r-   r(   r(   r)   __str__   s    zTestdir.__str__)N)N)rb   )r(   F)ry   )ry   )9__name__
__module____qualname____doc__Z__test__r   r   __annotations__r   r*   propertyr.   r/   r1   r3   setterr4   r5   r7   r8   r;   r?   rB   rD   rE   rF   rH   rI   rK   rN   rO   rR   rT   rV   rW   rX   rY   r]   r^   r_   r`   ra   rc   re   rh   rj   
subprocessPIPErk   rs   rt   rv   rx   r~   r   r   r   r(   r(   r(   r)   r   )   st   






r   c                   @  s$   e Zd ZeedddddZdS )LegacyTestdirPluginr   r   )r#   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      s   r   c                   @  sT   e Zd ZU dZded< ddddddd	d
ZdddddddZddddZdS )TempdirFactorya  Backward compatibility wrapper that implements ``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>`.

    r   _tmppath_factoryFr   r!   r"   )tmppath_factoryr    r$   c                C  s   t | || _d S r%   )r   r   )r'   r   r    r(   r(   r)   r*     s    zTempdirFactory.__init__TrC   r	   )basenamenumberedr$   c                 C  s   t | j|| S )zOSame as :meth:`TempPathFactory.mktemp`, but returns a ``py.path.local`` object.)r   r   mktempresolve)r'   r   r   r(   r(   r)   r     s    zTempdirFactory.mktempr+   c                 C  s   t | j  S )zTSame as :meth:`TempPathFactory.getbasetemp`, but returns a ``py.path.local`` object.)r   r   getbasetempr   r-   r(   r(   r)   r   #  s    zTempdirFactory.getbasetempN)T)r   r   r   r   r   r*   r   r   r(   r(   r(   r)   r   
  s   

r   c                   @  sB   e Zd ZeedddddddZeedd	d
ddZdS )LegacyTmpdirPluginsession)Zscoper   r   )r1   r$   c                 C  s   | j jS )zFReturn a :class:`pytest.TempdirFactory` instance for the test session.)rQ   _tmpdirhandler)r1   r(   r(   r)   tmpdir_factory)  s    z!LegacyTmpdirPlugin.tmpdir_factoryr   r	   )tmp_pathr$   c                 C  s   t | S )a=  Return a temporary directory (as `legacy_path`_ object)
        which is unique to each test function invocation.
        The temporary directory is created as a subdirectory
        of the base temporary directory, with configurable retention,
        as discussed in :ref:`temporary directory location and retention`.

        .. 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.   0  s    zLegacyTmpdirPlugin.tmpdirN)r   r   r   r   r   r   r.   r(   r(   r(   r)   r   (  s   r   r   rC   r	   )r'   rM   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   rK   rL   r(   r(   r)   Cache_makedirC  s    r   r   )r'   r$   c                 C  s
   t | jS )zO(deprecated) The file system path of the test module which collected this test.r   r,   r-   r(   r(   r)   FixtureRequest_fspathK  s    r   r   c                 C  s
   t | jS )zThe directory from which pytest was invoked.

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

    :type: LEGACY_PATH
    r   Z	startpathr-   r(   r(   r)   TerminalReporter_startdirP  s    r   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   rC   Zinvocation_paramsdirr-   r(   r(   r)   Config_invocation_dirZ  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   rC   Zrootpathr-   r(   r(   r)   Config_rootdire  s    r   zLEGACY_PATH | Nonec                 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   rC   r-   r(   r(   r)   Config_inifileo  s    r   r   c                 C  s
   t | jS )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_startdiry  s    r   zstr | list[str])rM   typevaluec                   s\   |dkrH| j d k	st| j j t|tr2t|n|} fdd|D S td| |d S )Npathlistc                   s   g | ]}t t | qS r(   )r   rC   ).0xZdpr(   r)   
<listcomp>  s     z/Config__getini_unknown_type.<locals>.<listcomp>zunknown configuration type: )r   AssertionErrorparent
isinstancerC   shlexsplit
ValueError)r'   rM   r   r   Zinput_valuesr(   r   r)   Config__getini_unknown_type  s    r   r   c                 C  s
   t | jS )z4(deprecated) returns a legacy_path copy of self.pathr   r-   r(   r(   r)   Node_fspath  s    r   r"   )r'   r   r$   c                 C  s   t || _d S r%   )r   r,   )r'   r   r(   r(   r)   Node_fspath_set  s    r   T)Ztryfirst)early_configr$   c                 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ZraisingfspathZstartdirZinvocation_dirrootdirZinifileZ_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   rP   c                 C  sn   | j drjt }| |j z
| j}W n tk
r<   Y n X t|dd}|j| d|dd | j 	t
d dS )	zKInstalls the LegacyTmpdirPlugin if the ``tmpdir`` plugin is also installed.r.   Tr   r   Fr   zlegacypath-tmpdirN)r6   Z
has_pluginr   r   r   Z_tmp_path_factoryAttributeErrorr   r   registerr   )rQ   r   Ztmp_path_factoryr   r(   r(   r)   pytest_configure  s    
r   objectr   )pluginmanagerr$   c                 C  s,   | | dk}|r(|ts(|td d S )Nr#   zlegacypath-pytester)Z
get_pluginZis_registeredr   r   )r   r   Zis_pytesterr(   r(   r)   pytest_plugin_registered  s    r   )?r   
__future__r   Zdataclassespathlibr   r   r   typingr   r   r   Z	iniconfigr   Z_pytest.cacheproviderr   Z_pytest.compatr	   r   Z_pytest.configr   r   r   Z_pytest.deprecatedr   Z_pytest.fixturesr   r   Z_pytest.mainr   Z_pytest.monkeypatchr   Z_pytest.nodesr   r   r   Z_pytest.pytesterr   r   r   Z_pytest.terminalr   Z_pytest.tmpdirr   Zpexpectr   r   Z	dataclassr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r(   r(   r)   <module>   sl    T



