
    9[gp                       d Z ddlmZ ddl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ZddlZddlmZ ddlZddlZddl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l0m1Z1 ddl0m2Z2 ddl0m3Z3 ddl0m4Z4 ddl0m5Z5 dd l0m6Z6 dd!l7m8Z8 dd"l9m:Z: dd#l;m<Z< dd$l;m=Z= dd%l>m?Z? dd&l@mAZA dd'lBmCZC dd(lBmDZD dd)lEmFZF dd*lEmGZG dd+lEmHZH dd,lImJZJ dd-lImKZK dd.lLmMZM dd/lLmNZN dd0lOmPZP dd1lQmRZR e!rddlSZSd2gZTd3gZUdTd4ZVdUd5ZW G d6 d7      ZXe<dVd9       Z' G d: d8      ZYdWd;ZZe G d< d=             Z[e G d> d?             Z\e<dXdA       Z] e<dBC      dYdD       Z^e<	 	 	 	 	 	 	 	 dZdF       Z_e<d[dG       Z`e<d\dH       Za ej                  dI      Zc ej                  dJ      Zde G dK dL             Ze G dM dN      Zf G dO dP      Zge G dQ dE             Zh G dR d@      Zi G dS dB      Zjy)]zZ(Disabled by default) support for testing pytest and pytest plugins.

PYTEST_DONT_REWRITE
    )annotationsN)fnmatch)StringIO)Path)Any)Callable)Final)final)	Generator)IO)Iterable)Literal)overload)Sequence)TextIO)TYPE_CHECKING)WeakKeyDictionary)	IniConfig)SectionWrapper)timing)Source)_get_multicapture)NOTSET)
NotSetType)_PluggyPlugin)Config)ExitCode)hookimpl)main)PytestPluginManager)Parser)check_ispytest)fixture)FixtureRequest)Session)MonkeyPatch)	Collector)Item)fail)importorskip)skip)bestrelpath)make_numbered_dir)CollectReport)
TestReport)TempPathFactory)PytestWarningpytester_assertionsz/var/lib/sss/mc/passwdc                    | j                  ddddd       | j                  ddd	d
d       | j                  dd       y )Nz--lsof
store_truelsofFz"Run FD checks if lsof is available)actiondestdefaulthelp--runpytest	inprocess	runpytest)r;   
subprocesszYRun pytest sub runs in tests using an 'inprocess' or 'subprocess' (python -m main) method)r8   r7   choicesr9   pytester_example_dirz1Directory to take the pytester example files from)r9   )	addoptionaddini)parsers    K/var/www/html/bid-api/venv/lib/python3.12/site-packages/_pytest/pytester.pypytest_addoptionrD   S   sc    
1   +6  	 MM%X      c                    | j                  d      r5t               }|j                         r| j                  j	                  |       | j                  dd       y )Nr5   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)configcheckers     rC   pytest_configurerP   l   sL    v#%$$&  ))'2
	<rE   c                  >    e Zd ZddZddZ edd      d	d       Zy)
rI   c           	     (   t         j                  dk\  rt        j                         }nt        j                  d      }t        j                  dddt        t        j                               ft
        j                  t
        j                  dd|      j                  }dd}g }|j                  d	      D ]Z  } ||      s|j                  d
      }|d   dd  }|d   dd  }|t        v r6|j                  d      sH|j!                  ||f       \ |S )N)      Fr5   z-Ffn0-pT)stdoutstderrchecktextencodingc                T    | j                  d      xr d| vxr d| vxr
 d| vxr d| vS )Nfdeletedmemtxtcwd
startswith)lines    rC   isopenz0LsofFdLeakChecker.get_open_files.<locals>.isopen   sI    ??3' % &%&%& %	rE   
 r      /)rc   strreturnbool)sysversion_infolocalegetencodinggetpreferredencodingr=   runri   osgetpidPIPEDEVNULLrV   split
IGNORE_PAMrb   append)	selfrZ   outrd   
open_filesrc   fieldsfdfilenames	            rC   get_open_filesz LsofFdLeakChecker.get_open_filesz   s    w&))+H2259HnnWdC		$45??%%
 & 		 
IIdODd|D)AYqr]!!9QR=z)&&s+%%r8n5 $ rE   c                r    	 t        j                  dd       y# t        t         j                  f$ r Y yw xY w)N)r5   z-vT)rX   F)r=   rq   OSErrorCalledProcessErrorry   s    rC   rJ   z#LsofFdLeakChecker.matching_platform   s9    	NN>6  667 		s    66T)wrappertryfirstc           	   #  \  K   | j                         }	 d t        t        d      rt        j                          | j                         }|D ch c]  }|d   	 c}|D ch c]  }|d   	 c}z
  }|D cg c]  }|d   |v s| }}|rdt        |       dgd |D        dd |D        dd	 |D        dt        |       d d
j                  |j                   d}|j                  t        dj                  |                   S S c c}w c c}w c c}w # t        t        d      rt        j                          | j                         }|D ch c]  }|d   	 nc c}w c}|D ch c]  }|d   	 nc c}w c}z
  }|D cg c]  }|d   |v s| nc c}w }}|rdt        |       dgd |D        dd |D        dd	 |D        dt        |       d d
j                  |j                   d}|j                  t        dj                  |                   w w xY ww)Npypy_version_infor   z***** z FD leakage detectedc              3  2   K   | ]  }t        |        y wNri   .0r\   s     rC   	<genexpr>z<LsofFdLeakChecker.pytest_runtest_protocol.<locals>.<genexpr>   s     3lc!fl   z*** Before:c              3  2   K   | ]  }t        |        y wr   r   r   s     rC   r   z<LsofFdLeakChecker.pytest_runtest_protocol.<locals>.<genexpr>        -fc!ffr   z
*** After:c              3  2   K   | ]  }t        |        y wr   r   r   s     rC   r   z<LsofFdLeakChecker.pytest_runtest_protocol.<locals>.<genexpr>   r   r   z*** function {}:{}: {} zSee issue #2366re   )r   hasattrrl   gccollectlenformatlocationwarnr1   join)ry   itemlines1lines2tnew_fdsleaked_fileserrors           rC   pytest_runtest_protocolz)LsofFdLeakChecker.pytest_runtest_protocol   s    $$&	;s/0

((*F%+,VqtV,f/Ef!f/EEG'-Av!1AvLAS.//CD
3l3
 "
 .f-	

 !
 .f-
 S.//CD
 5-44dmmD
 &
 		-		%(89:  -/EA s/0

((*F%+,VqtV,f/Ef!f/EEG'-Av!1AvALAS.//CD
3l3
 "
 .f-	

 !
 .f-
 S.//CD
 5-44dmmD
 &
 		-		%(89: sq   H,D 8H,DH,!D-	H,6DDBH,9H)E$#H)/E<
;H)
FFBH))H,N)rj   zlist[tuple[str, str]])rj   rk   )r   r(   rj   zGenerator[None, object, object])__name__
__module____qualname__r   rJ   r   r    rE   rC   rI   rI   y   s(    #J dT*; +;rE   rI   	PytestArgc                    t        |       S )zReturn a helper which offers a gethookrecorder(hook) method which
    returns a HookRecorder instance which helps to make assertions about called
    hooks.)r   requests    rC   _pytestr      s    
 WrE   c                      e Zd ZddZddZy)r   c                    || _         y r   )_request)ry   r   s     rC   __init__zPytestArg.__init__   s	    rE   c                z    t        |j                        }| j                  j                  |j                         |S r   )HookRecorder_pmr   addfinalizerfinish_recording)ry   hookhookrecorders      rC   gethookrecorderzPytestArg.gethookrecorder   s.    #DHH-""<#@#@ArE   N)r   r$   rj   None)rj   r   )r   r   r   r   r   r   rE   rC   r   r      s     rE   c                >    | D cg c]  }|d   dk7  s| c}S c c}w )zDOnly return names from iterator values without a leading underscore.r   _r   )valuesxs     rC   get_public_namesr      s$    -v!1Av---s   c                  .    e Zd ZdZddZddZerddZyy)	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
    c                H    | j                   j                  |       || _        y r   )__dict__update_name)ry   namekwargss      rC   r   zRecordedHookCall.__init__   s    V$
rE   c                b    | j                   j                         }|d= d| j                  d|dS )Nr   z<RecordedHookCall z(**z)>)r   copyr   )ry   ds     rC   __repr__zRecordedHookCall.__repr__   s4    MM gJ#DJJ>QE<<rE   c                     y r   r   )ry   keys     rC   __getattr__zRecordedHookCall.__getattr__   s    rE   N)r   ri   rj   r   rj   ri   )r   ri   )r   r   r   __doc__r   r   r   r   r   rE   rC   r   r      s    
=
 , rE   r   c                  `   e Zd ZdZdd	 	 	 	 	 ddZddZddZddZddZdd	Z	e
	 	 	 	 dd
       Ze
	 	 	 	 dd       Ze
	 d 	 	 	 d!d       Z	 d 	 	 	 d!dZ	 	 	 d"	 	 	 	 	 	 	 d#dZe
	 	 	 	 dd       Ze
	 	 	 	 dd       Ze
	 d 	 	 	 d!d       Z	 d 	 	 	 d!dZd$dZ	 	 d%dZd&dZd'd(dZddZy))r   zRecord 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	_ispytestc                    t        |       | _        g  _        d  _        d fd}dd}|j	                  ||       _        y )Nc                P    j                   j                  t        | |             y r   )callsrx   r   )	hook_name
hook_implsr   ry   s      rC   beforez%HookRecorder.__init__.<locals>.before  s    JJ.y&ABrE   c                     y r   r   )outcomer   r   r   s       rC   afterz$HookRecorder.__init__.<locals>.after  s    rE   )r   ri   rj   r   )r"   _pluginmanagerr   retadd_hookcall_monitoring_undo_wrapping)ry   rK   r   r   r   s   `    rC   r   zHookRecorder.__init__  sE     	y!+-/
*.	C	 ,CCFERrE   c                $    | j                          y r   )r   r   s    rC   r   zHookRecorder.finish_recording  s    rE   c                    t        |t              r|j                         }| j                  D cg c]  }|j                  |v s| c}S c c}w )z?Get all recorded calls to hooks with the given names (or name).)
isinstanceri   rv   r   r   )ry   namescalls      rC   getcallszHookRecorder.getcalls  s>    eS!KKME!%CtzzU/BCCCs   A
A
c                   d}d}t        |      }t        t        j                  d      j                        }|r|j                  d      \  }}t        | j                  |d        D ]  \  }}|j                  |k(  r^t        d||       t        |||j                        rt        dt        |      d|       nt        dt        |      d|       i||dz   z  } n!t        d	|d
|        t        d|d|       |ry y )NTr   rg   	NAMEMATCHCHECKERMATCHz->NOCHECKERMATCH-NONAMEMATCHwithzcould not find z check )listdictrl   	_getframef_localspop	enumerater   r   printevalr   reprr)   )	ry   entries__tracebackhide__i
backlocalsr   rX   indr   s	            rC   assert_containszHookRecorder.assert_contains  s     w-#--*334
!++a.KD%&tzz!"~6	T::%+tT2E:t}}=nd5k4F.US$G qLAmT648 7 thgeY?@ rE   c                &   d}t        | j                        D ]%  \  }}|j                  |k(  s| j                  |= |c S  d|dg}|j                  | j                  D cg c]  }d| 	 c}       t	        dj                  |             y c c}w )NTzcould not find call z, in:z  re   )r   r   r   extendr)   r   )ry   r   r   r   r   linesr   s          rC   popcallzHookRecorder.popcall2  s      ,GAtzzT!JJqM - (xu56

3
11#h
34TYYu 4s    Bc                \    | j                  |      }t        |      dk(  s	J ||f       |d   S )Nrg   r   )r   r   )ry   r   r   s      rC   getcallzHookRecorder.getcall<  s5    t$6{a/$/ayrE   c                     y r   r   ry   r   s     rC   
getreportszHookRecorder.getreportsC       #&rE   c                     y r   r   r  s     rC   r  zHookRecorder.getreportsI        #rE   c                     y r   r   r  s     rC   r  zHookRecorder.getreportsO       03rE   c                ^    | j                  |      D cg c]  }|j                   c}S c c}w r   )r   report)ry   r   r   s      rC   r  zHookRecorder.getreportsX  s+     #'--"67"6Q"6777s   *Nc                `   g }| j                  |      D ]c  }|s|j                  dk7  r|j                  r!|r|j                  |k7  r3|r||j                  j	                  d      v sS|j                  |       e |st        d|d      t        |      dkD  rt        d|d|       |d	   S )
z5Return a testreport whose dotted import path matches.)r   r   ::z$could not find test report matching z: no test reports at all!rg   z%found 2 or more testreports matching : r   )r  whenpassednodeidrv   rx   
ValueErrorr   )ry   	inamepartr   r  r   reps         rC   matchreportzHookRecorder.matchreporta  s     ???/CCHH.3::D(	SZZ-=-=d-C Cc" 0 6ym D* *  v;?7	}BvhO  ayrE   c                     y r   r   r  s     rC   getfailureszHookRecorder.getfailures  r  rE   c                     y r   r   r  s     rC   r  zHookRecorder.getfailures  r  rE   c                     y r   r   r  s     rC   r  zHookRecorder.getfailures  r  rE   c                d    | j                  |      D cg c]  }|j                  s| c}S c c}w r   )r  failed)ry   r   r  s      rC   r  zHookRecorder.getfailures  s-      $u5D55DDDs   --c                $    | j                  d      S )Npytest_collectreport)r  r   s    rC   getfailedcollectionsz!HookRecorder.getfailedcollections  s     677rE   c                N   g }g }g }| j                  d      D ]  }|j                  r4|j                  dk(  st        |t              sJ |j                  |       C|j                  r|j                  |       a|j                  s
J d|       |j                  |        |||fS )Nr  pytest_runtest_logreportr   zUnexpected outcome: )r  r  r  r   r/   rx   skippedr  )ry   r  r   r  r  s        rC   listoutcomeszHookRecorder.listoutcomes  s     ??@
C zz88v%%c:666MM#&s#zzA%9##AAzc"
 w&&rE   c                Z    | j                         D cg c]  }t        |       c}S c c}w r   )r!  r   )ry   r   s     rC   countoutcomeszHookRecorder.countoutcomes  s)     $ 1 1 34 31A 3444s   (c                L    d}ddl m} | j                         } |||||       y )NTr   )assertoutcome)r  r   r  )_pytest.pytester_assertionsr%  r!  )ry   r  r   r  r   r%  outcomess          rC   r%  zHookRecorder.assertoutcome  s-     =$$&		
rE   c                "    g | j                   d d  y r   )r   r   s    rC   clearzHookRecorder.clear  s    

1rE   )rK   r    r   rk   rj   r   rj   r   )r   str | Iterable[str]rj   zlist[RecordedHookCall])r   zSequence[tuple[str, str]]rj   r   )r   ri   rj   r   )r   zLiteral['pytest_collectreport']rj   Sequence[CollectReport])r   z#Literal['pytest_runtest_logreport']rj   zSequence[TestReport])r  )r   r+  rj   z$Sequence[CollectReport | TestReport]) )r  r  N)r  ri   r   r+  r  
str | Nonerj   zCollectReport | TestReport)rj   r,  )rj   zgtuple[Sequence[TestReport], Sequence[CollectReport | TestReport], Sequence[CollectReport | TestReport]])rj   z	list[int])r   r   r   )r  intr   r/  r  r/  rj   r   )r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r!  r#  r%  r)  r   rE   rC   r   r      s    HMS0S@DS	S"DA, &.& 
!& &
 #2# 
# #
 &
3"3 
.3 3&
8"8 
.8 &
   #  
$< &.& 
!& &
 #2# 
# #
 &
3"3 
.3 3&
E"E 
.E8'
'05

rE   r   LineCompc                     t               S )zeA :class: `LineComp` instance for checking that an input linearly
    contains a sequence of strings.)r0  r   rE   rC   linecompr2    s     :rE   LineMatcherr   c                    t         S )zA 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.
    )r3  r   s    rC   LineMatcher_fixturer6    s
     rE   Pytesterc                     t        | ||d      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   )r7  )r   tmp_path_factorymonkeypatchs      rC   pytesterr;    s     G-{dKKrE   c               #  |   K   t               } t               }d  |j                          | j                          y wr   )SysPathsSnapshotSysModulesSnapshotrestore)	snappathssnapmodss     rC   _sys_snapshotrB    s1      "I!#H	s   :<c               #  N   K   ddl m}   |        }| |j                          y w)Nr   )
get_config)_pytest.configrD  _ensure_unconfigure)rD  rN   s     rC   _config_for_testrG    s!     )\F
L
 s   #%z
\d+\.\d\dsz(\d+) (\w+)c                      e Zd ZdZ	 	 	 	 	 	 	 	 	 	 ddZd	dZd
dZed
d       Z	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	y)	RunResultz?The result of running a command from :class:`~pytest.Pytester`.c                    	 t        |      | _        	 || _        	 || _        	 t        |      | _        	 t        |      | _        	 || _        y # t        $ r
 || _        Y Lw xY wr   )	r   r   r  outlineserrlinesr3  rV   rW   duration)ry   r   rK  rL  rM  s        rC   r   zRunResult.__init__	  so    	'/}DH# !1 1!(+	
 "(+5 "  	DH	s   A A A c                    d| j                   t        | j                  j                        t        | j                  j                        | j
                  fz  S )NzK<RunResult ret=%s len(stdout.lines)=%d len(stderr.lines)=%d duration=%.2fs>)r   r   rV   r   rW   rM  r   s    rC   r   zRunResult.__repr__$  sB    YxxT[[../T[[5F5F1GWX	
rE   c                8    | j                  | j                        S )aU  Return 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_nounsrK  r   s    rC   parseoutcomeszRunResult.parseoutcomes*  s     ''66rE   c           	     V   t        |      D ]L  }t        j                  |      st        j	                  |      }|D ci c]  \  }}|t        |       }}} n t        d      ddd}|j                         D 	ci c]  \  }}	|j                  ||      |	 c}	}S c c}}w c c}	}w )a  Extract 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}``.
        z(Pytest terminal summary report not foundwarningserrors)warningr   )	reversedrex_session_durationsearchrex_outcomefindallr/  r  itemsget)
clsr   rc   r'  countnounr   	to_pluralkvs
             rC   rP  zRunResult.parse_summary_nouns6  s     UOD#**40&..t4=EFXMUDtSZ'XF	 $ GHH "
	 4799;?;41a	a#Q&;?? G @s   B>B%Nc	                V    d}	ddl m}
 | j                         } |
|||||||||	       y)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)r  r   r  rT  xpassedxfailedrS  
deselectedN)r&  rd  rQ  )ry   r  r   r  rT  re  rf  rS  rg  r   rd  r'  s               rC   rd  zRunResult.assert_outcomesN  s>    " !?%%'!
	
rE   )
r   zint | ExitCoderK  	list[str]rL  rh  rM  floatrj   r   r   )rj   zdict[str, int])r   r   r   r   r   r   NN)r  r/  r   r/  r  r/  rT  r/  re  r/  rf  r/  rS  
int | Nonerg  rj  rj   r   )
r   r   r   r   r   r   rQ  classmethodrP  rd  r   rE   rC   rI  rI    s    I## # 	#
 # 
#6

7 @ @2 #!%

 
 	

 
 
 
 
 
 

rE   rI  c                      e Zd ZdddZddZy)r>  Nc                N    || _         t        t        j                        | _        y r   )_SysModulesSnapshot__preserver   rl   modules_SysModulesSnapshot__saved)ry   preserves     rC   r   zSysModulesSnapshot.__init__q  s    "CKK(rE   c                ,     j                   r@ j                  j                   fdt        j                  j                         D               t        j                  j                          t        j                  j                   j                         y )Nc              3  P   K   | ]  \  }}j                  |      s||f  y wr   )rn  )r   ra  mry   s      rC   r   z-SysModulesSnapshot.restore.<locals>.<genexpr>w  s)       #641a$//!:LA#6s   &	&)rn  rp  r   rl   ro  r[  r)  r   s   `rC   r?  zSysModulesSnapshot.restoreu  s^    ??LL  #&;;#4#4#6   	4<<(rE   r   )rq  zCallable[[str], bool] | Nonerj   r   r*  r   r   r   r   r?  r   rE   rC   r>  r>  p  s    ))rE   r>  c                      e Zd ZddZddZy)r=  c                r    t        t        j                        t        t        j                        f| _        y r   )r   rl   path	meta_path_SysPathsSnapshot__savedr   s    rC   r   zSysPathsSnapshot.__init__  s    CHH~tCMM'::rE   c                f    | j                   \  t        j                  d d  t        j                  d d  y r   )rz  rl   rx  ry  r   s    rC   r?  zSysPathsSnapshot.restore  s!    (,%S]]1%rE   Nr*  ru  r   rE   rC   r=  r=  ~  s    ;5rE   r=  c                     e Zd ZU dZdZeZded<    G d de      Z	dd	 	 	 	 	 	 	 	 	 d:dZ
ed;d	       Zd<d
Zd=dZd>dZd?dZd=dZ	 d@	 	 	 	 	 	 	 	 	 dAdZdBdZdCdZdCdZdDdZdCdZd;dZd;dZdEdFdZdGdZdGdZdEdHdZdIdZdJdZdKdZ dLdZ!dMd Z"dNd!Z#d"dd#	 	 	 	 	 dOd$Z$	 	 	 	 	 	 dPd%Z%dPd&Z&	 	 	 	 dQd'Z'dRd(Z(dRd)Z)	 dS	 	 	 	 	 dTd*Z*dUd+Z+	 dVdd,	 	 	 dWd-Z,dXd.Z-e.j^                  e.j^                  ef	 	 	 	 	 	 	 dYd/Z0ded0	 	 	 	 	 	 	 dZd1Z1d2 Z2d[d3Z3d\d4Z4d]d5Z5dd6	 	 	 	 	 d^d7Z6d_d`d8Z7d_dad9Z8y)br7  an  
    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.
    Fr	   CLOSE_STDINc                      e Zd Zy)Pytester.TimeoutExpiredNr   r   r   r   rE   rC   TimeoutExpiredr    s    rE   r  r   c               ~   t        |       || _        t               | _        |j                  r|j                  j
                  }n|j                  j                  }|| _        |j                  |d      | _
        g | _        t               | _        | j                         | _        | j                  j!                  | j"                         | j                  j$                  j'                  d      | _        |j                  d| d      | _        |x| _        }| j/                          |j1                  dt3        | j*                               |j5                  dd       |j5                  d	d       t3        | j6                        }|j1                  d
|       |j1                  d|       |j1                  dd       y )NT)numberedr:   ztmp-PYTEST_DEBUG_TEMPROOTTOX_ENV_DIRF)raisingPYTEST_ADDOPTSHOMEUSERPROFILE	PY_COLORS0)r"   r   r   _mod_collectionsfunctionr   noder   r   mktemp_pathpluginsr=  _sys_path_snapshot$_Pytester__take_sys_modules_snapshot_sys_modules_snapshotr   	_finalizerN   	getoption_method_test_tmproot_monkeypatchchdirsetenvri   delenvrx  )ry   r   r9  r:  r   r   mptmphomes           rC   r   zPytester.__init__  sg    	y! 	 ((11D<<$$D
+224$2G

 35"2"4%)%E%E%G"""4>>2}}++55mD-44tD6]T4R!,,B


		)3t/A/A+BC
		-	/
		"E	2dii.
		&'"
		-)
		+s#rE   c                    | j                   S )zBTemporary directory path used to create files/run tests from, etc.)r  r   s    rC   rx  zPytester.path  s     zzrE   c                "    d| j                   dS )Nz
<Pytester >)rx  r   s    rC   r   zPytester.__repr__  s    DII=**rE   c                l    | j                   j                          | j                  j                          y)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)r  r?  r  r   s    rC   r  zPytester._finalize  s(     	""**,'')rE   c                     d }t        |      S )Nc                $    | j                  d      S )N)zopereadlinera   r4  s    rC   preserve_modulez=Pytester.__take_sys_modules_snapshot.<locals>.preserve_module  s    ??#788rE   )rq  )r>  )ry   r  s     rC   __take_sys_modules_snapshotz$Pytester.__take_sys_modules_snapshot  s    	9 "?;;rE   c                x    t        |d      x|_        }| j                  j                  |j                         |S )zFCreate a new :class:`HookRecorder` for a :class:`PytestPluginManager`.Tr   )r   reprecr   r   r   )ry   rK   r  s      rC   make_hook_recorderzPytester.make_hook_recorder  s3    (4]d(SSv""6#:#:;rE   c                N    | j                   j                  | j                         y)zaCd into the temporary directory.

        This is done automatically upon instantiation.
        N)r  r  rx  r   s    rC   r  zPytester.chdir  s    
 			*rE   c                z   t        |j                               }|t        d      |r"|j                  d      st	        d| d|       dfd|r:dj                  fd|D              }| j                  }|j                  d||f       d }|D ]  \  }}	| j                  j                  |      j                  |      }
|
j                  j                  d	d	
       t        |	      }dj                  fd|j                  D              }|
j                  |j!                                ||
} |J |S )Nzext must not be None.z1pytester.makefile expects a file extension, try .z instead of c                \    t        | t              r| j                        S t        |       S r   )r   bytesdecoderi   )srZ   s    rC   to_textz#Pytester._makefile.<locals>.to_text   s$    )3Au)=188H%I3q6IrE   re   c              3  .   K   | ]  } |        y wr   r   )r   r   r  s     rC   r   z%Pytester._makefile.<locals>.<genexpr>  s     95awqz5   r   T)parentsexist_okc              3  .   K   | ]  } |        y wr   r   )r   rc   r  s     rC   r   z%Pytester._makefile.<locals>.<genexpr>  s     Gwt}r  rZ   )r  zAny | bytesrj   ri   )r   r[  	TypeErrorrb   r  r   r   insertrx  joinpathwith_suffixparentmkdirr   r   
write_textstrip)ry   extr   filesrZ   r[  sourcebasenamer   valuepsource_r  s       `       @rC   	_makefilezPytester._makefile  s&    U[[]#;233s~~c*CC5UXTYZ 	J YY9599FzzHLLXv./$OHe		""8,88=AHHNN4$N7UmGYYGGGFLL(L;{  % 
rE   c                (    | j                  |||      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  )ry   r  argsr   s       rC   makefilezPytester.makefile  s    < ~~c400rE   c                &    | j                  |      S )zpWrite a conftest.py file.

        :param source: The contents.
        :returns: The conftest.py file.
        )conftest)
makepyfilery   r  s     rC   makeconftestzPytester.makeconftest4  s     //rE   c                (    | j                  d|      S )zhWrite a tox.ini file.

        :param source: The contents.
        :returns: The tox.ini file.
        z.ini)toxr  r  s     rC   makeinizPytester.makeini<  s     }}V}00rE   c                R    | j                  |      }t        t        |            d   S )z7Return the pytest section from the tox.ini config file.pytest)r  r   ri   )ry   r  r  s      rC   	getinicfgzPytester.getinicfgD  s$    LL Q **rE   c                (    | j                  d|      S )zWrite a pyproject.toml file.

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

        .. versionadded:: 6.0
        z.toml)	pyprojectr  r  s     rC   makepyprojecttomlzPytester.makepyprojecttomlI  s     }}W}77rE   c                (    | j                  d||      S )aS  Shortcut 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  ry   r  r   s      rC   r  zPytester.makepyfileS  s    $ ~~eT622rE   c                (    | j                  d||      S )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  s      rC   maketxtfilezPytester.maketxtfileg  s    $ ~~fdF33rE   Nc                h    || j                   }| j                  j                  t        |             y)zPrepend 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)rx  r  syspath_prependri   )ry   rx  s     rC   syspathinsertzPytester.syspathinsert{  s*     <99D))#d)4rE   c                D    | j                   |z  }|j                          |S )zCreate a new (sub)directory.

        :param name:
            The name of the directory, relative to the pytester path.
        :returns:
            The created directory.
        :rtype: pathlib.Path
        )rx  r  ry   r   r  s      rC   r  zPytester.mkdir  s      II		rE   c                    | j                   |z  }|j                          |j                  d      j                          |S )zCreate 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)rx  r  r  touchr  s      rC   mkpydirzPytester.mkpydir  s5     II			

=!'')rE   c                   | j                   j                  j                  d      }|t        d      | j                   j                  j                  |z  }| j                   j
                  j                  d      D ])  }|j                  sJ  |j                  |j                   }+ |O| j                  }||z  }||dz   z  }|j                         r|}n4|j                         r|}n!t        | d|       |j                  |      }|j                         rN|j                  d      j                         s/t        j                  || j                  dd       | j                  S |j                         r=| j                  j                  |j                         }	t        j"                  ||	       |	S t        d	| d
      )zCopy 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``).
        :rtype: pathlib.Path
        r?   z2pytester_example_dir is unset, can't copy examplespytester_example_pathr  z( can't be found as module or package in r  T)symlinksdirs_exist_okz	example "z%" is not found as a file or directory)r   rN   getinir  rootpathr  iter_markersr  r  r   is_diris_fileLookupErrorshutilcopytreerx  r   r   )
ry   r   example_dir_example_dirextra_element	func_name	maybe_dir
maybe_fileexample_pathresults
             rC   copy_examplezPytester.copy_example  s    }}++223IJQRR MM0099LH!]]//<<=TUM %%%%.+..0B0BCK V <

I#i/I$	E(9:J!(##%)! k!I+W  '//5L )>)>})M)U)U)WOOL$))dRVW99!!#YY''(9(9:FKKf-ML>)NO rE   c                l   t        j                  |      }dt        |      vsJ t        t        j
                  j                  |            }|j                  j                  |       |j                  t        |      gd      d   }|j                  j                  |t        j                         |S )a  Get 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_configri   r   rr   rx  abspathr   pytest_sessionstartperform_collectpytest_sessionfinishr   OK)ry   rN   argr  r  ress         rC   getnodezPytester.getnode  s     %%f-3s8###%&'''8%%s1vh%?B((X[[(Q
rE   c                P   t        |      }| j                  |      }t        j                  |      }t	        |j
                  |      }|j                  j                  |       |j                  |gd      d   }|j                  j                  |t        j                         |S )a  Return 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  r   r  )r   parseconfigurer%   r  r,   rx  r   r	  r
  r  r   r  )ry   rx  rN   r  r   r  s         rC   getpathnodezPytester.getpathnode  s     Dz$$T*%%f-d+'''8%%qcE%:1=((X[[(Q
rE   c                v    |d   j                   }g }|D ]"  }|j                  |j                  |             $ |S )a  Generate 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  )ry   colitemsr  r  colitems        rC   r  zPytester.genitems  s>     1+%%GMM'**734  rE   c                    | j                  |      }| j                  j                  }|j                         } ||      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.
        ``_pytest.runner.runtestprotocol``.
        )getitemr   instance	getrunner)ry   r  r   testclassinstancerunners        rC   runitemzPytester.runitem  s:     ||F# MM22",,.d|rE   c                `    | j                  |      }g t        |      |} | j                  | S )ag  Run 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)ry   r  cmdlineargsr  r   s        rC   inline_runsourcezPytester.inline_runsource  s7     OOF#(4$(a(t''rE   c                     | j                   dg| }|j                  d      D cg c]  }|j                   }}||fS c c}w )a"  Run ``pytest.main(['--collect-only'])`` 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-onlypytest_itemcollected)r  r   r   )ry   r  recr   r[  s        rC   inline_genitemszPytester.inline_genitems$  sN     doo.66!$.D!EF!EA!EFcz Gs   A r   )r  no_reraise_ctrlcc                   t        j                          t        |      }g }	 |j                   j	                         j
                         |j                  t               j
                         g  G  fdd      }|j                   |              t        |D cg c]  }t        |       c}|      }t              dk(  rj                         }n
 G d d      }||_        |t        j                  k(  r?|s=|j                  d      }	|	r*|	d   j                  j                   t"        k(  r
t#               ||D ]	  }
 |
         S c c}w # |D ]	  }
 |
         w xY w)	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.
        c                      e Zd Zd fdZy)$Pytester.inline_run.<locals>.Collectc                Z    j                  j                  |j                               y r   )rx   r  rK   )r   rN   r#  ry   s     rC   rP   z5Pytester.inline_run.<locals>.Collect.pytest_configure]  s     JJt66v7K7KLMrE   NrN   r   rj   r   )r   r   r   rP   )r#  ry   s   rC   Collectr(  \  s	    NrE   r+  )r  rg   c                      e Zd Zy)#Pytester.inline_run.<locals>.reprecNr  r   rE   rC   r  r-  f  s    rE   r  pytest_keyboard_interrupt)	importlibinvalidate_cachesr   rx   r  r?  r=  r   ri   r   r   r   r   INTERRUPTEDr   excinfotypeKeyboardInterrupt)ry   r  r%  r  
finalizersr+  r   r   r  r   	finalizerr#  s   `          @rC   r  zPytester.inline_run/  s6   2 	##%w-
(	
 d>>@HHI.0889 CN N NN79%-1A-w?C3x1}  FJ h***3C(CDU2Y..337HH+--'	 (% .$ (	 (s   A:E E1BE E E!c                "   |j                  dd      }|r| j                          t        j                         }t	        d      }|j                          	 	  | j                  |i |}|j                         \  }	}
|j                          t         j"                  j%                  |	       t         j&                  j%                  |
       |j(                  J t+        |j(                  |	j-                         |
j-                         t        j                         |z
        }||_        |S # t        $ rM}|j                  d   }	 t        |j                  d         }n# t        $ r Y nw xY w G d d      }Y d}~d}~wt        $ r" t        j                           G d d      }Y ?w xY w# |j                         \  }	}
|j                          t         j"                  j%                  |	       t         j&                  j%                  |
       w xY w)	ztReturn result of running pytest in-process, providing a similar
        interface to what self.runpytest() provides.r  Frl   r   c                      e Zd ZeZy),Pytester.runpytest_inprocess.<locals>.reprecN)r   r   r   r   r   rE   rC   r  r:    s    CrE   r  Nc                      e Zd Z ed      Zy)r:  rS   N)r   r   r   r   r   r   rE   rC   r  z,Pytester.runpytest_inprocess.<locals>.reprec  s    "1+CrE   )r   r  r   timer   start_capturingr  
SystemExitr  r   r  	Exception	traceback	print_exc
readouterrstop_capturingrl   rV   writerW   r   rI  
splitlinesr  )ry   r  r   r  nowcapturer  er   rz   errr  s               rC   runpytest_inprocesszPytester.runpytest_inprocessv  s   
 

?E: kkm#E*!	"&($9&9$ ))+HC""$JJS!JJS!zz%%%JJ(#..*:FKKMC<O
 

7  ffQi"166!9-C!    &##%& && ))+HC""$JJS!JJS!s[   D) )	F(2E:EE:	E'$E:&E''E:4F+ :*F($F+ 'F((F+ +A#Hc                    | j                  |      }| j                  dk(  r | j                  |i |S | j                  dk(  r | j                  |i |S t	        d| j                         )zRun pytest inline or in a subprocess, depending on the command line
        option "--runpytest" and return a :py:class:`~pytest.RunResult`.r;   r=   zUnrecognized runpytest option: )_ensure_basetempr  rJ  runpytest_subprocessRuntimeError)ry   r  r   new_argss       rC   r<   zPytester.runpytest  ss     ((.<<;&+4++X@@@\\\),4,,hA&AA<T\\NKLLrE   c                    t        |      }|D ]  }t        |      j                  d      s |S  |j                  dj	                  | j
                  j                  j                  d                   |S )Nz
--basetempz--basetemp={}basetemp)r   ri   rb   rx   r   rx  r  r  )ry   r  rO  r   s       rC   rL  zPytester._ensure_basetemp  sk     :A1v  .
   OO&&tyy'7'7'@'@'LM rE   c                    ddl }| j                  |      }|D cg c]  }t        |       }}|j                  j	                  || j
                        }| j                  j                  |j                         |S c c}w )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.
        r   N)	rE  rL  ri   rN   _prepareconfigr  r   r   rF  )ry   r  r   rO  r   rN   s         rC   parseconfigzPytester.parseconfig  sm     	((.$,-HqCFH-..xF 	""6#=#=> .s   A;c                D     | j                   | }|j                          |S )zReturn 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.
        )rT  _do_configure)ry   r  rN   s      rC   r  zPytester.parseconfigure  s'     "!!4(rE   c                v    | j                  |      }|D ]  }|j                  |k(  s|c S  J |d| d|        )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.
        z item not found in module:
z
items: )getitemsr   )ry   r  funcnamer[  r   s        rC   r  zPytester.getitem  sL      f%DyyH$  	VXL <VHIeWUUqrE   c                H    | j                  |      }| j                  |g      S )zReturn 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  )ry   r  modcols      rC   rX  zPytester.getitems  s%     ""6*}}fX&&rE   )withinitc               P   t        |t        j                        r$| j                  j	                  |      }|r0J d       | j
                  t        |      i} | j                  di |}|r| j                  d        | j                  |g| x| _	        }| j                  ||      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.
        znot supported for paths#)r   r   )r   rr   PathLikerx  r  r   ri   r  r  rN   r  )ry   r  
configargsr]  rx  kwrN   s          rC   r[  zPytester.getmodulecol  s    . fbkk*99%%f-D:!::<**c&k*B"4??(R(DOOSO)2t224E*EEf||FD))rE   c                    || j                   vr&t        |j                               | j                   |<   | j                   |   D ]  }|j                  |k(  s|c S  y)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)r  r   r   r   )ry   r\  r   r  s       rC   collect_by_namezPytester.collect_by_name  sY     ...,01A,BD!!&),,V4G||t# 5 rE   c           
        t         j                  j                         }t         j                  j	                  t        dt        j                         |j                  dd      g            |d<   ||d<   || j                  u rt        j                  |d<   n)t        |t              rt        j                  |d<   n||d<   t        j                  |f||d|}|| j                  u r*|j                  J |j                  j                          |S t        |t              r)|j                  J |j                  j!                  |       |S )zInvoke :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-  envstdin)rV   rW   )rr   environr   pathsepr   filtergetcwdr\  r}  r=   rt   r   r  Popenrh  closerD  )ry   cmdargsrV   rW   rh  rb  rg  popens           rC   rp  zPytester.popen-  s    jjooJJOO4"))+sww|R'@AB
L 5	D$$$$//BwKu%$//BwKBwK  MM"MD$$$;;***KK
 	 u%;;***KKe$rE   )timeoutrh  c          
     B    d}t        d D               j                  j                  d      } j                  j                  d      }t        dg  t        dt	        j
                                |j                  dd	      5 }|j                  dd	      5 }t        j                         }	 j                  |||t        j                  d
k7        j                  j                  j                          d fd}
j                         }n	 j                        }ddd       ddd       |j                  d	      5 }|j                  d	      5 }|j#                         j%                         }|j#                         j%                         }ddd       ddd        j'                  t        j(                          j'                  t        j*                         t-        j.                  t0              5  t3              }ddd       t5        ||t        j                         	z
        S # t        j                   $ r  |
        Y /w xY w# 1 sw Y   5xY w# 1 sw Y   :xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)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 ``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`.
        :type stdin: _pytest.compat.NotSetType | bytes | IO[Any] | int
        :returns:
            The result.

        Tc              3  F   K   | ]  }t        j                  |        y wr   )rr   fspath)r   r  s     rC   r   zPytester.run.<locals>.<genexpr>z  s     :'3		#'s   !rV   rW   zrunning:z     in:wutf8r  win32)rh  rV   rW   	close_fdsNc                 x    d}  d }j                          j                          j                  |      )NTz! second timeout expired running: )killwaitr  )r   timeout_messagero  rp  ry   rq  s     rC   handle_timeoutz$Pytester.run.<locals>.handle_timeout  s=    $(!%,I-Nwi"X



))/::rE   r*  )tuplerx  r  r   r   r`   openr   r<  rp  rl   platformrh  rn  r{  r=   r  readrE  _dump_linesrV   rW   
contextlibsuppressr  r   rI  )ry   rq  rh  ro  r   p1p2f1f2rF  r}  r   rz   rI  rp  s   `` `          @rC   rq   zPytester.runS  s   J !:'::YY)YY)j#7#j$((*%WWS6W*b"''#'2OSU++-CJJ<<72  E {{&!!#; ; jjl%**W-C3 3P*: WWfW%RWWfW-E'')&&(C'')&&(C .F% 	cjj)cjj)  ,3-C -c3(;<< "00 %"$%5 3P2O**: .F-E%% -,ss   I0 A>I#I0I0J	%=I="J	JI I#I  I##I-	(I00I:=J	J		JJc                j    	 |D ]  }t        ||        y # t        $ r t        d| d       Y y w xY w)N)filezcouldn't print to z because of encoding)r   UnicodeEncodeError)ry   r   fprc   s       rC   r  zPytester._dump_lines  s@    	Ad$ ! 	A&rd*>?@	As    22c                &    t         j                  dfS )Nz-mpytest)rl   
executabler   s    rC   _getpytestargszPytester._getpytestargs  s    ~~z))rE   c                B    | j                  t        j                  |      S )z8Run a python script using sys.executable as interpreter.rq   rl   r  )ry   scripts     rC   	runpythonzPytester.runpython  s    xx//rE   c                D    | j                  t        j                  d|      S )zRun ``python -c "command"``.z-cr  )ry   commands     rC   runpython_czPytester.runpython_c  s    xxg66rE   )rq  c                  d}t        | j                  dd      }d| g|}| j                  D cg c]  }t        |t              s| }}|r
d|d   g|}| j                         |z   } | j                  |d|iS c c}w )	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modez--basetemp=rU   r   rq  )r-   rx  r  r   ri   r  rq   )ry   rq  r  r   r  r   r  s          rC   rM  zPytester.runpytest_subprocess  s    & !499\NaS!)D)"llAljC.@1lA'!*,t,D""$t+txx/w//	 Bs   A?A?c                    | j                   dz  }|j                  d       dj                  t        t        | j                                     }| d| d| }| j                  ||      S )zRun 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-pexpectr  )r   z --basetemp=)expect_timeout)rx  r  r   mapri   r  spawn)ry   stringr  rQ  invokecmds         rC   spawn_pytestzPytester.spawn_pytest  sg     99~-E"#c4#6#6#89:XJax8zz#nz==rE   c                v   t        dd      }t        t        d      r!dt        j                         v rt        d       t        |d      st        d       | j                  j                  d      j                  d	      } |j                  |||
      }| j                  j                  |j                         |S )zMRun a command using pexpect.

        The pexpect child is returned.
        pexpectz3.0r   64zpypy-64 bit not supportedr  zpexpect.spawn not availablez	spawn.outwb)logfilerq  )r*   r   rl   r  machiner+   rx  r  r  r  r   r   rn  )ry   r  r  r  r  childs         rC   r  zPytester.spawn  s    
 y%03+,9I9I9K1K,-w(./))$$[166t<c7NK""7==1rE   )
r   r$   r9  r0   r:  r&   r   rk   rj   r   )rj   r   r   r*  )rj   r>  )rK   r    rj   r   )zutf-8)
r  ri   r   zSequence[Any | bytes]r  zdict[str, str]rZ   ri   rj   r   )r  ri   r  ri   r   ri   rj   r   )r  ri   rj   r   )r  ri   rj   r   r   )rx  zstr | os.PathLike[str] | Nonerj   r   )r   str | os.PathLike[str]rj   r   )r   r.  rj   r   )rN   r   r  r  rj   Collector | Item)rx  r  rj   r  )r  zSequence[Item | Collector]rj   
list[Item])r  ri   rj   r   )r  ri   rj   r   )rj   ztuple[list[Item], HookRecorder])r  r  r%  rk   rj   r   )r  r  r   r   rj   rI  )r   Sequence[str | os.PathLike[str]]rj   zlist[str | os.PathLike[str]])r  r  rj   r   )	test_func)r  r  rY  ri   rj   r(   )r  r  rj   r  )r   )r  r  r]  rk   )r\  r'   r   ri   rj   zItem | Collector | None)ro  r  rV   int | TextIOrW   r  rh  "NotSetType | bytes | IO[Any] | int)ro  r  rq  float | Nonerh  r  rj   rI  )rj   ztuple[str, ...])r  zos.PathLike[str]rj   rI  )r  ri   rj   rI  )r  r  rq  r  rj   rI  )g      $@)r  ri   r  ri  rj   pexpect.spawn)r  ri   r  ri  rj   r  )9r   r   r   r   __test__r   r}  __annotations__r?  r  r   propertyrx  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r$  r  rJ  r<   rL  rT  r  r  rX  r[  rd  r=   rt   rp  rq   r  r  r  r  rM  r  r  r   rE   rC   r7  r7    s    HK   *$*$ **$ !	*$ *$ 
*$X  +	*
<+  ## %# 	#
 # 
#J1@01+
83(4(5	,\&("(	 !&	E%E 	E
 
EN*+*7:*	*XM4	%0	 ?JV,V8;V	V,'  *
  *& *
  *D&  *)4?$1$ $ 	$
 2$R !%4?	S=(S= S= 2	S=
 
S=jA*07
 FJ0+06B0	08>rE   c                      e Zd ZddZddZy)r0  c                "    t               | _        y r   )r   stringior   s    rC   r   zLineComp.__init__  s     
DrE   c                    d}| j                   j                         }| j                   j                  d       | j                   j                  d       |j	                  d      }t        |      j                  |       y)zAssert that ``lines2`` are contained (linearly) in :attr:`stringio`'s value.

        Lines are matched using :func:`LineMatcher.fnmatch_lines <pytest.LineMatcher.fnmatch_lines>`.
        Tr   re   N)r  rH   truncateseekrv   r3  fnmatch_lines)ry   r   r   valr   s        rC   assert_contains_lineszLineComp.assert_contains_lines  s`    
 !mm$$&q!14F))&1rE   Nr*  r   Sequence[str]rj   r   )r   r   r   r   r  r   rE   rC   r0  r0    s    E
2rE   c                      e Zd ZdZddZddZddZddZddZ	 	 	 	 	 	 ddZ	ddZ
dd	Zedd
       Zdd	 	 	 	 	 ddZdd	 	 	 	 	 ddZdd	 	 	 	 	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 	 	 d dZd!dZddZy)"r3  zFlexible 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()``.
    c                     || _         g | _        y r   )r   _log_output)ry   r   s     rC   r   zLineMatcher.__init__  s    
&(rE   c                8    dj                  | j                        S )zReturn the entire original text.

        .. versionadded:: 6.2
            You can use :meth:`str` in older versions.
        re   )r   r   r   s    rC   __str__zLineMatcher.__str__  s     yy$$rE   c                    t        |t              rt        |      }t        |t              r|j                         j                  }|S r   )r   ri   r   r  r   )ry   r   s     rC   	_getlineszLineMatcher._getlines  s5    fc"F^Fff%\\^))FrE   c                4    d}| j                  |t               y)zTCheck lines exist in the output in any order (using :func:`python:fnmatch.fnmatch`).TN)_match_lines_randomr   ry   r   r   s      rC   fnmatch_lines_randomz LineMatcher.fnmatch_lines_random$  s       1rE   c                .    d}| j                  |d        y)zMCheck lines exist in the output in any order (using :func:`python:re.match`).Tc                @    t        t        j                  ||             S r   rk   rematchr   pats     rC   <lambda>z3LineMatcher.re_match_lines_random.<locals>.<lambda>,  s    4d@S;TrE   N)r  r  s      rC   re_match_lines_randomz!LineMatcher.re_match_lines_random)  s       )TUrE   c                    d}| j                  |      }|D ]f  }| j                  D ]-  }||k(  s
 |||      s| j                  dt        |              > d|d}| j                  |       | j	                  |       h y )NTz	matched: line  not found in output)r  r   _logr   _fail)ry   r   
match_funcr   rc   r   msgs          rC   r  zLineMatcher._match_lines_random.  s|     !'DZZ19
1d 3IIk4:6  
 dX%9:		#

3 rE   c                    t        | j                        D ]*  \  }}||k(  st        ||      s| j                  |dz   d c S  t        d|d      )zsReturn all lines following the given line in the text.

        The given line can contain glob wildcards.
        rg   Nr  r  )r   r   r   r  )ry   fnliner   rc   s       rC   get_lines_afterzLineMatcher.get_lines_after=  sW    
 !,GAt~v!6zz!a%'** - 5
*>?@@rE   c                f    | j                   j                  dj                  d |D                     y )Nr  c              3  2   K   | ]  }t        |        y wr   r   )r   r   s     rC   r   z#LineMatcher._log.<locals>.<genexpr>H  s     (>AQr   )r  rx   r   )ry   r  s     rC   r  zLineMatcher._logG  s%    (>(> >?rE   c                8    dj                  | j                        S )Nre   )r   r  r   s    rC   	_log_textzLineMatcher._log_textJ  s    yy))**rE   Fconsecutivec               :    d}| j                  |t        d|       y)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?
        Tr   r  N)_match_linesr   ry   r   r  r   s       rC   r  zLineMatcher.fnmatch_linesN  s!     !&'9+NrE   c               4    d}| j                  |d d|       y)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?
        Tc                @    t        t        j                  ||             S r   r  r  s     rC   r  z,LineMatcher.re_match_lines.<locals>.<lambda>m  s    d288C#67rE   re.matchr  N)r  r  s       rC   re_match_lineszLineMatcher.re_match_lines]  s)     !7#	 	 	
rE   c                  t        |t        j                  j                        s!t	        dt        |      j                         | j                  |      }| j                  dd }g }d}t        |      dz   }d}	|D ]  }
d}|rR|j                  d      }|
|k(  r| j                  dt        |
             d}	= |||
      rM| j                  | dt        |
             | j                  d	j                  d
|      t        |             d}	|rU|	rSd|
}| j                  |       | j                  d	j                  d
|      t        |             | j                  |       |s.| j                  d	j                  d|      t        |
             d}| j                  d	j                  d|      t        |             |j                  |       |rRd|
}| j                  |       | j                  |        g | _        y)aq  Underlying 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?
        zinvalid type for lines2: NTrg   Fr   zexact match::{:>{width}}with:widthzno consecutive match: nomatch:and:zremains unmatched: )r   collectionsabcr   r  r4  r   r  r   r   r   r  r   r   r  rx   r  )ry   r   r  match_nicknamer  r   
extralinesr   wnickstartedrc   nomatchprintednextliner  s                 rC   r  zLineMatcher._match_linesr  s   . &+//":":;7V8M8M7NOPP'A
 N#a'D"N!::a=8#IInd4j9"G$/II 02DJ?II%,,WE,BDN #G"w 6th?		#		)000FX 

3)		)0050I4PT: *.IIm2262GhX!!(+7 : ,D84		#

3C D rE   c                6    d}| j                  |t        d       y)zEnsure captured lines do not match the given pattern, using ``fnmatch.fnmatch``.

        :param str pat: The pattern to match lines.
        Tr   N)_no_match_liner   ry   r  r   s      rC   no_fnmatch_linezLineMatcher.no_fnmatch_line  s    
 !C)4rE   c                0    d}| j                  |d d       y)zEnsure captured lines do not match the given pattern, using ``re.match``.

        :param str pat: The regular expression to match lines.
        Tc                @    t        t        j                  ||             S r   r  r  s     rC   r  z.LineMatcher.no_re_match_line.<locals>.<lambda>  s    4d(;#<rE   r  N)r  r   s      rC   no_re_match_linezLineMatcher.no_re_match_line  s     
 !<j	
rE   c                   d}d}t        |      dz   }| j                  D ]  } |||      rV| d|}| j                  |       | j                  dj                  d|      t	        |             | j                  |       b|s.| j                  dj                  d|      t	        |             d}| j                  dj                  d	|      t	        |              g | _        y
)zEnsure captured lines does not have a the given pattern, using ``fnmatch.fnmatch``.

        :param str pat: The pattern to match lines.
        TFrg   r  r  r  r  r  r  N)r   r   r  r   r   r  r  )	ry   r  r  r  r   nomatch_printedr  rc   r  s	            rC   r  zLineMatcher._no_match_line  s     !N#a'JJD$$'(3'2		#		-..we.Dd4jQ

3&IIm22:U2KTRUYW&*O		-..vU.CT$ZP  rE   c                D    d}| j                   }g | _        t        |       y )NT)r  r  r)   )ry   r  r   log_texts       rC   r  zLineMatcher._fail  s      >>XrE   c                    t        |       S )z Return the entire original text.r   r   s    rC   ri   zLineMatcher.str  s    4yrE   N)r   rh  rj   r   r   )r   zstr | Sequence[str] | Sourcerj   r  r  )r   r  r  Callable[[str, str], bool]rj   r   )r  ri   rj   r  r*  )r   r  r  rk   rj   r   )
r   r  r  r
  r  ri   r  rk   rj   r   )r  ri   rj   r   )r  ri   r  r
  r  ri   rj   r   )r  ri   rj   r   )r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  ri   r   rE   rC   r3  r3    s"   )%2
V
 # 1K 	 A@ + + =BO#O59O	O  =B
#
59
	
6 "AA /A 	A A 
AF5
$>PS	.rE   )rB   r!   rj   r   r*  )r   r$   rj   r   )r   zIterable[str]rj   rh  )rj   r0  )r   r$   rj   ztype[LineMatcher])r   r$   r9  r0   r:  r&   rj   r7  )rj   zGenerator[None])rj   zGenerator[Config])kr   
__future__r   collections.abcr  r  r   r   r0  ior   rn   rr   pathlibr   r  r  r  r=   rl   r@  typingr   r   r	   r
   r   r   r   r   r   r   r   r   weakrefr   	iniconfigr   r   r   r   _pytest._coder   _pytest.capturer   _pytest.compatr   r   rE  r   r   r   r   r   r    _pytest.config.argparsingr!   _pytest.deprecatedr"   _pytest.fixturesr#   r$   _pytest.mainr%   _pytest.monkeypatchr&   _pytest.nodesr'   r(   _pytest.outcomesr)   r*   r+   _pytest.pathlibr,   r-   _pytest.reportsr.   r/   _pytest.tmpdirr0   _pytest.warning_typesr1   r  pytest_pluginsrw   rD   rP   rI   r   r   r   r   r2  r6  r;  rB  rG  compilerW  rY  rI  r>  r=  r7  r0  r3  r   rE   rC   <module>r"     sa  
 #    	    	   	   
               %  $    - ! % ( ! # #  . , - $ +   + #  ! ) ! ' - ) & * /  (( 

2
F; F;X 	 	 .
 - - -6 O O Od 	 	 	m  	LL/>LMXLL 	L  	 	 	! 	! "rzz-0 bjj( g
 g
 g
T) )5 5 k k k\2 2$_ _rE   