a
    ˆÏ?e!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	�rnd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%ƒZ3ee4ed&œd'd(„Z5eed)œd*d+„Z6e)ed)œd,d-„Z7eed)œd.d/„Z8eed)œd0d1„Z9eee d)œd2d3„Z:eed)œd4d5„Z;e4e4e
e4ee4 f d6œd7d8„Z<e#ed)œd9d:„Z=e#edd;œd<d=„Z>ed>d?�edd@œdAdB„ƒZ?eeddCœdDdE„ƒZ@eeAeddFœdGdH„ƒZBdS )Iz?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œee	ddœd	d
„Z
eedœdd„ƒZeedœdd„ƒZedd„ ƒZedd„ ƒZej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„Zedœdd „Zedœd!d"„Zeed#œd$d%„Zedœd&d'„Zedœd(d)„Zedœd*d+„Z dqddœd,d-„Z!edœd.d/„Z"edœd0d1„Z#dredœd2d3„Z$e%e&e'e(e)f  d4œd5d6„Z*d7d8„ Z+e,e'e(e)f  e,e( d9œd:d;„Z-d<d=„ Z.d>d?„ Z/d@dA„ Z0dBddCœe	dDœdEdF„Z1e2dœdGdH„Z3e2dœdIdJ„Z4e%dœdKdL„Z5e%dœdMdN„Z6dsdPdQ„Z7dRdS„ Z8dtdTdU„Z9e)ee&e'e(e)f  dVœdWdX„Z:e;j<e;j<efdYdZ„Z=ded[œe2dœd\d]„Z>e2dœd^d_„Z?d`da„ Z@ddbœe2dœdcdd„ZAdueeBdfdgœdhdi„ZCdveeBdfdjœdkdl„ZDedœdmdn„ZEedœdodp„ZFdS )wÚ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©Ú	_ispytestN)Úpytesterr"   Úreturnc                C   s   t |ƒ || _d S ©N)r   Ú	_pytester)Úselfr#   r"   © r(   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/_pytest/legacypath.pyÚ__init__6   s    zTestdir.__init__©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)   ÚrequestC   s    zTestdir.requestc                 C   s   | j jS r%   ©r&   Úpluginsr-   r(   r(   r)   r3   G   s    zTestdir.pluginsc                 C   s   || j _d S r%   r2   )r'   r3   r(   r(   r)   r3   K   s    c                 C   s   | j jS r%   )r&   Z_monkeypatchr-   r(   r(   r)   ÚmonkeypatchO   s    zTestdir.monkeypatchc                 C   s   | j  |¡S )z(See :meth:`Pytester.make_hook_recorder`.)r&   Úmake_hook_recorder)r'   Úpluginmanagerr(   r(   r)   r5   S   s    zTestdir.make_hook_recorderc                 C   s
   | j  ¡ S )zSee :meth:`Pytester.chdir`.)r&   Úchdirr-   r(   r(   r)   r7   W   s    zTestdir.chdirc                 C   s
   | j  ¡ S )zSee :meth:`Pytester._finalize`.)r&   Z	_finalizer-   r(   r(   r)   Úfinalize[   s    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)   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)rA   r$   c                 C   s   | j  |¡S )zSee :meth:`Pytester.getinicfg`.)r&   Ú	getinicfgr@   r(   r(   r)   rC   s   s    zTestdir.getinicfgc                 C   s   t | j |¡ƒS )z'See :meth:`Pytester.makepyprojecttoml`.)r   r&   Úmakepyprojecttomlr@   r(   r(   r)   rD   w   s    zTestdir.makepyprojecttomlc                 O   s   t | jj|i |¤ŽƒS )z See :meth:`Pytester.makepyfile`.)r   r&   Ú
makepyfile©r'   r=   r>   r(   r(   r)   rE   {   s    zTestdir.makepyfilec                 O   s   t | jj|i |¤ŽƒS )z!See :meth:`Pytester.maketxtfile`.)r   r&   ÚmaketxtfilerF   r(   r(   r)   rG      s    zTestdir.maketxtfilec                 C   s   | j  |¡S )z#See :meth:`Pytester.syspathinsert`.)r&   Úsyspathinsert©r'   r,   r(   r(   r)   rH   ƒ   s    zTestdir.syspathinsertc                 C   s   t | j |¡ƒS )zSee :meth:`Pytester.mkdir`.)r   r&   Úmkdir©r'   Únamer(   r(   r)   rJ   ‡   s    zTestdir.mkdirc                 C   s   t | j |¡ƒS )zSee :meth:`Pytester.mkpydir`.)r   r&   ÚmkpydirrK   r(   r(   r)   rM   ‹   s    zTestdir.mkpydirc                 C   s   t | j |¡ƒS )z"See :meth:`Pytester.copy_example`.)r   r&   Úcopy_examplerK   r(   r(   r)   rN   �   s    zTestdir.copy_example©Úconfigr$   c                 C   s   | j  ||¡S )zSee :meth:`Pytester.getnode`.)r&   Úgetnode)r'   rP   Úargr(   r(   r)   rQ   “   s    zTestdir.getnodec                 C   s   | j  |¡S )z!See :meth:`Pytester.getpathnode`.)r&   ÚgetpathnoderI   r(   r(   r)   rS   —   s    zTestdir.getpathnode)Úcolitemsr$   c                 C   s   | j  |¡S )zSee :meth:`Pytester.genitems`.)r&   Úgenitems)r'   rT   r(   r(   r)   rU   ›   s    zTestdir.genitemsc                 C   s   | j  |¡S )zSee :meth:`Pytester.runitem`.)r&   Úrunitemr@   r(   r(   r)   rV   Ÿ   s    zTestdir.runitemc                 G   s   | j j|g|¢R Ž S )z&See :meth:`Pytester.inline_runsource`.)r&   Úinline_runsource)r'   rA   Zcmdlineargsr(   r(   r)   rW   £   s    zTestdir.inline_runsourcec                 G   s   | j j|Ž S )z%See :meth:`Pytester.inline_genitems`.)r&   Úinline_genitems©r'   r=   r(   r(   r)   rX   §   s    zTestdir.inline_genitemsr(   ©r3   Úno_reraise_ctrlc)r[   c                G   s   | j j|||dœŽS )z See :meth:`Pytester.inline_run`.rZ   )r&   Ú
inline_run)r'   r3   r[   r=   r(   r(   r)   r\   «   s    ÿzTestdir.inline_runc                 O   s   | j j|i |¤ŽS )z)See :meth:`Pytester.runpytest_inprocess`.)r&   Úrunpytest_inprocessrF   r(   r(   r)   r]   ±   s    zTestdir.runpytest_inprocessc                 O   s   | j j|i |¤ŽS )zSee :meth:`Pytester.runpytest`.)r&   Ú	runpytestrF   r(   r(   r)   r^   µ   s    zTestdir.runpytestc                 G   s   | j j|Ž S )z!See :meth:`Pytester.parseconfig`.)r&   ÚparseconfigrY   r(   r(   r)   r_   ¹   s    zTestdir.parseconfigc                 G   s   | j j|Ž S )z$See :meth:`Pytester.parseconfigure`.)r&   ÚparseconfigurerY   r(   r(   r)   r`   ½   s    zTestdir.parseconfigureÚ	test_funcc                 C   s   | j  ||¡S )zSee :meth:`Pytester.getitem`.)r&   Úgetitem)r'   rA   Úfuncnamer(   r(   r)   rb   Á   s    zTestdir.getitemc                 C   s   | j  |¡S )zSee :meth:`Pytester.getitems`.)r&   Úgetitemsr@   r(   r(   r)   rd   Å   s    zTestdir.getitemsc                 C   s   | j j|||d�S )z"See :meth:`Pytester.getmodulecol`.)Ú
configargsÚwithinit)r&   Úgetmodulecol)r'   rA   re   rf   r(   r(   r)   rg   É   s    ÿzTestdir.getmodulecol)ÚmodcolrL   r$   c                 C   s   | j  ||¡S )z%See :meth:`Pytester.collect_by_name`.)r&   Úcollect_by_name)r'   rh   rL   r(   r(   r)   ri   Ï   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)   rj   Õ   s    	zTestdir.popen©Útimeoutrn   c                G   s   | j j|||dœŽS )zSee :meth:`Pytester.run`.rp   )r&   Úrun)r'   rq   rn   rk   r(   r(   r)   rr   à   s    zTestdir.runc                 C   s   | j  |¡S )zSee :meth:`Pytester.runpython`.)r&   Ú	runpython)r'   Úscriptr(   r(   r)   rs   ä   s    zTestdir.runpythonc                 C   s   | j  |¡S )z!See :meth:`Pytester.runpython_c`.)r&   Úrunpython_c)r'   Úcommandr(   r(   r)   ru   è   s    zTestdir.runpython_c)rq   c                G   s   | j j|d|iŽS )z*See :meth:`Pytester.runpytest_subprocess`.rq   )r&   Úrunpytest_subprocess)r'   rq   r=   r(   r(   r)   rw   ì   s    zTestdir.runpytest_subprocessç      $@zpexpect.spawn)ÚstringÚexpect_timeoutr$   c                 C   s   | j j||d�S )z"See :meth:`Pytester.spawn_pytest`.©rz   )r&   Úspawn_pytest)r'   ry   rz   r(   r(   r)   r|   ð   s    zTestdir.spawn_pytest)Úcmdrz   r$   c                 C   s   | j j||d�S )zSee :meth:`Pytester.spawn`.r{   )r&   Úspawn)r'   r}   rz   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%   )Ústrr.   r-   r(   r(   r)   Ú__str__ý   s    zTestdir.__str__)N)N)ra   )r(   F)rx   )rx   )GÚ__name__Ú
__module__Ú__qualname__Ú__doc__Z__test__r   r   Ú__annotations__r    Úboolr*   Úpropertyr
   r.   r/   r1   r3   Úsetterr   r4   r   r5   r7   r8   r;   r?   rB   r�   r   rC   rD   rE   rG   rH   rJ   rM   rN   r   r   r   r   r   rQ   rS   r   rU   rV   rW   rX   r\   r   r]   r^   r_   r`   rb   rd   rg   ri   Ú
subprocessÚPIPErj   rr   rs   ru   rw   Úfloatr|   r~   r€   r‚   r(   r(   r(   r)   r   (   s€   



 

þ	û
 ÿþr   c                   @   s$   e Zd Zeeeedœdd„ƒƒZdS )ÚLegacyTestdirPlugin)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(   r)   rŽ     s   rŽ   c                   @   sT   e Zd ZU dZeed< ddœeeddœdd„Zdeee	d
œdd„Z
e	dœ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!   N)Útmppath_factoryr"   r$   c                C   s   t |ƒ || _d S r%   )r   r’   )r'   r“   r"   r(   r(   r)   r*     s    zTempdirFactory.__init__T)ÚbasenameÚnumberedr$   c                 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–   #  s    zTempdirFactory.mktempr+   c                 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˜   '  s    zTempdirFactory.getbasetemp)T)rƒ   r„   r…   r†   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�eedœdd„ƒƒZeeee	dœdd„ƒƒZ
d	S )
ÚLegacyTmpdirPluginÚsession)Zscope)r1   r$   c                 C   s   | j jS )zFReturn a :class:`pytest.TempdirFactory` instance for the test session.)rP   Ú_tmpdirhandler)r1   r(   r(   r)   Útmpdir_factory-  s    z!LegacyTmpdirPlugin.tmpdir_factory)Útmp_pathr$   c                 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'   rL   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   rJ   rK   r(   r(   r)   ÚCache_makedirL  s    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_fspathT  s    r    c                 C   s
   t | jƒS )zŒThe 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_startdirY  s    r¢   c                 C   s   t t| jjƒƒS )z¸The 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�   Zinvocation_paramsÚdirr-   r(   r(   r)   ÚConfig_invocation_dirc  s    r¤   c                 C   s   t t| jƒƒS )z�The path to the :ref:`rootdir <rootdir>`.

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

    :type: LEGACY_PATH
    )r   r�   Zrootpathr-   r(   r(   r)   ÚConfig_rootdirn  s    r¥   c                 C   s   | j rtt| j ƒƒS dS )z�The 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   s
   t | jƒS )z‡The 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‚  s    r¨   )rL   ÚtypeÚvaluec                    s\   |dkrH| j d usJ ‚| 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   r�   )Ú.0Úx©Zdpr(   r)   Ú
<listcomp>”  ó    z/Config__getini_unknown_type.<locals>.<listcomp>zunknown configuration type: )r¦   ÚparentÚ
isinstancer�   ÚshlexÚsplitÚ
ValueError)r'   rL   r©   rª   Zinput_valuesr(   r®   r)   ÚConfig__getini_unknown_typeŒ  s    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$   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Â   rO   c                 C   sl   | j  d¡rhtƒ }|  |j¡ z
| j}W n ty:   Y n 0 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™   )rP   rÁ   Ztmp_path_factoryr›   r(   r(   r)   Úpytest_configureÂ  s    
rÅ   )ÚpluginÚmanagerr$   c                 C   s,   | |  d¡u }|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È   )Cr†   Zdataclassesr³   r‹   Úpathlibr   Útypingr   r   r   r   Z	iniconfigr   Z_pytest.cacheproviderr   Z_pytest.compatr	   r
   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typing_extensionsr   Zpexpectr   rŽ   Z	dataclassr‘   r™   r�   rž   r    r¢   r¤   r¥   r§   r¨   r¶   r·   r¸   rÂ   rÅ   ÚobjectrÈ   r(   r(   r(   r)   Ú<module>   sr    Y 


ÿ