a
    f	g~                     @   sd  d 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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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/m0Z0 dd!l/m1Z1 dd"l2m3Z3 dd#l2m4Z4 erdd$l5m6Z6 e%dd%d&d'Z7e8e8d(d)d*Z9eeed+geee:e f  f ee:e f d,d-d.Z;eee:e f d/d0d1Z<ed+eee:e f  d2d3d4Z=d+dd5d6d7Z>d+e?d5d8d9Z@e	e?d(d:d;ZAe	eee? d<d=d>ZBeejC edd?d@dAZDG dBdC dCZEG dDdE dEeFZGG dFdG dGeHZIejJG dHdI dIee	e8f ZKeG dJd+ d+ejLZMe8e8dKdLdMZNdNdOe	e8e?ee	ee8 f dPdQdRZOdS )SzHCore implementation of the testing process: init, session, runtest loop.    N)Path)Callable)Dict)	FrozenSet)Iterator)List)Optional)Sequence)Set)Tuple)Type)TYPE_CHECKING)Union)nodes)final)overload)Config)directory_arg)ExitCode)hookimpl)PytestPluginManager)
UsageError)Parser)FixtureManager)exitabsolutepath)bestrelpath
fnmatch_ex)visit)CollectReport)
TestReport)collect_one_node)
SetupState)Literal)parserreturnc              	   C   s  | j dddg dd | j dddg d | dd	}|jd
dddddd | d}|jddddd | j dddd |jdddtdddd  |jd!d"d#d |jd$d"d%d |jd&d"d'd |jd(d)d*td+d,d- |jd.d"d/d0d1d2 |jd3dd4d5d6 | d7d8}|jd9d:d;d"d<d |jd=d"d>d |jd?dd@dAdB |jdCdd@dDdB |jdEddFdGdB |jdHdId dJtjtdHdKdLdM |jdNd"dOd/dPdQ |jdRdSd"dTd/dUdQ |jdVd"dWd/dXdQ |jdYdZg d[d\d]d^ | d_d`}|jdadbd t	dJdcdd d S )eNnorecursedirsz)Directory patterns to avoid for recursionargs)	z*.eggz.*_darcsbuildCVSdistZnode_modulesvenvz{arch})typedefaultZ	testpathszZDirectories to search for tests when no files or directories are given on the command lineZgeneralzRunning and selection optionsz-xz--exitfirststore_constmaxfail   z,Exit instantly on first error or failed test)actiondestconsthelpzpytest-warningsz-Wz--pythonwarningsappendz<Set which warnings to report, see -W option of Python itself)r4   r7   filterwarningsZlinelistz_Each line specifies a pattern for warnings.filterwarnings. Processed after -W/--pythonwarnings.)r/   r7   z	--maxfailnumstorer   z'Exit after first num failures or errors)metavarr4   r/   r5   r0   r7   z--strict-config
store_truezbAny warnings encountered while parsing the `pytest` section of the configuration file raise errorsz--strict-markerszVMarkers not registered in the `markers` section of the configuration file raise errorsz--strictz&(Deprecated) alias to --strict-markersz-cz--config-fileFILEZinifilenamezcLoad configuration from `FILE` instead of trying to locate one of the implicit configuration files.)r<   r/   r5   r7   z--continue-on-collection-errorsFcontinue_on_collection_errorsz4Force test execution even if collection errors occur)r4   r0   r5   r7   z	--rootdirrootdirzDefine root directory for tests. Can be relative path: 'root_dir', './root_dir', 'root_dir/another_dir/'; absolute path: '/home/user/root_dir'; path with variables: '$HOME/root_dir'.)r4   r5   r7   collect
collectionz--collectonlyz--collect-onlyz--coz&Only collect tests, don't execute themz--pyargsz1Try to interpret all arguments as Python packagesz--ignorepathz-Ignore path during collection (multi-allowed))r4   r<   r7   z--ignore-globz5Ignore path pattern during collection (multi-allowed)z
--deselectZnodeid_prefixzDDeselect item (via node id prefix) during collection (multi-allowed)z--confcutdirZ
confcutdirdir)optnamez1Only load conftest.py's relative to specified dir)r5   r0   r<   r/   r7   z--noconftestZ
noconftestz Don't load any conftest.py files)r4   r5   r0   r7   z--keepduplicatesz--keep-duplicateskeepduplicateszKeep duplicate testsz--collect-in-virtualenvcollect_in_virtualenvz2Don't ignore tests in a local virtualenv directoryz--import-modeprepend)rH   r8   	importlib
importmodez\Prepend/append to sys.path when importing test modules and conftest files. Default: prepend.)r0   choicesr5   r7   Zdebugconfigz(test session debugging and configurationz
--basetempZbasetempz^Base temporary directory for this test run. (Warning: this directory is removed if it exists.))r5   r0   r/   r<   r7   )
ZaddiniZgetgroupZ
_addoptionZ	addoptionintstr	functoolspartialr   validate_basetemp)r&   group rR   O/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/_pytest/main.pypytest_addoption2   s6   
				rT   rC   r'   c                 C   sl   d}| st |tttddd}|t t|  rDt ||t  t|  rht || S )NzWbasetemp must not be empty, the current working directory or any parent directory of it)basequeryr'   c                 S   s   | |krdS || j v S )z,Return whether query is an ancestor of base.T)parents)rV   rW   rR   rR   rS   is_ancestor   s    z&validate_basetemp.<locals>.is_ancestor)argparseArgumentTypeErrorr   boolcwdabsoluteresolve)rC   msgrY   rR   rR   rS   rP      s    


rP   Session)configdoitr'   c                 C   s  t | }tj|_d}z:z4|   d}| jj|d d}|| |pFd|_W nl tyl   tj	|_ Y nP t
y   tj|_Y n6 ttjfy   tjj }tj}t|jtjr|jjdur|jj}|dk rtj|j d|jj d | jj|d ||_Y n ty   tj|_tjj }z| || j  W nZ tjy } z>|jdurh|j|_tjt!|j" d| d W Y d}~n$d}~0 0 t|jt#rtjd	 Y n0 W d}t$%|j& |dkrJz| jj'||jd
 W nZ tjyH } z>|jdur|j|_tjt!|j" d| d W Y d}~n
d}~0 0 | (  nd}t$%|j& |dkrz| jj'||jd
 W nZ tjy } z>|jdur|j|_tjt!|j" d| d W Y d}~n
d}~0 0 | (  0 |jS )zSkeleton command line program.r   r3   session   Nz: 
)excinfoz(mainloop: caught unexpected SystemExit!
)re   
exitstatus))ra   from_configr   OKri   Z_do_configurehookZpytest_sessionstartr   ZUSAGE_ERRORFailedTESTS_FAILEDKeyboardInterruptr   	Exception_pytest_codeZExceptionInfoZfrom_currentZINTERRUPTED
isinstancevalue
returncodesysstderrwritetypenamer`   Zpytest_keyboard_interruptBaseExceptionINTERNAL_ERRORZnotify_exceptionoptionr/   __name__
SystemExitoschdir	startpathZpytest_sessionfinishZ_ensure_unconfigure)rb   rc   re   Z	initstaterh   ri   excrR   rR   rS   wrap_session  sz    

4

4


4
r   rb   r'   c                 C   s
   t | tS N)r   _mainrb   rR   rR   rS   pytest_cmdline_main<  s    r   )rb   re   r'   c                 C   s<   | j j|d | j j|d |jr(tjS |jdkr8tjS dS )z[Default command line protocol for initialization, session,
    running tests and reporting.rd   r   N)rl   pytest_collectionpytest_runtestlooptestsfailedr   rn   testscollectedZNO_TESTS_COLLECTED)rb   re   rR   rR   rS   r   @  s    
r   )re   r'   c                 C   s   |    d S r   )perform_collectrd   rR   rR   rS   r   M  s    r   c                 C   s   | j r2| jjjs2| d| j | j dkr(dndf | jjjr@dS t| jD ]b\}}|d t| jk rr| j|d  nd }|jj	j
||d | jr| | j| jrJ| | jqJdS )Nz%d error%s during collectionr3   s T)itemnextitem)r   rb   r|   r?   InterruptedZcollectonly	enumerateitemslenrl   Zpytest_runtest_protocol
shouldfailrm   
shouldstop)re   ir   r   rR   rR   rS   r   Q  s     
$r   c                    s`   |  tjdrdnd}z| s*W dS W n ty@   Y dS 0 d t fdd| D S )zAttempt to detect if ``path`` is the root of a Virtual Environment by
    checking for the existence of the appropriate activate script.winZScriptsbinF)activatezactivate.cshzactivate.fishZActivatezActivate.batzActivate.ps1c                 3   s   | ]}|j  v V  qd S r   name).0fnameZ	activatesrR   rS   	<genexpr>v      z_in_venv.<locals>.<genexpr>)joinpathrv   platform
startswithis_dirOSErroranyiterdir)rC   ZbindirrR   r   rS   _in_venve  s    
r   )collection_pathrb   r'   c                    s   |j d j|jd}|pg }|d}|r>|dd |D   |v rJdS |j d j|jd}|pdg }|d}|r|d	d |D  t fd
d|D rdS |d}|st rdS   r|d}t fdd|D rdS d S )NZcollect_ignore)rC   rootpathignorec                 s   s   | ]}t |V  qd S r   r   r   xrR   rR   rS   r     r   z(pytest_ignore_collect.<locals>.<genexpr>TZcollect_ignore_globZignore_globc                 s   s   | ]}t |V  qd S r   r   r   rR   rR   rS   r     r   c                 3   s"   | ]}t  t t|V  qd S r   )fnmatchrM   )r   globr   rR   rS   r     r   rG   r(   c                 3   s   | ]}t | V  qd S r   r   )r   patr   rR   rS   r     r   )	Z_getconftest_pathlistparentr   	getoptionextendr   r   r   Zgetini)r   rb   Zignore_pathsZ
excludeoptZignore_globsZexcludegloboptZallow_in_venvZnorecursepatternsrR   r   rS   pytest_ignore_collecty  s4    





r   )r   rb   r'   c                 C   sp   t |dpg }|sd S g }g }| D ]&}|j|rB|| q&|| q&|rl|jj|d || d d < d S )NZdeselect)r   )tupler   nodeidr   r8   rl   Zpytest_deselected)r   rb   Zdeselect_prefixes	remainingZ
deselectedZcolitemrR   rR   rS   pytest_collection_modifyitems  s    r   c                   @   s*   e Zd ZeddddZedddZdS )FSHookProxyN)pmr'   c                 C   s   || _ || _d S r   )r   remove_mods)selfr   r   rR   rR   rS   __init__  s    zFSHookProxy.__init__r   c                 C   s    | j j|| jd}|| j|< |S )N)Zremove_plugins)r   Zsubset_hook_callerr   __dict__)r   r   r   rR   rR   rS   __getattr__  s    
zFSHookProxy.__getattr__)r}   
__module____qualname__r   r   rM   r   rR   rR   rR   rS   r     s   r   c                   @   s   e Zd ZdZdZdS )r   z*Signals that the test run was interrupted.builtinsNr}   r   r   __doc__rR   rR   rR   rS   r     s   r   c                   @   s   e Zd ZdZdS )rm   z"Signals a stop as failed test run.Nr   rR   rR   rR   rS   rm     s   rm   c                   @   s*   e Zd ZU dZeed< eedddZdS )_bestrelpath_cache)rC   rC   rU   c                 C   s   t | j|}|| |< |S r   )r   rC   )r   rC   rrR   rR   rS   __missing__  s    z_bestrelpath_cache.__missing__N)r}   r   r   	__slots__r   __annotations__rM   r   rR   rR   rR   rS   r     s   
r   c                       s  e Zd ZU eZeZeed< eed< ee	e
f ed< edd fddZeed ddd	Zed
ddZeed
ddZeedddZedddd
ddZeddeeef ddddZeZeedf edddZddddZd ed!d"d#Zd3eeee j! d$d%d&Z"e#d4e$ee  d(ee j% d)d*d+Z&e#d5e$ee  eeee j%e j!f  d)d,d+Z&d6e$ee  eeee j%e j!f  d)d-d+Z&e'ee j%e j!f  d
d.d/Z(ee j%e j!f e'e j% d0d1d2Z)  Z*S )7ra   Z_setupstateZ_fixturemanagerri   Nr   c                    sl   t  j|jd d || dd d| _d| _d| _d| _|jj	d| _t
 | _t|j| _| jjj| dd d S )Nr   )rC   fspathr   rb   re   r   r   FrB   re   r   )superr   r   r   r   r   r   tracerootget	frozenset_initialpathsr   _bestrelpathcacherb   pluginmanagerregister)r   rb   	__class__rR   rS   r     s     zSession.__init__c                 C   s   | j |d}|S )Nr   )_create)clsrb   re   rR   rR   rS   rj     s    zSession.from_config)r'   c                 C   s$   d| j j| jt| dd| j| jf S )Nz6<%s %s exitstatus=%r testsfailed=%d testscollected=%d>ri   z<UNSET>)r   r}   r   getattrr   r   r   rR   rR   rS   __repr__  s    
zSession.__repr__c                 C   s
   | j jjS )zQThe path from which pytest was invoked.

        .. versionadded:: 7.0.0
        )rb   invocation_paramsrD   r   rR   rR   rS   r     s    zSession.startpath)	node_pathr'   c                 C   s
   | j | S r   )r   )r   r   rR   rR   rS   _node_location_to_relpath  s    z!Session._node_location_to_relpathT)Ztryfirstc                 C   s(   | j r| | j | jr$| | jd S r   )r   rm   r   r   r   rR   rR   rS   pytest_collectstart  s    zSession.pytest_collectstart)reportr'   c                 C   sH   |j rDt|dsD|  jd7  _| jd}|rD| j|krDd| j | _d S )NZwasxfailr3   r2   zstopping after %d failures)failedhasattrr   rb   getvaluer   )r   r   r2   rR   rR   rS   pytest_runtest_logreport  s
    z Session.pytest_runtest_logreportzos.PathLike[str]rU   c                 C   s    t |tr|nt|}|| jv S r   )rs   r   r   )r   rC   Zpath_rR   rR   rS   
isinitpath  s    zSession.isinitpath)r   c                 C   sr   t |tr|nt|}| jj}|j|| jd| jjd}|j|}|rfddl	m
} |t||}n| jj}|S )NrJ   )r   r3   )PathAwareHookProxy)rs   r   rb   r   Z_getconftestmodulesr   r   Z_conftest_plugins
differenceZconfig.compatr   r   rl   )r   r   rC   r   Zmy_conftestmodulesr   r   proxyrR   rR   rS   gethookproxy  s    
zSession.gethookproxyzos.DirEntry[str])direntryr'   c                 C   s<   |j dkrdS t|j}| |j}|j|| jdr8dS dS )N__pycache__Fr   rb   T)r   r   rC   r   r   r   rb   )r   r   r   ihookrR   rR   rS   _recurse5  s    

zSession._recurse)r   handle_dupesr'   c                 C   s   |  s(J d|| | | | |}| |sP|j|| jdrPdS |r| j	d}|s| jj
j}||v rzdS || |j|| dS )Nz9{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})r   rR   rF   )	file_pathr   )is_fileformatr   exists
is_symlinkr   r   r   rb   r   r   Z_duplicatepathsaddZpytest_collect_file)r   r   r   r   rF   Zduplicate_pathsrR   rR   rS   _collectfile>  s$    



zSession._collectfile.zLiteral[True])r)   genitemsr'   c                 C   s   d S r   rR   r   r)   r   rR   rR   rS   r   V  s    zSession.perform_collectc                 C   s   d S r   rR   r   rR   rR   rS   r   \  s    c              
   C   s  |du r| j j}| d| | | jj jd7  _g | _g | _g | _| j j}| j}z6g }|D ]<}t	| j j
j|| j jjd\}}| j||f || q\t|| _t| }	| jj|	d | jj jd8  _| jr&g }
| jD ]>\}}|r|
d| d|d|d	 q|
d
|  qt|
 |s4|	j}n(|	jr\|	jD ]}| j| | qB| j j  |j| | j |d W |j| d n|j| d 0 t|| _|S )a  Perform the collection phase for this session.

        This is called by the default :hook:`pytest_collection` hook
        implementation; see the documentation of this hook for more details.
        For testing purposes, it may also be called directly on a fresh
        ``Session``.

        This function normally recursively expands any collectors collected
        from the session to their items, and only items are returned. For
        testing purposes, this may be suppressed by passing ``genitems=False``,
        in which case the return value contains these collectors unexpanded,
        and ``session.items`` is empty.
        Nr   r3   	as_pypathr   znot found: z

(no name z in any of )zfound no collectors for )re   rb   r   rd   )rb   r)   r   r   indent	_notfound_initial_partsr   rl   resolve_collection_argumentr   rD   r|   Zpyargsr8   r   r   r#   r   pytest_collectreportr   resultpassedr   r   r   Zcheck_pendingr   Zpytest_collection_finishr   r   )r   r)   r   rl   r   Zinitialpathsargr   partsreperrorsZ
collectorsnoderR   rR   rS   r   b  sX    



c              	   c   s  ddl m} i }i }i }i }| jD ]\}}| d||f | jj jd7  _| jdds| jj}|g|j	R D ]r}	|
|s q|	 rr|	d }
|
 rr|
|vrr| j|
dd}|rrt|d |r|d ||	< |d g||d j< qr| r|rJ d	||ft }t|| jD ]}| s,qt|j}|j}||vr|| |d }
|
 r| |
D ] }|V  t||rl|||< ql||v rq| |D ]8}t||jf}||v r|| V  n|||< |V  qqn| sJ ||v r
|| }n*||j| }|j|dd}|r4|||< g }||fg}|rz| d
|| | jj jd7  _| \}}|D ]}|s|| qxt|tjsqxt||jf}||v r|| }nt|}|||< |jr@g }|j D ]:}|j!|d ks|j!"dd |d kr|| q|rN|||dd  f n|j#j$|d qx| dt%|d | jj jd8  _qB|sd&t'|g|R }| j(||f q"|j!dkrt|d |rzt)t*|d + V  W q" t,y   Y q"0 q"|E d H  | jj jd8  _q"d S )Nr   )Packagezprocessing argumentr3   ZdoctestmodulesFz__init__.py)r   zinvalid arg 
matchnodes[r   zmatchnodes finished -> r   ::)-Z_pytest.pythonr  r  r   r   r   rb   r   r   rX   Z_is_in_confcutdirr   r   r   rs   rC   setr    r   r   r   r   r   r/   r   popr8   r   	Collectorr   r#   r  r  r   splitr   r  r   joinrM   r   nextiterrA   StopIteration)r   r  Znode_cache1Znode_cache2Zmatchnodes_cacheZ	pkg_rootsZargpathnamesr   r   ZpkginitcolZ	seen_dirsr   rC   dirpathr   key2Zcollect_rootZmatchingZworkr  Z
matchnamesr
  keyr  Zsubmatchnodesr   Z
report_argrR   rR   rS   rA     s    















zSession.collect)r
  r'   c                 c   sz   |  d| t|tjr.|jj|d |V  nHt|tjs>J t|}|jrh|j	D ]}| 
|E d H  qR|jj|d d S )Nr   )r   r   )r   rs   r   Itemr   Zpytest_itemcollectedr  r#   r  r  r   r  )r   r
  r  ZsubnoderR   rR   rS   r   ;  s    
zSession.genitems)T)..)..)NT)+r}   r   r   r   rm   r$   r   r   r   rL   r   r   r   classmethodrj   rM   r   propertyr   r   r   r   r   r"   r!   r   r  r\   r   r   r   r	   r   r  r   r   r   r  r   r   rA   r   __classcell__rR   rR   r   rS   ra     sb   
	
	
    G )module_namer'   c              
   C   sl   zt j| }W n tttfy,   |  Y S 0 |du sJ|jdu sJ|jdkrN| S |jrbtj	
|jS |jS dS )zTSearch sys.path for the given a dotted module name, and return its file system path.N	namespace)rI   util	find_specAttributeErrorImportError
ValueErrororiginsubmodule_search_locationsr   rC   dirname)r   specrR   rR   rS   search_pypathK  s    
r+  Fr   )invocation_pathr  r   r'   c          
      C   s   t |d\}}}|d^}}|r>|d  | | |d< |rJt|}| | }t|}| s~|rjdnd}	t|	j|d|r| r|rdnd}	t|	j|d||fS )	a`  Parse path arguments optionally containing selection parts and return (fspath, names).

    Command-line arguments can point to files and/or directories, and optionally contain
    parts for specific tests selection, for example:

        "pkg/tests/test_foo.py::TestClass::test_foo"

    This function ensures the path exists, and returns a tuple:

        (Path("/full/path/to/pkg/tests/test_foo.py"), ["TestClass", "test_foo"])

    When as_pypath is True, expects that the command-line argument actually contains
    module paths instead of file-system paths:

        "pkg.tests.test_foo::TestClass::test_foo"

    In which case we search sys.path for a matching module, and then return the *path* to the
    found module.

    If the path doesn't exist, raise UsageError.
    If the path is a directory and selection parts are present, raise UsageError.
    r  r  z9module or package not found: {arg} (missing __init__.py?)z"file or directory not found: {arg})r  z9package argument cannot contain :: selection parts: {arg}z;directory argument cannot contain :: selection parts: {arg})	rM   	partitionr  r+  r   r   r   r   r   )
r,  r  r   rV   ZsquacketrestZstrpathr  r   r`   rR   rR   rS   r  \  s*    r  )Pr   rZ   Zdataclassesr   rN   rI   r   rv   pathlibr   typingr   r   r   r   r   r   r	   r
   r   r   r   r   Z_pytest._coderq   r   Z_pytest.compatr   r   Z_pytest.configr   r   r   r   r   r   Z_pytest.config.argparsingr   Z_pytest.fixturesr   Z_pytest.outcomesr   Z_pytest.pathlibr   r   r   r    Z_pytest.reportsr!   r"   Z_pytest.runnerr#   r$   Ztyping_extensionsr%   rT   rM   rP   rL   r   r   r   r   r\   r   r   r   r  r   r   ro   r   rp   rm   Z	dataclassr   ZFSCollectorra   r+  r  rR   rR   rR   rS   <module>   s    7
;#  }