HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/_pytest/__pycache__/pytester.cpython-310.pyc
o

%we1��	@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddl#m$Z$ddl%m&Z&ddl%m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl.m0Z0ddl.m1Z1ddl2m3Z3ddl2m4Z4dd l2m5Z5dd!l2m6Z6dd"l2m7Z7dd#l2m8Z8dd$l9m:Z:dd%l;m<Z<dd&l=m>Z>dd'l=m?Z?dd(l@mAZAdd)lBmCZCdd*lDmEZEdd+lDmFZFdd,lGmHZHdd-lGmIZIdd.lGmJZJdd/lKmLZLdd0lKmMZMdd1lKmNZNdd2lOmPZPdd3lOmQZQdd4lRmSZSdd5lTmUZUe!�rwdd6lVmWZWdd7lVmXZXddlYZYd8gZZd9gZ[d:e:d;dfd<d=�Z\d>e4d;dfd?d@�Z]GdAdB�dB�Z^e>dCe?d;dDfdEdF��Z(GdGdD�dD�Z_dHee`d;ee`fdIdJ�Zae/GdKdL�dL��Zbe/GdMdN�dN��Zce>dmdPdQ��Zde>dRdS�dCe?d;e dRfdTdU��Zee>dCe?dVeSdWeCd;dXfdYdZ��Zfe>d;ed[fd\d]��Zge>d;ee4ddffd^d_��Zhe	�id`�Zje	�ida�Zke/Gdbdc�dc��ZlGddde�de�ZmGdfdg�dg�ZnGdhdi�di�Zoe/GdjdX�dX��ZpGdkdO�dO�ZqGdldR�dR�ZrdS)nzZ(Disabled by default) support for testing pytest and pytest plugins.

PYTEST_DONT_REWRITE
�N)�fnmatch)�StringIO)�Path)�Any)�Callable)�Dict)�	Generator)�IO)�Iterable)�List)�Optional)�overload)�Sequence)�TextIO)�Tuple)�Type)�
TYPE_CHECKING)�Union)�WeakKeyDictionary)�	IniConfig)�SectionWrapper)�timing)�Source)�_get_multicapture)�final)�NOTSET)�
NotSetType)�
_PluggyPlugin)�Config)�ExitCode)�hookimpl)�main)�PytestPluginManager)�Parser)�check_ispytest)�fixture)�FixtureRequest)�Session)�MonkeyPatch)�	Collector)�Item)�fail)�importorskip)�skip)�bestrelpath)�copytree)�make_numbered_dir)�
CollectReport)�
TestReport)�TempPathFactory)�
PytestWarning)�Final)�Literal�pytester_assertionsz/var/lib/sss/mc/passwd�parser�returncCs:|jdddddd�|jddd	d
dd�|jd
dd�dS)Nz--lsof�
store_true�lsofFz"Run FD checks if lsof is available)�action�dest�default�help�--runpytest�	inprocess�	runpytest)rA�
subprocesszYRun pytest sub runs in tests using an 'inprocess' or 'subprocess' (python -m main) method)r>r=�choicesr?�pytester_example_dirz1Directory to take the pytester example files from)r?)�	addoption�addini)r8�rH�I/home/arjun/projects/env/lib/python3.10/site-packages/_pytest/pytester.py�pytest_addoptionWs"��
�rJ�configcCs4|�d�rt�}|��r|j�|�|�dd�dS)Nr;�markerszlpytester_example_path(*path_segments): join the given path segments to `pytester_example_dir` for this test.)�getvalue�LsofFdLeakChecker�matching_platform�
pluginmanager�register�addinivalue_line)rK�checkerrHrHrI�pytest_configureps
�rTc@sVeZdZdeeeeffdd�Zdefdd�Ze	ddd�de
ded	fd
d��ZdS)
rNr9c	Cs�tjdddtt���ftjtjddt�d�d�j	}dtdt
fd	d
�}g}|�d�D],}||�rU|�d�}|d
dd�}|ddd�}|tvrIq)|�
d�rU|�||f�q)|S)Nr;z-Ffn0�-pTF)�stdout�stderr�check�text�encoding�liner9cSs*|�d�od|vod|vod|vod|vS)N�f�deleted�mem�txt�cwd��
startswith)r[rHrHrI�isopen�s
���z0LsofFdLeakChecker.get_open_files.<locals>.isopen�
�r��/)rC�run�str�os�getpid�PIPE�DEVNULL�locale�getpreferredencodingrV�bool�split�
IGNORE_PAMrb�append)�self�outrc�
open_filesr[�fields�fd�filenamerHrHrI�get_open_files~s.��	

�z LsofFdLeakChecker.get_open_filesc	Cs0z
tjddd�WdSttjfyYdSw)N)r;z-vT)rXF)rCrh�OSError�CalledProcessError�rtrHrHrIrO�s��z#LsofFdLeakChecker.matching_platformT)�hookwrapper�tryfirst�item�NNNc#s��|��}dVttd�rt��|��}dd�|D�dd�|D���fdd�|D�}|rgdt|�gdd�|D��d	�d
d�|D��d�dd�|D��dt|��d
|j�d�}|�td�	|���dSdS)N�pypy_version_infocSsh|]}|d�qS�rrH��.0�trHrHrI�	<setcomp>��z<LsofFdLeakChecker.pytest_runtest_protocol.<locals>.<setcomp>csg|]
}|d�vr|�qSr�rHr���new_fdsrHrI�
<listcomp>��z=LsofFdLeakChecker.pytest_runtest_protocol.<locals>.<listcomp>z***** %s FD leakage detectedcs��|]}t|�VqdS�N�ri�r�r\rHrHrI�	<genexpr>���z<LsofFdLeakChecker.pytest_runtest_protocol.<locals>.<genexpr>z*** Before:csr�r�r�r�rHrHrIr��r�z
*** After:csr�r�r�r�rHrHrIr��r�z*** function %s:%s: %s zSee issue #2366rd)
rz�hasattr�sys�gc�collect�len�location�warnr4�join)rtr��lines1�lines2�leaked_files�errorrHr�rI�pytest_runtest_protocol�s:�

������
��	��z)LsofFdLeakChecker.pytest_runtest_protocolN)
�__name__�
__module__�__qualname__rrrirzrprOr r*rr�rHrHrHrIrN}s
 
rN�request�	PytestArgcC�t|�S)z�Return a helper which offers a gethookrecorder(hook) method which
    returns a HookRecorder instance which helps to make assertions about called
    hooks.)r��r�rHrHrI�_pytest�sr�c@s(eZdZdeddfdd�Zd	dd�ZdS)
r�r�r9NcCs
||_dSr�)�_request)rtr�rHrHrI�__init__��
zPytestArg.__init__�HookRecordercCst|j�}|j�|j�|Sr�)r��_pmr��addfinalizer�finish_recording)rt�hook�hookrecorderrHrHrI�gethookrecorder�s
zPytestArg.gethookrecorder)r9r�)r�r�r�r&r�r�rHrHrHrIr��s�valuescCsdd�|D�S)zDOnly return names from iterator values without a leading underscore.cSsg|]
}|ddkr|�qS)r�_rH�r��xrHrHrIr��r�z$get_public_names.<locals>.<listcomp>rH)r�rHrHrI�get_public_names��r�c@sFeZdZdZdeddfdd�Zdefdd�Zer!d	efd
d�ZdSdS)�RecordedHookCalla;A recorded call to a hook.

    The arguments to the hook call are set as attributes.
    For example:

    .. code-block:: python

        calls = hook_recorder.getcalls("pytest_runtest_setup")
        # Suppose pytest_runtest_setup was called once with `item=an_item`.
        assert calls[0].item is an_item
    �namer9NcCs|j�|�||_dSr�)�__dict__�update�_name)rtr��kwargsrHrHrIr��s
zRecordedHookCall.__init__cCs$|j��}|d=d|j�d|�d�S)Nr�z<RecordedHookCall z(**z)>)r��copyr�)rt�drHrHrI�__repr__�s
zRecordedHookCall.__repr__�keycC�dSr�rH)rtr�rHrHrI�__getattr__��zRecordedHookCall.__getattr__)	r�r�r��__doc__rir�r�rr�rHrHrHrIr��s�r�c@szeZdZdZdd�dededdfdd	�Zd8d
d�Zdee	e
e	fdeefd
d�Z
deee	e	fddfdd�Zde	defdd�Zde	defdd�Zedddeefdd��Zedddeefdd��Ze	d9dee	e
e	fdeeeeffdd��Z	d9dee	e
e	fdeeeeffdd�Z		 	d:d!e	dee	e
e	fd"ee	deeeffd#d$�Zedddeefd%d&��Zedddeefd'd&��Ze	d9dee	e
e	fdeeeeffd(d&��Z	d9dee	e
e	fdeeeeffd)d&�Zdeefd*d+�Zdeeeeeeefeeeefffd,d-�Zdeefd.d/�Zd;d1ed2ed3eddfd4d5�Zd8d6d7�ZdS)<r�z�Record all hooks called in a plugin manager.

    Hook recorders are created by :class:`Pytester`.

    This wraps all the hook calls in the plugin manager, recording each call
    before propagating the normal calls.
    F��	_ispytestrPr�r9NcsTt|�|�_g�_d�_dtddf�fdd�}dtddfdd�}|�||��_dS)N�	hook_namer9cs�j�t||��dSr�)�callsrsr�)r��
hook_implsr�r}rHrI�before	�z%HookRecorder.__init__.<locals>.beforecSr�r�rH)�outcomer�r�r�rHrHrI�afterr�z$HookRecorder.__init__.<locals>.after)r$�_pluginmanagerr��retri�add_hookcall_monitoring�_undo_wrapping)rtrPr�r�r�rHr}rIr�szHookRecorder.__init__cCs|��dSr�)r�r}rHrHrIr�szHookRecorder.finish_recording�namescs&t�t�r	�����fdd�|jD�S)z?Get all recorded calls to hooks with the given names (or name).csg|]	}|j�vr|�qSrH)r�)r��call�r�rHrIr��z)HookRecorder.getcalls.<locals>.<listcomp>)�
isinstancerirqr��rtr�rHr�rI�getcallss
zHookRecorder.getcalls�entriesc	Cs�d}d}t|�}t�d�j}|rh|�d�\}}t|j|d��D]9\}}|j|krRtd||�t	|||j
�r@tdt|�d|�n
tdt|�d|�q ||d7}ntd	|d
|�q td|�d|���|sdSdS)
NTrrf�	NAMEMATCH�CHECKERMATCHz->�NOCHECKERMATCH�-�NONAMEMATCH�withzcould not find z check )
�listr��	_getframe�f_locals�pop�	enumerater�r��print�evalr��reprr+)	rtr��__tracebackhide__�i�
backlocalsr�rX�indr�rHrHrI�assert_containss$
�zHookRecorder.assert_containsr�cCshd}t|j�D]\}}|j|kr|j|=|Sqd|�d�g}|�dd�|jD��td�|��dS)NTzcould not find call z, in:cSsg|]}d|�qS)z  %srHr�rHrHrIr�6r�z(HookRecorder.popcall.<locals>.<listcomp>rd)r�r�r��extendr+r�)rtr�r�r�r��linesrHrHrI�popcall/s
�zHookRecorder.popcallcCs*|�|�}t|�dksJ||f��|dS)Nrfr)r�r�)rtr�r�rHrHrI�getcall9s
zHookRecorder.getcallzLiteral['pytest_collectreport']cCr�r�rHr�rHrHrI�
getreports@�zHookRecorder.getreportsz#Literal['pytest_runtest_logreport']cCr�r�rHr�rHrHrIr�Gr���pytest_collectreport�pytest_runtest_logreportcCr�r�rHr�rHrHrIr�N�cC�dd�|�|�D�S)NcS�g|]}|j�qSrH)�reportr�rHrHrIr�_�z+HookRecorder.getreports.<locals>.<listcomp>)r�r�rHrHrIr�X���r�r��	inamepart�whencCs�g}|j|d�D]$}|s|jdkr|jrq|r|j|krq|r'||j�d�vr,|�|�q|s6td|f��t|�dkrDtd�||���|dS)z5Return a testreport whose dotted import path matches.r�r��::z?could not find test report matching %r: no test reports at all!rfz-found 2 or more testreports matching {!r}: {}r)	r�r�passed�nodeidrqrs�
ValueErrorr��format)rtr�r�rr��reprHrHrI�matchreportas,

�����zHookRecorder.matchreportcCr�r�rHr�rHrHrI�getfailures�r�zHookRecorder.getfailurescCr�r�rHr�rHrHrIr�r�cCr�r�rHr�rHrHrIr�r�cCr�)NcSsg|]}|jr|�qSrH)�failed)r�rrHrHrIr��sz,HookRecorder.getfailures.<locals>.<listcomp>)r�r�rHrHrIr�r�cC�
|�d�S)Nr�)rr}rHrHrI�getfailedcollections�r�z!HookRecorder.getfailedcollectionscCs�g}g}g}|�d�D]/}|jr"|jdkr!t|t�sJ�|�|�q|jr+|�|�q|js5Jd|����|�|�q|||fS)Nr�r�zUnexpected outcome: )r�rrr�r2rs�skippedr	)rtrrr	rrHrHrI�listoutcomes�s �

�
zHookRecorder.listoutcomescCsdd�|��D�S)NcS�g|]}t|��qSrH)r�r�rHrHrIr��r�z.HookRecorder.countoutcomes.<locals>.<listcomp>)r
r}rHrHrI�
countoutcomes��zHookRecorder.countoutcomesrrrr	cCs,d}ddlm}|��}|||||d�dS)NTr)�
assertoutcome)rrr	)�_pytest.pytester_assertionsrr
)rtrrr	r�r�outcomesrHrHrIr�s
�zHookRecorder.assertoutcomecCsg|jdd�<dSr�)r�r}rHrHrI�clear�rzHookRecorder.clear�r9N)r�)r�r�N)rrr) r�r�r�r�r"rpr�r�rrir
rr�r�rrr�r�r�r
r1r�r2rrrrr
�intrrrrHrHrHrIr��s�	���
�
"
���������
�����

� ���������
�	��
�r��LineCompcCst�S)zeA :class: `LineComp` instance for checking that an input linearly
    contains a sequence of strings.)rrHrHrHrI�linecomp�sr�LineMatcher�r�cCstS)z�A reference to the :class: `LineMatcher`.

    This is instantiable with a list of lines (without their trailing newlines).
    This is useful for testing large texts, such as the output of commands.
    )rr�rHrHrI�LineMatcher_fixture�sr�tmp_path_factory�monkeypatch�PytestercCst|||dd�S)a
    Facilities to write tests/configuration files, execute pytest in isolation, and match
    against expected output, perfect for black-box testing of pytest plugins.

    It attempts to isolate the test run from external factors as much as possible, modifying
    the current working directory to ``path`` and environment variables during initialization.

    It is particularly useful for testing plugins. It is similar to the :fixture:`tmp_path`
    fixture but provides methods which aid in testing pytest itself.
    Tr�)r)r�rrrHrHrI�pytester�srr�ccs(�t�}t�}dV|��|��dSr�)�SysPathsSnapshot�SysModulesSnapshot�restore)�	snappaths�snapmodsrHrHrI�
_sys_snapshot�s�r%ccs&�ddlm}|�}|V|��dS)Nr)�
get_config)�_pytest.configr&�_ensure_unconfigure)r&rKrHrHrI�_config_for_test�s
�r)z
\d+\.\d\dsz(\d+) (\w+)c@s�eZdZdZdeeefdeedeede	ddf
dd	�Z
defd
d�Zdeeeffdd
�Z
edeeeffdd��Z								ddededededededeedeeddfdd�ZdS)�	RunResultz?The result of running a command from :class:`~pytest.Pytester`.r��outlines�errlines�durationr9NcCsZzt|�|_Wnty||_Ynw||_	||_	t|�|_	t|�|_	||_dSr�)	rr�rr+r,rrVrWr-)rtr�r+r,r-rHrHrIr�s 

�

zRunResult.__init__cCs$d|jt|jj�t|jj�|jfS)NzK<RunResult ret=%s len(stdout.lines)=%d len(stderr.lines)=%d duration=%.2fs>)r�r�rVr�rWr-r}rHrHrIr�)s��zRunResult.__repr__cCs|�|j�S)aUReturn a dictionary of outcome noun -> count from parsing the terminal
        output that the test process produced.

        The returned nouns will always be in plural form::

            ======= 1 failed, 1 passed, 1 warning, 1 error in 0.13s ====

        Will return ``{"failed": 1, "passed": 1, "warnings": 1, "errors": 1}``.
        )�parse_summary_nounsr+r}rHrHrI�
parseoutcomes/s
zRunResult.parseoutcomescs\t|�D]}t�|�rt�|�}dd�|D�}nqtd��ddd���fdd�|��D�S)aExtract the nouns from a pytest terminal summary line.

        It always returns the plural noun for consistency::

            ======= 1 failed, 1 passed, 1 warning, 1 error in 0.13s ====

        Will return ``{"failed": 1, "passed": 1, "warnings": 1, "errors": 1}``.
        cSsi|]	\}}|t|��qSrH)r)r��count�nounrHrHrI�
<dictcomp>Hr�z1RunResult.parse_summary_nouns.<locals>.<dictcomp>z(Pytest terminal summary report not found�warnings�errors)�warningr�csi|]\}}��||�|�qSrH)�get)r��k�v��	to_pluralrHrIr2Qs)�reversed�rex_session_duration�search�rex_outcome�findallr�items)�clsr�r[rr�rHr9rIr.;s


��zRunResult.parse_summary_nounsrrrr	r4�xpassed�xfailedr3�
deselectedc	Cs6d}	ddlm}
|��}|
|||||||||d�	dS)z�
        Assert that the specified outcomes appear with the respective
        numbers (0 means it didn't occur) in the text output from a test run.

        ``warnings`` and ``deselected`` are only checked if not None.
        Tr)�assert_outcomes)rrr	r4rBrCr3rDN)rrEr/)rtrrr	r4rBrCr3rDr�rErrHrHrIrESs
�zRunResult.assert_outcomes)rrrrrrNN)r�r�r�r�rrrrri�floatr�r�rr/�classmethodr.rrErHrHrHrIr*
sX
����
���������	�
�r*c@� eZdZddd�Zddd�ZdS)�CwdSnapshotr9NcCst��|_dSr�)rj�getcwd�_CwdSnapshot__savedr}rHrHrIr�v�zCwdSnapshot.__init__cCst�|j�dSr�)rj�chdirrKr}rHrHrIr"yszCwdSnapshot.restorer�r�r�r�r�r"rHrHrHrIrIu�
rIc@s8eZdZddeeegefddfdd�Zd	dd�ZdS)
r!N�preserver9cCs||_ttj�|_dSr�)�_SysModulesSnapshot__preserve�dictr��modules�_SysModulesSnapshot__saved)rtrPrHrHrIr�~szSysModulesSnapshot.__init__csB�jr�j��fdd�tj��D��tj��tj��j�dS)Nc3s&�|]\}}��|�r||fVqdSr�)rQ)r�r7�mr}rHrIr��s��
�z-SysModulesSnapshot.restore.<locals>.<genexpr>)rQrTr�r�rSr@rr}rHr}rIr"�s�
zSysModulesSnapshot.restorer�r)	r�r�r�rrrirpr�r"rHrHrHrIr!}s"r!c@rH)r r9NcCsttj�ttj�f|_dSr�)r�r��path�	meta_path�_SysPathsSnapshot__savedr}rHrHrIr��szSysPathsSnapshot.__init__cCs"|j\tjdd�<tjdd�<dSr�)rXr�rVrWr}rHrHrIr"�s"zSysPathsSnapshot.restorerrNrHrHrHrIr �rOr c
@s�eZdZUdZdZeZded<Gdd�de�Z	dd�de
d	ed
ede
dd
f
dd�Zedefdd��Zdefdd�Zd�dd�Zdefdd�Zdedefdd�Zd�dd�Z	d�dedeeeefd eeefd!edef
d"d#�Z ded$ed%edefd&d'�Z!d(edefd)d*�Z"d(edefd+d,�Z#d(ede$fd-d.�Z%d(edefd/d0�Z&defd1d2�Z'defd3d4�Z(	
d�d5e)eed6fdd
fd7d8�Z*d9eed6fdefd:d;�Z+d9eed6fdefd<d=�Z,d�d9e)edefd>d?�Z-d@e.dAeed6fdee/e0ffdBdC�Z1d5eed6fdee/e0ffdDdE�Z2dFeee0e/fde3e0fdGdH�Z4d(edefdIdJ�Z5d(edefdKdL�Z6de7e3e0effdMdN�Z8dOddP�d$eed6fdQe
defdRdS�Z9d$eed6fd%ede:fdTdU�Z;d$eed6fd%ede:fdVdW�Z<d$eeed6fde3eed6ffdXdY�Z=d$eed6fde.fdZd[�Z>d$eed6fde.fd\d]�Z?	^d�d(eed6fd_ede0fd`da�Z@d(eed6fde3e0fdbdc�ZA	Od�ddd�d(eed6fdee
fdfdg�ZBdhe/d9ede)ee0e/ffdidj�ZCeDjEeDjEefdkeeed6fdleeFeGfdmeeFeGfdneeHeeIeeFffdodp�ZJd
edq�dkeed6fdre)eKdneeHeeIeeFfde:fdsdt�ZLdudv�ZMde7edwffdxdy�ZNdzd6de:fd{d|�ZOd}ede:fd~d�ZPd
d��d$eed6fdre)eKde:fd�d��ZQ	�d�d�ed�eKdd�fd�d��ZRd�d�ed�eKdd�fd�d��ZSd
S)�ran
    Facilities to write tests/configuration files, execute pytest in isolation, and match
    against expected output, perfect for black-box testing of pytest plugins.

    It attempts to isolate the test run from external factors as much as possible, modifying
    the current working directory to :attr:`path` and environment variables during initialization.
    Fr5�CLOSE_STDINc@�eZdZdS)zPytester.TimeoutExpiredN�r�r�r�rHrHrHrI�TimeoutExpired��r\r�r�rrr�r9NcCs
t|�||_t�|_|jr|jj}n|jj}||_|j	|dd�|_
g|_t�|_
t�|_|��|_|��|j�|j�|jj�d�|_|j	d|��dd�|_||_}|�dt|j��|jddd�|jd	dd�t|j�}|�d
|�|�d|�|�dd
�dS)NT)�numberedr@ztmp-�PYTEST_DEBUG_TEMPROOT�TOX_ENV_DIRF)�raising�PYTEST_ADDOPTS�HOME�USERPROFILE�	PY_COLORS�0)r$r�r�_mod_collections�functionr��noder�r��mktemp�_path�pluginsrI�
_cwd_snapshotr �_sys_path_snapshot�$_Pytester__take_sys_modules_snapshot�_sys_modules_snapshotrMr��	_finalizerK�	getoption�_method�
_test_tmproot�_monkeypatch�setenvri�delenvrV)rtr�rrr�r��mp�tmphomerHrHrIr��s2�



zPytester.__init__cCs|jS)zBTemporary directory path used to create files/run tests from, etc.)rkr}rHrHrIrV�sz
Pytester.pathcCsd|j�d�S)Nz
<Pytester �>)rVr}rHrHrIr��rLzPytester.__repr__cCs"|j��|j��|j��dS)a
        Clean up global state artifacts.

        Some methods modify the global interpreter state and this tries to
        clean this up. It does not remove the temporary directory however so
        it can be looked at after the test run has finished.
        N)rpr"rnrmr}rHrHrIrq�s

zPytester._finalizecCsdd�}t|d�S)NcSr
)N)�zope�readlinerarrHrHrI�preserve_module�r�z=Pytester.__take_sys_modules_snapshot.<locals>.preserve_module)rP)r!)rtr}rHrHrI�__take_sys_modules_snapshot�s
z$Pytester.__take_sys_modules_snapshotrPcCs$t|dd�|_}|j�|j�|S)zFCreate a new :class:`HookRecorder` for a :class:`PytestPluginManager`.Tr�)r��reprecr�r�r�)rtrPrrHrHrI�make_hook_recorder�szPytester.make_hook_recordercCst�|j�dS)zaCd into the temporary directory.

        This is done automatically upon instantiation.
        N)rjrMrVr}rHrHrIrM�szPytester.chdir�utf-8�extr��filesrZcst|���}|r|�d�std|�d|����dtttfdtf�fdd��|r?d��fd	d
�|D��}|j	}|�
d||f�d}|D]5\}}	|j�|��
|�}
|
jjddd
�t|	�}d��fdd
�|jD��}|
j|���d�|durx|
}qC|dusJ�|S)N�.z1pytester.makefile expects a file extension, try .z instead of �sr9cst|t�r
|���St|�Sr�)r��bytes�decoderi)r��rZrHrI�to_textsz#Pytester._makefile.<locals>.to_textrdc3��|]}�|�VqdSr�rHr��r�rHrIr�r�z%Pytester._makefile.<locals>.<genexpr>rT)�parents�exist_okc3r�r�rH)r�r[r�rHrIr�r�r�)r�r@rbrrrr�rir�r��insertrV�joinpath�with_suffix�parent�mkdirrr��
write_text�strip)rtr�r�r�rZr@�source�basenamer��value�p�source_rH)rZr�rI�	_makefile�s,��zPytester._makefile�argsr�cOs|�|||�S)a�Create new text file(s) in the test directory.

        :param ext:
            The extension the file(s) should use, including the dot, e.g. `.py`.
        :param args:
            All args are treated as strings and joined using newlines.
            The result is written as contents to the file.  The name of the
            file is based on the test function requesting this fixture.
        :param kwargs:
            Each keyword is the name of a file, while the value of it will
            be written as contents of the file.
        :returns:
            The first created file.

        Examples:

        .. code-block:: python

            pytester.makefile(".txt", "line1", "line2")

            pytester.makefile(".ini", pytest="[pytest]\naddopts=-rs\n")

        To create binary files, use :meth:`pathlib.Path.write_bytes` directly:

        .. code-block:: python

            filename = pytester.path.joinpath("foo.bin")
            filename.write_bytes(b"...")
        �r�)rtr�r�r�rHrHrI�makefile szPytester.makefiler�cCs|j|d�S)zoWrite a contest.py file.

        :param source: The contents.
        :returns: The conftest.py file.
        )�conftest)�
makepyfile�rtr�rHrHrI�makeconftest@�zPytester.makeconftestcC�|jd|d�S)zhWrite a tox.ini file.

        :param source: The contents.
        :returns: The tox.ini file.
        z.ini)�tox�r�r�rHrHrI�makeiniHszPytester.makeinicCs|�|�}tt|��dS)z7Return the pytest section from the tox.ini config file.�pytest)r�rri)rtr�r�rHrHrI�	getinicfgPs
zPytester.getinicfgcCr�)z�Write a pyproject.toml file.

        :param source: The contents.
        :returns: The pyproject.ini file.

        .. versionadded:: 6.0
        z.toml)�	pyprojectr�r�rHrHrI�makepyprojecttomlUszPytester.makepyprojecttomlcO�|�d||�S)aSShortcut for .makefile() with a .py extension.

        Defaults to the test name with a '.py' extension, e.g test_foobar.py, overwriting
        existing files.

        Examples:

        .. code-block:: python

            def test_something(pytester):
                # Initial file is created test_something.py.
                pytester.makepyfile("foobar")
                # To create multiple files, pass kwargs accordingly.
                pytester.makepyfile(custom="foobar")
                # At this point, both 'test_something.py' & 'custom.py' exist in the test directory.

        �.pyr��rtr�r�rHrHrIr�_�zPytester.makepyfilecOr�)a[Shortcut for .makefile() with a .txt extension.

        Defaults to the test name with a '.txt' extension, e.g test_foobar.txt, overwriting
        existing files.

        Examples:

        .. code-block:: python

            def test_something(pytester):
                # Initial file is created test_something.txt.
                pytester.maketxtfile("foobar")
                # To create multiple files, pass kwargs accordingly.
                pytester.maketxtfile(custom="foobar")
                # At this point, both 'test_something.txt' & 'custom.txt' exist in the test directory.

        z.txtr�r�rHrHrI�maketxtfilesr�zPytester.maketxtfilerVzos.PathLike[str]cCs"|dur|j}|j�t|��dS)z�Prepend a directory to sys.path, defaults to :attr:`path`.

        This is undone automatically when this object dies at the end of each
        test.

        :param path:
            The path.
        N)rVru�syspath_prependri)rtrVrHrHrI�
syspathinsert�szPytester.syspathinsertr�cCs|j|}|��|S)z�Create a new (sub)directory.

        :param name:
            The name of the directory, relative to the pytester path.
        :returns:
            The created directory.
        )rVr��rtr�r�rHrHrIr��s
zPytester.mkdircCs$|j|}|��|�d���|S)z�Create a new python package.

        This creates a (sub)directory with an empty ``__init__.py`` file so it
        gets recognised as a Python package.
        �__init__.py)rVr�r��touchr�rHrHrI�mkpydir�s
zPytester.mkpydirc
Cs|jj�d�}|durtd��|jjj|}|jj�d�D]
}|js$J�|j|j�}q|durS|j	}||}||d}|�
�rC|}n|��rJ|}nt|�d|����|�|�}|�
�rl|�d���slt
||j�|jS|��r|j�|j�}	t�||	�|	Std|�d	���)
z�Copy file from project's directory into the testdir.

        :param name:
            The name of the file to copy.
        :return:
            Path to the copied directory (inside ``self.path``).
        rENz2pytester_example_dir is unset, can't copy examples�pytester_example_pathr�z( can't be found as module or package in r�z	example "z%" is not found as a file or directory)r�rK�getinir�rootpathri�iter_markersr�r�r��is_dir�is_file�LookupErrorr/rVr��shutilr�)
rtr��example_dir_�example_dir�
extra_element�	func_name�	maybe_dir�
maybe_file�example_path�resultrHrHrI�copy_example�s:
�

�zPytester.copy_examplerK�argcCsft�|�}dt|�vs
J�ttj�|��}|jj|d�|j	t|�gdd�d}|jj
|tjd�|S)aGet the collection node of a file.

        :param config:
           A pytest config.
           See :py:meth:`parseconfig` and :py:meth:`parseconfigure` for creating it.
        :param arg:
            Path to the file.
        :returns:
            The node.
        r��sessionF��genitemsr�r��
exitstatus)
r'�from_configrirrjrV�abspathr��pytest_sessionstart�perform_collect�pytest_sessionfinishr�OK)rtrKr�r�r��resrHrHrI�getnode�s

zPytester.getnodecCs`t|�}|�|�}t�|�}t|j|�}|jj|d�|j|gdd�d}|jj	|t
jd�|S)aReturn the collection node of a file.

        This is like :py:meth:`getnode` but uses :py:meth:`parseconfigure` to
        create the (configured) pytest Config instance.

        :param path:
            Path to the file.
        :returns:
            The node.
        r�Fr�rr�)r�parseconfigurer'r�r.rVr�r�r�r�rr�)rtrVrKr�r�r�rHrHrI�getpathnode�s

zPytester.getpathnode�colitemscCs,|dj}g}|D]
}|�|�|��q	|S)aGenerate all test items from a collection node.

        This recurses into the collection node and returns a list of all the
        test items contained within.

        :param colitems:
            The collection nodes.
        :returns:
            The collected items.
        r)r�r�r�)rtr�r�r��colitemrHrHrIr�s

zPytester.genitemscCs"|�|�}|jj}|��}||�S)a'Run the "test_func" Item.

        The calling test instance (class containing the test method) must
        provide a ``.getrunner()`` method which should return a runner which
        can run the test protocol for a single item, e.g.
        :py:func:`_pytest.runner.runtestprotocol`.
        )�getitemr��instance�	getrunner)rtr�r��testclassinstance�runnerrHrHrI�runitems
	zPytester.runitemcGs"|�|�}t|�|g}|j|�S)agRun a test module in process using ``pytest.main()``.

        This run writes "source" into a temporary file and runs
        ``pytest.main()`` on it, returning a :py:class:`HookRecorder` instance
        for the result.

        :param source: The source code of the test module.
        :param cmdlineargs: Any extra command line arguments to use.
        )r�r��
inline_run)rtr��cmdlineargsr�r�rHrHrI�inline_runsource&s


zPytester.inline_runsourcecGs.|jdg|�R�}dd�|�d�D�}||fS)a!Run ``pytest.main(['--collectonly'])`` in-process.

        Runs the :py:func:`pytest.main` function to run all of pytest inside
        the test process itself like :py:meth:`inline_run`, but returns a
        tuple of the collected items and a :py:class:`HookRecorder` instance.
        z--collect-onlycSr�rH)r�r�rHrHrIr�<r�z,Pytester.inline_genitems.<locals>.<listcomp>�pytest_itemcollected)r�r�)rtr��recr@rHrHrI�inline_genitems4szPytester.inline_genitemsrH)rl�no_reraise_ctrlcr�c
s�t��t|�}g}ze|����j�|�t�j�g�G��fdd�d�}|�|��tdd�|D�|d�}t��dkrB��	�}nGdd�d�}||_
|tjkre|se|�
d	�}|re|d
jjtkret��|W|D]}	|	�qiS|D]}	|	�qrw)a�Run ``pytest.main()`` in-process, returning a HookRecorder.

        Runs the :py:func:`pytest.main` function to run all of pytest inside
        the test process itself.  This means it can return a
        :py:class:`HookRecorder` instance which gives more detailed results
        from that run than can be done by matching stdout/stderr from
        :py:meth:`runpytest`.

        :param args:
            Command line arguments to pass to :py:func:`pytest.main`.
        :param plugins:
            Extra plugin instances the ``pytest.main()`` instance should use.
        :param no_reraise_ctrlc:
            Typically we reraise keyboard interrupts from the child run. If
            True, the KeyboardInterrupt exception is captured.
        cs$eZdZdeddf��fdd�ZdS)z$Pytester.inline_run.<locals>.CollectrKr9Ncs����|j��dSr�)rsr�rP)r�rK�r�rtrHrIrTmr�z5Pytester.inline_run.<locals>.Collect.pytest_configure)r�r�r�rrTrHr�rHrI�Collectlsr�cSrrHr�r�rHrHrIr�qr�z'Pytester.inline_run.<locals>.<listcomp>)rlrfc@rZ)z#Pytester.inline_run.<locals>.reprecNr[rHrHrHrIrvr]r�pytest_keyboard_interrupt���)�	importlib�invalidate_cachesr�rsror"r r!r�r�r�r�INTERRUPTEDr��excinfo�type�KeyboardInterrupt)
rtrlr�r��
finalizersr�r�rr��	finalizerrHr�rIr�?s0


��zPytester.inline_runcOsf|�dd�}|r|��t��}td�}|��zgz
|j|i|��}WnDtyT}z%|jd}z	t	|jd�}Wn	t
yBYnwGdd�d�}WYd}~nd}~wtygt�
�Gdd�d�}YnwW|��\}	}
|��tj�|	�tj�|
�n|��\}	}
|��tj�|	�tj�|
�w|jdus�J�t|j|	��|
��t��|�}||_|S)	ztReturn result of running pytest in-process, providing a similar
        interface to what self.runpytest() provides.r�Fr�rc@seZdZeZdS)�,Pytester.runpytest_inprocess.<locals>.reprecN)r�r�r�r�rHrHrHrIr�srNc@seZdZed�ZdS)r��N)r�r�r�rr�rHrHrHrIr�s)r�r�r�timer�start_capturingr��
SystemExitr�rr�	Exception�	traceback�	print_exc�
readouterr�stop_capturingr�rV�writerWr�r*�
splitlinesr)rtr�r�r��now�capturer�er�ru�errr�rHrHrI�runpytest_inprocess�sJ
������zPytester.runpytest_inprocesscOsN|�|�}|jdkr|j|i|��S|jdkr|j|i|��Std|j����)z�Run pytest inline or in a subprocess, depending on the command line
        option "--runpytest" and return a :py:class:`~pytest.RunResult`.rArCzUnrecognized runpytest option: )�_ensure_basetemprsr�runpytest_subprocess�RuntimeError)rtr�r��new_argsrHrHrIrB�s


zPytester.runpytestcCsBt|�}|D]}t|��d�r|Sq|�d|jj�d��|S)Nz
--basetemp�
--basetemp=%s�basetemp)r�rirbrsrVr�r�)rtr�rr�rHrHrIr�s�zPytester._ensure_basetempcGsBddl}|�|�}dd�|D�}|j�||j�}|j�|j�|S)a�Return a new pytest :class:`pytest.Config` instance from given
        commandline args.

        This invokes the pytest bootstrapping code in _pytest.config to create a
        new :py:class:`pytest.PytestPluginManager` and call the
        :hook:`pytest_cmdline_parse` hook to create a new :class:`pytest.Config`
        instance.

        If :attr:`plugins` has been populated they should be plugin modules
        to be registered with the plugin manager.
        rNcSrrHr�r�rHrHrIr��r�z(Pytester.parseconfig.<locals>.<listcomp>)r'rrK�_prepareconfigrlr�r�r()rtr�r�rrKrHrHrI�parseconfig�s
zPytester.parseconfigcGs|j|�}|��|S)z�Return a new pytest configured Config instance.

        Returns a new :py:class:`pytest.Config` instance like
        :py:meth:`parseconfig`, but also calls the :hook:`pytest_configure`
        hook.
        )r�
_do_configure)rtr�rKrHrHrIr��s
zPytester.parseconfigure�	test_func�funcnamecCs8|�|�}|D]}|j|kr|SqJd�|||���)a�Return the test item for a test function.

        Writes the source to a python file and runs pytest's collection on
        the resulting module, returning the test item for the requested
        function name.

        :param source:
            The module source.
        :param funcname:
            The name of the test function for which to return a test item.
        :returns:
            The test item.
        rz+{!r} item not found in module:
{}
items: {})�getitemsr�r)rtr�rr@r�rHrHrIr��s

��zPytester.getitemcCs|�|�}|�|g�S)z�Return all test items collected from the module.

        Writes the source to a Python file and runs pytest's collection on
        the resulting module, returning all test items contained within.
        )�getmodulecolr�)rtr��modcolrHrHrIrs
zPytester.getitems)�withinitrcCsxt|tj�r|j�|�}|rJd��n|jt|�i}|jdi|��}|r*|jdd�|j|g|�R�|_	}|�
||�S)a*Return the module collection node for ``source``.

        Writes ``source`` to a file using :py:meth:`makepyfile` and then
        runs the pytest collection on it, returning the collection node for the
        test module.

        :param source:
            The source code of the module to collect.

        :param configargs:
            Any extra arguments to pass to :py:meth:`parseconfigure`.

        :param withinit:
            Whether to also write an ``__init__.py`` file to the same
            directory to ensure it is a package.
        znot supported for paths�#)r�NrH)r�rj�PathLikerVr�r�rir�r�rKr�)rtr��
configargsrrV�kwrKrHrHrIr
szPytester.getmodulecolrcCsB||jvrt|���|j|<|j|D]}|j|kr|SqdS)a.Return the collection node for name from the module collection.

        Searches a module collection node for a collection node matching the
        given name.

        :param modcol: A module collection node; see :py:meth:`getmodulecol`.
        :param name: The name of the node to return.
        N)rgr�r�r�)rtrr�r�rHrHrI�collect_by_name/s

�zPytester.collect_by_name�cmdargsrVrW�stdinc	Ks�tj��}tj�tdt��|�dd�g��|d<||d<||jur't	j
|d<nt|t�r2t	j
|d<n||d<t	j
|f||d�|��}||jurU|jdusNJ�|j��|St|t�rg|jdusaJ�|j�|�|S)z�Invoke :py:class:`subprocess.Popen`.

        Calls :py:class:`subprocess.Popen` making sure the current working
        directory is in ``PYTHONPATH``.

        You probably want to use :py:meth:`run` instead.
        N�
PYTHONPATHr��envr)rVrW)rj�environr��pathsepr��filterrJr6rYrCrlr�r��Popenr�closer�)rtrrVrWrrr�popenrHrHrIr!As&
�




�zPytester.popen)�timeoutrr"c
sd}tdd��D����j�d�}�j�d�}tdg��R�tdt���|jdd	d
��b}|jdd	d
��K}t��}	�j	�|||t
jdkd���jd
urQ�j�
�d����fdd�}
�d
urd���}nz����}Wn
tjyx|
�YnwWd
�n1s�wYWd
�n1s�wY|jd	d
��*}|jd	d
��}|����}|����}
Wd
�n1s�wYWd
�n1s�wY��|t
j���|
t
j�t�t��t|�}Wd
�n1s�wYt|||
t��|	�S)a�Run a command with arguments.

        Run a process using :py:class:`subprocess.Popen` saving the stdout and
        stderr.

        :param cmdargs:
            The sequence of arguments to pass to :py:class:`subprocess.Popen`,
            with path-like objects being converted to :py:class:`str`
            automatically.
        :param timeout:
            The period in seconds after which to timeout and raise
            :py:class:`Pytester.TimeoutExpired`.
        :param stdin:
            Optional standard input.

            - If it is :py:attr:`CLOSE_STDIN` (Default), then this method calls
              :py:class:`subprocess.Popen` with ``stdin=subprocess.PIPE``, and
              the standard input is closed immediately after the new command is
              started.

            - If it is of type :py:class:`bytes`, these bytes are sent to the
              standard input of the command.

            - Otherwise, it is passed through to :py:class:`subprocess.Popen`.
              For further information in this case, consult the document of the
              ``stdin`` parameter in :py:class:`subprocess.Popen`.
        :returns:
            The result.
        Tcss�|]}t�|�VqdSr�)rj�fspath)r�r�rHrHrIr��s�zPytester.run.<locals>.<genexpr>rVrWzrunning:z     in:�w�utf8r��win32)rrVrW�	close_fdsNr9cs,d}dj��d�}��������|��)NTz3{seconds} second timeout expired running: {command})�seconds�command)r�kill�waitr\)r��timeout_message�rr!rtr"rHrI�handle_timeout�s��
z$Pytester.run.<locals>.handle_timeoutr)�tuplerVr�r�rr`�openrr�r!r��platformrr r+rCr\�readr��_dump_linesrVrW�
contextlib�suppressrrr*)rtr"rrr��p1�p2�f1�f2r�r.r�rurrHr-rIrhgsR# �



���� ��
�zPytester.runcCsBz|D]}t||d�qWdSty td|�d��YdSw)N)�filezcouldn't print to z because of encoding)r��UnicodeEncodeError)rtr��fpr[rHrHrIr3�s��zPytester._dump_lines.cCs
tjdfS)Nz-mpytest)r��
executabler}rHrHrI�_getpytestargs�r�zPytester._getpytestargs�scriptcCs|�tj|�S)z8Run a python script using sys.executable as interpreter.�rhr�r=)rtr?rHrHrI�	runpython�r�zPytester.runpythonr)cCs|�tjd|�S)zRun ``python -c "command"``.z-cr@)rtr)rHrHrI�runpython_c�szPytester.runpython_c)r"cGsbd}t|jddd�}d|f|}dd�|jD�}|r#d|d	f|}|��|}|j|d
|i�S)a�Run pytest as a subprocess with given arguments.

        Any plugins added to the :py:attr:`plugins` list will be added using the
        ``-p`` command line option.  Additionally ``--basetemp`` is used to put
        any temporary files and directories in a numbered directory prefixed
        with "runpytest-" to not conflict with the normal numbered pytest
        location for temporary files and directories.

        :param args:
            The sequence of arguments to pass to the pytest subprocess.
        :param timeout:
            The period in seconds after which to timeout and raise
            :py:class:`Pytester.TimeoutExpired`.
        :returns:
            The result.
        Tz
runpytest-�)�root�prefix�modercSsg|]	}t|t�r|�qSrH)r�rir�rHrHrIr��r�z1Pytester.runpytest_subprocess.<locals>.<listcomp>rUrr")r0rVrlr>rh)rtr"r�r�r�rlrHrHrIr�szPytester.runpytest_subprocess�$@�string�expect_timeoutz
pexpect.spawncCsL|jd}|jdd�d�tt|����}|�d|�d|��}|j||d�S)z�Run pytest using pexpect.

        This makes sure to use the right pytest and sets up the temporary
        directory locations.

        The pexpect child is returned.
        ztemp-pexpectrC)rF� z --basetemp=)rI)rVr�r��maprir>�spawn)rtrHrIr	�invoke�cmdrHrHrI�spawn_pytest�s


zPytester.spawn_pytestrNcCsntdd�}ttd�rdt��vrtd�t|d�std�|j�d��d	�}|j	|||d
�}|j
�|j�|S)zMRun a command using pexpect.

        The pexpect child is returned.
        �pexpectz3.0r��64zpypy-64 bit not supportedrLzpexpect.spawn not availablez	spawn.out�wb)�logfiler")
r,r�r�r1�machiner-rVr�r0rLr�r�r )rtrNrIrPrS�childrHrHrIrL�s

zPytester.spawnr)r�r�)r
)rH)rG)Tr�r�r�r��__test__rrY�__annotations__r�r\r&r3r(rpr��propertyrrVrir�rqr!ror"r�r�rMrrrr�rr�r�r�r�rr�r�r�r�rr�r�r�r�rr)r*r�r�rr�r�r�rr�r�r*rrBrrr�r�rrrrCrlrrrr	r!rFrhr3r>rArBrrOrLrHrHrHrIr�sL
	�����
�-

���
��
�" 
��
�-�
�

�
�

�"�
��
�G
��
�,
��
��
��
��
���
�
�"��
���
�
�
�)�
���
�V�
��
����
�c@s,eZdZddd�Zdeeddfdd�ZdS)	rr9NcCst�|_dSr�)r�stringior}rHrHrIr�
szLineComp.__init__r�cCsBd}|j��}|j�d�|j�d�|�d�}t|��|�dS)z�Assert that ``lines2`` are contained (linearly) in :attr:`stringio`'s value.

        Lines are matched using :func:`LineMatcher.fnmatch_lines <pytest.LineMatcher.fnmatch_lines>`.
        TrrdN)rYrM�truncate�seekrqr�
fnmatch_lines)rtr�r��valr�rHrHrI�assert_contains_liness

zLineComp.assert_contains_linesr)r�r�r�r�rrir^rHrHrHrIrs
c@s�eZdZdZdeeddfdd�Zdefdd�Zd	eee	ee
fde	efd
d�Zd	e	eddfdd
�Zd	e	eddfdd�Z
d	e	edeeegefddfdd�Zdede	efdd�Zd0dd�Zedefdd��Zdd�d	e	ededdfdd�Zdd�d	e	ededdfdd �Zdd�d	e	edeeegefd!ededdf
d"d#�Zd$eddfd%d&�Zd$eddfd'd(�Zd$edeeegefd!eddfd)d*�Zd+eddfd,d-�Zdefd.d/�ZdS)1rz�Flexible matching of text.

    This is a convenience class to test large texts like the output of
    commands.

    The constructor takes a list of lines without their trailing newlines, i.e.
    ``text.splitlines()``.
    r�r9NcCs||_g|_dSr�)r��_log_output)rtr�rHrHrIr�(s
zLineMatcher.__init__cC�d�|j�S)zReturn the entire original text.

        .. versionadded:: 6.2
            You can use :meth:`str` in older versions.
        rd)r�r�r}rHrHrI�__str__,r�zLineMatcher.__str__r�cCs*t|t�r	t|�}t|t�r|��j}|Sr�)r�rirr�r�)rtr�rHrHrI�	_getlines4s



zLineMatcher._getlinescCsd}|�|t�dS)zTCheck lines exist in the output in any order (using :func:`python:fnmatch.fnmatch`).TN)�_match_lines_randomr�rtr�r�rHrHrI�fnmatch_lines_random;sz LineMatcher.fnmatch_lines_randomcCsd}|�|dd��dS)zMCheck lines exist in the output in any order (using :func:`python:re.match`).TcS�tt�||��Sr��rp�re�match�r��patrHrHrI�<lambda>C�z3LineMatcher.re_match_lines_random.<locals>.<lambda>N)rcrdrHrHrI�re_match_lines_random@sz!LineMatcher.re_match_lines_random�
match_funccCsjd}|�|�}|D])}|jD]}||ks|||�r#|�dt|��nqd|}|�|�|�|�q	dS)NTz	matched: �line %r not found in output)rbr��_logr��_fail)rtr�ror�r[r��msgrHrHrIrcEs

�

��zLineMatcher._match_lines_random�fnlinecCsHt|j�D]\}}||kst||�r|j|dd�Sqtd|��)zsReturn all lines following the given line in the text.

        The given line can contain glob wildcards.
        rfNrp)r�r�rr)rtrtr�r[rHrHrI�get_lines_afterTs
�zLineMatcher.get_lines_aftercGs |j�d�dd�|D���dS)NrJcsr�r�r�r�rHrHrIr�_r�z#LineMatcher._log.<locals>.<genexpr>)r_rsr�)rtr�rHrHrIrq^s zLineMatcher._logcCr`)Nrd)r�r_r}rHrHrI�	_log_textaszLineMatcher._log_textF��consecutiverxcCsd}|j|td|d�dS)a�Check lines exist in the output (using :func:`python:fnmatch.fnmatch`).

        The argument is a list of lines which have to match and can use glob
        wildcards.  If they do not match a pytest.fail() is called.  The
        matches and non-matches are also shown as part of the error message.

        :param lines2: String patterns to match.
        :param consecutive: Match lines consecutively?
        TrrwN)�_match_linesr�rtr�rxr�rHrHrIr\eszLineMatcher.fnmatch_linescCsd}|j|dd�d|d�dS)a�Check lines exist in the output (using :func:`python:re.match`).

        The argument is a list of lines which have to match using ``re.match``.
        If they do not match a pytest.fail() is called.

        The matches and non-matches are also shown as part of the error message.

        :param lines2: string patterns to match.
        :param consecutive: match lines consecutively?
        TcSrfr�rgrjrHrHrIrl�rmz,LineMatcher.re_match_lines.<locals>.<lambda>�re.matchrwN)ryrzrHrHrI�re_match_linests

�zLineMatcher.re_match_lines�match_nicknamecCs|t|tjj�stdt|�j����|�|�}|jdd�}g}d}t	|�d}d}	|D]�}
d}|r�|�
d�}|
|krE|�dt|
��d}	ns|||
�rd|�d|t|
��|�d	j
d
|d�t|��d}	nT|r�|	r�d|
��}
|�|
�|�d	j
d
|d�t|��|�|
�|s�|�d	j
d
|d�t|
��d}|�d	j
d|d�t|��|�|�|s1d|
��}
|�|
�|�|
�q+g|_dS)aqUnderlying implementation of ``fnmatch_lines`` and ``re_match_lines``.

        :param Sequence[str] lines2:
            List of string patterns to match. The actual format depends on
            ``match_func``.
        :param match_func:
            A callable ``match_func(line, pattern)`` where line is the
            captured line from stdout/stderr and pattern is the matching
            pattern.
        :param str match_nickname:
            The nickname for the match function that will be logged to stdout
            when a match occurs.
        :param consecutive:
            Match lines consecutively?
        zinvalid type for lines2: NTrfFrzexact match:z%s:�{:>{width}}�with:��widthzno consecutive match: �nomatch:�and:zremains unmatched: )r��collections�abcr�	TypeErrorr�r�rbr�r�r�rqr�rrrrsr_)rtr�ror}rxr��
extralinesr��wnick�startedr[�nomatchprinted�nextlinersrHrHrIry�sV


�

�
�
�


�
zLineMatcher._match_linesrkcCsd}|�|td�dS)z�Ensure captured lines do not match the given pattern, using ``fnmatch.fnmatch``.

        :param str pat: The pattern to match lines.
        TrN)�_no_match_liner�rtrkr�rHrHrI�no_fnmatch_line�szLineMatcher.no_fnmatch_linecCsd}|�|dd�d�dS)z�Ensure captured lines do not match the given pattern, using ``re.match``.

        :param str pat: The regular expression to match lines.
        TcSrfr�rgrjrHrHrIrl�rmz.LineMatcher.no_re_match_line.<locals>.<lambda>r{N)r�r�rHrHrI�no_re_match_line�s
�zLineMatcher.no_re_match_linec	Cs�d}d}t|�d}|jD]D}|||�r3|�d|��}|�|�|�djd|d�t|��|�|�q
|sD|�djd|d�t|��d}|�djd	|d�t|��q
g|_d
S)z�Ensure captured lines does not have a the given pattern, using ``fnmatch.fnmatch``.

        :param str pat: The pattern to match lines.
        TFrfz: r~rr�r�r�N)r�r�rqrr�rrr_)	rtrkror}r��nomatch_printedr�r[rsrHrHrIr��s



zLineMatcher._no_match_linerscCsd}|j}g|_t|�dS)NT)rvr_r+)rtrsr��log_textrHrHrIrr�szLineMatcher._failcCr�)z Return the entire original text.r�r}rHrHrIri�szLineMatcher.strr)r�r�r�r�rrir�rarrrrbrernrrprcrurqrXrvr\r|ryr�r�r�rrrHrHrHrIrsv	$��
�

���
����
������
�C
���
�)r9r)sr��collections.abcr�r4r�r�rnrjr1rhr�rCr�r�r�ior�pathlibr�typingrrrrr	r
rrr
rrrrrr�weakrefr�	iniconfigrrr�r�
_pytest._coder�_pytest.capturer�_pytest.compatrrrr'rrrr r!r"�_pytest.config.argparsingr#�_pytest.deprecatedr$�_pytest.fixturesr%r&�_pytest.mainr'�_pytest.monkeypatchr(�
_pytest.nodesr)r*�_pytest.outcomesr+r,r-�_pytest.pathlibr.r/r0�_pytest.reportsr1r2�_pytest.tmpdirr3�_pytest.warning_typesr4�typing_extensionsr5r6rP�pytest_pluginsrrrJrTrNr�rir�r�r�rrrr%r)�compiler<r>r*rIr!r rrrrHrHrHrI�<module>s��
E
Z	����
	
j~