o
    h                     @   s  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*m/Z/ dd!l0m1Z1 dd"l0m2Z2 dd#l3m4Z4 dd$l3m5Z5 erdd%l6m7Z7 d&e%d'dfd(d)Z8d*e9d'e9fd+d,Z:d-ed.eed/geee;e f  f d'ee;e f fd0d1Z<d-ed'ee;e f fd2d3Z=d-ed4d/d'eee;e f  fd5d6Z>dVd7d8Z?d4d/d'e@fd9d:ZAd*e	d'e@fd;d<ZBd=e	d-ed'ee@ fd>d?ZCd@eejD d-ed'dfdAdBZEG dCdD dDZFG dEdF dFeGZHG dGdH dHeIZJejKG dIdJ dJee	e9f ZLeG dKd/ d/ejMZNdLe9d'e9fdMdNZOdOdPdQe	dRe9dSe@d'ee	ee9 f fdTdUZPdS )WzHCore 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)safe_exists)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distnode_modulesvenvz{arch})typedefault	testpathszZDirectories to search for tests when no files or directories are given on the command line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)r8   r;   filterwarningslinelistz_Each line specifies a pattern for warnings.filterwarnings. Processed after -W/--pythonwarnings.)r1   r;   z	--maxfailnumstorer   z'Exit after first num failures or errors)metavarr8   r1   r9   r2   r;   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FILEinifilenamezcLoad configuration from `FILE` instead of trying to locate one of the implicit configuration files.)rA   r1   r9   r;   z--continue-on-collection-errorsFcontinue_on_collection_errorsz4Force test execution even if collection errors occur)r8   r2   r9   r;   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'.)r8   r9   r;   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))r8   rA   r;   z--ignore-globz5Ignore path pattern during collection (multi-allowed)z
--deselectnodeid_prefixzDDeselect item (via node id prefix) during collection (multi-allowed)z--confcutdir
confcutdirdir)optnamez1Only load conftest.py's relative to specified dir)r9   r2   rA   r1   r;   z--noconftest
noconftestz Don't load any conftest.py files)r8   r9   r2   r;   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)rQ   r<   	importlib
importmodez\Prepend/append to sys.path when importing test modules and conftest files. Default: prepend.)r2   choicesr9   r;   debugconfigz(test session debugging and configurationz
--basetempbasetempz^Base temporary directory for this test run. (Warning: this directory is removed if it exists.))r9   r2   r1   rA   r;   )
addinigetgroup
_addoption	addoptionintstr	functoolspartialr   validate_basetemp)r'   group ra   B/var/www/html/ai/venv/lib/python3.10/site-packages/_pytest/main.pypytest_addoption3   s6  
				
rc   rI   c                 C   sp   d}| s	t |dtdtdtfdd}|t t|  r$t ||t  t|  r6t || 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)rd   re   ra   ra   rb   is_ancestor   s   
z&validate_basetemp.<locals>.is_ancestor)argparseArgumentTypeErrorr   boolcwdabsoluteresolve)rI   msgrg   ra   ra   rb   r_      s   


r_   configdoitSessionc                 C   s  t | }tj|_d}zz|   d}| jj|d d}|| |p#d|_W n ty2   tj	|_  t
y>   tj|_Y n ttjfy   tjj }tj}t|jtjrt|jjdura|jj}|dk rttj|j d|jj d | jj|d ||_Y nT ty   tj|_tjj }z	| || j  W n+ tjy } z|jdur|j|_tjt!|j" d| d W Y d}~nd}~ww t|jt#rtjd	 Y nw W d}t$%|j& |dkrz| jj'||jd
 W n- tjy } z|jdur|j|_tjt!|j" d| d W Y d}~nd}~ww | (  |jS d}t$%|j& |dkrhz| jj'||jd
 W n- tjyg } z|jdurN|j|_tjt!|j" d| d W Y d}~nd}~ww | (  w )zSkeleton command line program.r   r7   session   Nz: 
)excinfoz(mainloop: caught unexpected SystemExit!
)rs   
exitstatus))rq   from_configr   OKrw   _do_configurehookpytest_sessionstartr   USAGE_ERRORFailedTESTS_FAILEDKeyboardInterruptr   	Exception_pytest_codeExceptionInfofrom_currentINTERRUPTED
isinstancevalue
returncodesysstderrwritetypenamern   pytest_keyboard_interruptBaseExceptionINTERNAL_ERRORnotify_exceptionoptionr1   __name__
SystemExitoschdir	startpathpytest_sessionfinish_ensure_unconfigure)ro   rp   rs   	initstaterv   rw   excra   ra   rb   wrap_session  s   


*

*

*
r   c                 C   s
   t | tS N)r   _mainro   ra   ra   rb   pytest_cmdline_main=  s   
r   rs   c                 C   s<   | j j|d | j j|d |jrtjS |jdkrtjS dS )z[Default command line protocol for initialization, session,
    running tests and reporting.rr   r   N)r{   pytest_collectionpytest_runtestlooptestsfailedr   r   testscollectedNO_TESTS_COLLECTED)ro   rs   ra   ra   rb   r   A  s   
r   c                 C   s   |    d S r   )perform_collectrr   ra   ra   rb   r   N  s   r   c                 C   s   | j r| jjjs| d| j | j dkrdf df | jjjr#dS t| jD ]1\}}|d t| jk r<| j|d  nd }|jj	j
||d | jrP| | j| jrY| | jq(dS )Nz%d error%s during collectionr7   s T)itemnextitem)r   ro   r   rE   Interruptedcollectonly	enumerateitemslenr{   pytest_runtest_protocol
shouldfailr~   
shouldstop)rs   ir   r   ra   ra   rb   r   R  s(   
$r   c                    s`   |  tjdr
dnd}z	| sW dS W n
 ty    Y dS w 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.winScriptsbinF)activatezactivate.cshzactivate.fishActivatezActivate.batzActivate.ps1c                 3   s    | ]}|j  v V  qd S r   name).0fname	activatesra   rb   	<genexpr>w      z_in_venv.<locals>.<genexpr>)joinpathr   platform
startswithis_dirOSErroranyiterdir)rI   bindirra   r   rb   _in_venvf  s   r   collection_pathc                    s   |j d j|jd}|pg }|d}|r|dd |D   |v r%dS |j d j|jd}|p2g }|d}|rD|d	d |D  t fd
d|D rQdS |d}|s^t r^dS   rt|d}t fdd|D rtdS d S )Ncollect_ignore)rI   rootpathignorec                 s       | ]}t |V  qd S r   r   r   xra   ra   rb   r         z(pytest_ignore_collect.<locals>.<genexpr>Tcollect_ignore_globignore_globc                 s   r   r   r   r   ra   ra   rb   r     r   c                 3   s$    | ]}t  t t|V  qd S r   )fnmatchr\   )r   globr   ra   rb   r     s   " rP   r)   c                 3   s    | ]}t | V  qd S r   r   )r   patr   ra   rb   r     r   )	_getconftest_pathlistparentr   	getoptionextendr   r   r   getini)r   ro   ignore_paths
excludeoptignore_globsexcludegloboptallow_in_venvnorecursepatternsra   r   rb   pytest_ignore_collectz  s4   





r   r   c                 C   st   t |dpg }|sd S g }g }| D ]}|j|r!|| q|| q|r8|jj|d || d d < d S d S )Ndeselect)r   )tupler   nodeidr   r<   r{   pytest_deselected)r   ro   deselect_prefixes	remaining
deselectedcolitemra   ra   rb   pytest_collection_modifyitems  s   r   c                   @   s,   e Zd ZdeddfddZdefddZdS )	FSHookProxypmr(   Nc                 C   s   || _ || _d S r   )r   remove_mods)selfr   r   ra   ra   rb   __init__  s   
zFSHookProxy.__init__r   c                 C   s    | j j|| jd}|| j|< |S )N)remove_plugins)r   subset_hook_callerr   __dict__)r   r   r   ra   ra   rb   __getattr__  s   
zFSHookProxy.__getattr__)r   
__module____qualname__r   r   r\   r   ra   ra   ra   rb   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__ra   ra   ra   rb   r     s    r   c                   @   s   e Zd ZdZdS )r~   z"Signals a stop as failed test run.Nr   ra   ra   ra   rb   r~     s    r~   c                   @   s,   e Zd ZU dZeed< dedefddZdS )_bestrelpath_cache)rI   rI   r(   c                 C   s   t | j|}|| |< |S r   )r   rI   )r   rI   rra   ra   rb   __missing__  s   z_bestrelpath_cache.__missing__N)r   r   r   	__slots__r   __annotations__r\   r   ra   ra   ra   rb   r     s   
 r   c                       s  e Zd ZU dZeZeZeed< eed< e	e
ef ed< deddf fdd	Zededd fd
dZdefddZedefddZdedefddZeddd5ddZeddde	eef ddfddZeZde	edf defddZd6dd Zd!d"defd#d$Z	d7ded%ede e!j" fd&d'Z#e$	(d8d)e%e e  d*d+de e!j& fd,d-Z'e$	(d8d)e%e e  d*ede e	e!j&e!j"f  fd.d-Z'	d9d)e%e e  d*ede e	e!j&e!j"f  fd/d-Z'de(e	e!j&e!j"f  fd0d1Z)d2e	e!j&e!j"f de(e!j& fd3d4Z*  Z+S ):rq   zoThe root of the collection tree.

    ``Session`` collects the initial paths given as arguments to pytest.
    _setupstate_fixturemanagerrw   ro   r(   Nc                    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   )rI   fspathr   ro   rs   r   r   FrH   rs   r   )superr   r   r   r   r   r   tracerootget	frozenset_initialpathsr   _bestrelpathcachero   pluginmanagerregister)r   ro   	__class__ra   rb   r     s    zSession.__init__c                 C   s   | j |d}|S )Nr   )_create)clsro   rs   ra   ra   rb   rx     s   zSession.from_configc                 C   s$   d| j j| jt| dd| j| jf S )Nz6<%s %s exitstatus=%r testsfailed=%d testscollected=%d>rw   z<UNSET>)r  r   r   getattrr   r   r   ra   ra   rb   __repr__  s   
zSession.__repr__c                 C   s
   | j jjS )zQThe path from which pytest was invoked.

        .. versionadded:: 7.0.0
        )ro   invocation_paramsrL   r  ra   ra   rb   r     s   
zSession.startpath	node_pathc                 C   s
   | j | S r   )r	  )r   r  ra   ra   rb   _node_location_to_relpath	  s   
z!Session._node_location_to_relpathT)tryfirstc                 C   s(   | j r	| | j | jr| | jd S r   )r   r~   r   r   r  ra   ra   rb   pytest_collectstart  s
   zSession.pytest_collectstartreportc                 C   sX   |j r$t|ds&|  jd7  _| jd}|r(| j|kr*d| j | _d S d S d S d S d S )Nwasxfailr7   r6   zstopping after %d failures)failedhasattrr   ro   getvaluer   )r   r  r6   ra   ra   rb   pytest_runtest_logreport  s   z Session.pytest_runtest_logreportrI   os.PathLike[str]c                 C   s    t |tr|nt|}|| jv S r   )r   r   r  )r   rI   path_ra   ra   rb   
isinitpath   s   
zSession.isinitpathr  c                 C   st   t |tr|nt|}| jj}|j|| jd| jjd}|j|}|r4ddl	m
} |t||}|S | jj}|S )NrS   )r   r7   )PathAwareHookProxy)r   r   ro   r
  _getconftestmodulesr   r   _conftest_plugins
differenceconfig.compatr!  r   r{   )r   r  rI   r   my_conftestmodulesr   r!  proxyra   ra   rb   gethookproxy%  s   
zSession.gethookproxydirentryzos.DirEntry[str]c                 C   s<   |j dkrdS t|j}| |j}|j|| jdrdS dS )N__pycache__Fr   ro   T)r   r   rI   r(  r   r   ro   )r   r)  r  ihookra   ra   rb   _recurse;  s   

zSession._recursehandle_dupesc                 C   s   |  sJ d|| | | | |}| |s(|j|| jdr(dS |rB| j	d}|sB| jj
j}||v r=dS || |j|| dS )Nz9{!r} is not a file (isdir={!r}, exists={!r}, islink={!r})r+  ra   rO   )	file_pathr   )is_fileformatr   exists
is_symlinkr(  r   r   ro   r   r
  _duplicatepathsaddpytest_collect_file)r   r  r.  r,  rO   duplicate_pathsra   ra   rb   _collectfileD  s$   



zSession._collectfile.r*   genitemszLiteral[True]c                 C      d S r   ra   r   r*   r9  ra   ra   rb   r   \     zSession.perform_collectc                 C   r:  r   ra   r;  ra   ra   rb   r   b  r<  c              
   C   s  |du r| j j}| d| | | jj jd7  _g | _g | _g | _| j j}| j}zg }|D ]}t	| j j
j|| j jjd\}}| j||f || q-t|| _t| }	| jj|	d | jj jd8  _| jrg }
| jD ]\}}|r|
d| d|d|d	 qm|
d
|  qmt|
 |s|	j}n|	jr|	jD ]}| j| | q| j j  |j| | j |d W |j| d n|j| d w 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   r7   	as_pypathr  znot found: z

(no name z in any of )zfound no collectors for )rs   ro   r   rr   )ro   r*   r  r  indent	_notfound_initial_partsr   r{   resolve_collection_argumentr  rL   r   pyargsr<   r  r  r$   r,  pytest_collectreportr   resultpassedr   r9  r
  check_pendingr   pytest_collection_finishr   r   )r   r*   r9  r{   r   initialpathsargr  partsreperrors
collectorsnodera   ra   rb   r   h  sX   



c              	   c   s    ddl m} i }i }i }i }| jD ]\}}| d||f | jj jd7  _| jddst| jj}|g|j	R D ]9}	|
|sC n1|	 rs|	d }
|
 rs|
|vrs| j|
dd}|rst|d |ri|d ||	< |d g||d j< q:| r|rJ d	||ft }t|| jD ]Y}| sqt|j}|j}||vr|| |d }
|
 r| |
D ]}|V  t||r|||< q||v rq| |D ]}t||jf}||v r|| V  q|||< |V  qqn| sJ ||v r|| }n||j| }|j|dd}|r|||< g }||fg}|r| d
|| | jj jd7  _| \}}|D ]m}|s:|| q.t|tjsCq.t||jf}||v rT|| }nt|}|||< |jrg }|j D ]}|j!|d ks||j!"dd |d kr|| qe|r|||dd  f q.|j#j$|d q.| dt%|d | jj jd8  _|s|sd&t'|g|R }| j(||f q|j!dkrt|d |rzt)t*|d + V  W n
 t,y   Y nw q|E d H  | jj jd8  _qd S )Nr   )Packagezprocessing argumentr7   doctestmodulesFz__init__.py)r.  zinvalid arg 
matchnodes[r?  zmatchnodes finished -> r   ::)-_pytest.pythonrR  rC  r  r  rA  ro   r   r
  rf   _is_in_confcutdirr   r0  r8  r   rI   setr!   r-  r   r   r5  r2  r1   r  popr<   r   	Collectorr   r$   rH  rG  r   splitr,  rF  r   joinr\   rB  nextiterrG   StopIteration)r   rR  node_cache1node_cache2matchnodes_cache	pkg_rootsargpathnamesr   r   pkginitcol	seen_dirsr)  rI   dirpathr   key2collect_rootmatchingworkrT  
matchnamesrQ  keyrN  submatchnodesr   
report_argra   ra   rb   rG     s   









&
 zSession.collectrQ  c                 c   s~    |  d| t|tjr|jj|d |V  d S t|tjs!J t|}|jr6|j	D ]
}| 
|E d H  q+|jj|d d S )Nr9  )r   r?  )r  r   r   Itemr,  pytest_itemcollectedr[  r$   rH  rG  r9  rF  )r   rQ  rN  subnodera   ra   rb   r9  A  s   

zSession.genitems)r(   N)r  r  )T)..)NT),r   r   r   r   r   r~   r%   r   r   r   r[   r   r   r   classmethodrx   r\   r  propertyr   r   r  r   r  r#   r"   r  rF  rj   r   r(  r-  r	   r   r[  r8  r   r   rs  r   r   rG   r9  __classcell__ra   ra   r  rb   rq     s   
 	
	






G module_namec              
   C   sh   zt j| }W n tttfy   |  Y S w |du s%|jdu s%|jdkr'| S |jr1tj	
|jS |jS )zTSearch sys.path for the given a dotted module name, and return its file system path.N	namespace)rR   util	find_specAttributeErrorImportError
ValueErrororiginsubmodule_search_locationsr   rI   dirname)ry  specra   ra   rb   search_pypathQ  s   r  Fr=  invocation_pathrL  r>  c          
      C   s   t |d\}}}|d^}}|r|d  | | |d< |r%t|}| | }t|}t|s?|r5dnd}	t|	j|d|rS| rS|rId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.
    rU  rV  z9module or package not found: {arg} (missing __init__.py?)z"file or directory not found: {arg})rL  z9package argument cannot contain :: selection parts: {arg}z;directory argument cannot contain :: selection parts: {arg})	r\   	partitionr\  r  r   r    r   r1  r   )
r  rL  r>  rd   squacketreststrpathrM  r  rn   ra   ra   rb   rD  b  s*   rD  )rs   rq   r(   N)Qr   rh   dataclassesr   r]   rR   r   r   pathlibr   typingr   r   r   r   r   r   r	   r
   r   r   r   r   _pytest._coder   r   _pytest.compatr   r   _pytest.configr   r   r   r   r   r   _pytest.config.argparsingr   _pytest.fixturesr   _pytest.outcomesr   _pytest.pathlibr   r   r   r    r!   _pytest.reportsr"   r#   _pytest.runnerr$   r%   typing_extensionsr&   rc   r\   r_   r[   r   r   r   r   rj   r   r   r   rs  r   r   r   r   r   r~   	dataclassr   FSCollectorrq   r  rD  ra   ra   ra   rb   <module>   s     7

;"
#   