a
    !f                     @   sp  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 e%dd&d'd(Z8e9e9d)d*d+Z:eeed,geee;e f  f ee;e f d-d.d/Z<eee;e f d0d1d2Z=ed,eee;e f  d3d4d5Z>d,dd6d7d8Z?d,e@d6d9d:ZAe	e@d)d;d<ZBe	eee@ d=d>d?ZCeejD edd@dAdBZEG dCdD dDZFG dEdF dFeGZHG dGdH dHeIZJejKG dIdJ dJee	e9f ZLeG dKd, d,ejMZNe9e9dLdMdNZOdOdPe	e9e@ee	ee9 f dQdRdSZPdS )TzHCore 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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)r5   r8   filterwarningsZlinelistz_Each line specifies a pattern for warnings.filterwarnings. Processed after -W/--pythonwarnings.)r0   r8   z	--maxfailnumstorer   z'Exit after first num failures or errors)metavarr5   r0   r6   r1   r8   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=   r0   r6   r8   z--continue-on-collection-errorsFcontinue_on_collection_errorsz4Force test execution even if collection errors occur)r5   r1   r6   r8   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'.)r5   r6   r8   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))r5   r=   r8   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)r6   r1   r=   r0   r8   z--noconftestZ
noconftestz Don't load any conftest.py files)r5   r6   r1   r8   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)rI   r9   	importlib
importmodez\Prepend/append to sys.path when importing test modules and conftest files. Default: prepend.)r1   choicesr6   r8   Zdebugconfigz(test session debugging and configurationz
--basetempZbasetempz^Base temporary directory for this test run. (Warning: this directory is removed if it exists.))r6   r1   r0   r=   r8   )
ZaddiniZgetgroupZ
_addoptionZ	addoptionintstr	functoolspartialr   validate_basetemp)r'   group rS   M/var/www/html/python-backend/venv/lib/python3.9/site-packages/_pytest/main.pypytest_addoption3   s6   
				rU   rD   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)rW   rX   rS   rS   rT   is_ancestor   s    z&validate_basetemp.<locals>.is_ancestor)argparseArgumentTypeErrorr   boolcwdabsoluteresolve)rD   msgrZ   rS   rS   rT   rQ      s    


rQ   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   r4   session   Nz: 
)excinfoz(mainloop: caught unexpected SystemExit!
)rf   
exitstatus))rb   from_configr   OKrj   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typenamera   Zpytest_keyboard_interruptBaseExceptionINTERNAL_ERRORZnotify_exceptionoptionr0   __name__
SystemExitoschdir	startpathZpytest_sessionfinishZ_ensure_unconfigure)rc   rd   rf   Z	initstateri   rj   excrS   rS   rT   wrap_session  sz    

4

4


4
r   rc   r(   c                 C   s
   t | tS N)r   _mainrc   rS   rS   rT   pytest_cmdline_main=  s    r   )rc   rf   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.re   r   N)rm   pytest_collectionpytest_runtestlooptestsfailedr   ro   testscollectedZNO_TESTS_COLLECTED)rc   rf   rS   rS   rT   r   A  s    
r   )rf   r(   c                 C   s   |    d S r   )perform_collectre   rS   rS   rT   r   N  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 collectionr4   s T)itemnextitem)r   rc   r}   r@   InterruptedZcollectonly	enumerateitemslenrm   Zpytest_runtest_protocol
shouldfailrn   
shouldstop)rf   ir   r   rS   rS   rT   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 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.win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	activatesrS   rT   	<genexpr>w      z_in_venv.<locals>.<genexpr>)joinpathrw   platform
startswithis_dirOSErroranyiterdir)rD   ZbindirrS   r   rT   _in_venvf  s    
r   )collection_pathrc   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)rD   rootpathignorec                 s   s   | ]}t |V  qd S r   r   r   xrS   rS   rT   r     r   z(pytest_ignore_collect.<locals>.<genexpr>TZcollect_ignore_globZignore_globc                 s   s   | ]}t |V  qd S r   r   r   rS   rS   rT   r     r   c                 3   s"   | ]}t  t t|V  qd S r   )fnmatchrN   )r   globr   rS   rT   r     r   rH   r)   c                 3   s   | ]}t | V  qd S r   r   )r   patr   rS   rT   r     r   )	Z_getconftest_pathlistparentr   	getoptionextendr   r   r   Zgetini)r   rc   Zignore_pathsZ
excludeoptZignore_globsZexcludegloboptZallow_in_venvZnorecursepatternsrS   r   rT   pytest_ignore_collectz  s4    





r   )r   rc   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   r9   rm   Zpytest_deselected)r   rc   Zdeselect_prefixes	remainingZ
deselectedZcolitemrS   rS   rT   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   rS   rS   rT   __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   rS   rS   rT   __getattr__  s    
zFSHookProxy.__getattr__)r~   
__module____qualname__r   r   rN   r   rS   rS   rS   rT   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__rS   rS   rS   rT   r     s   r   c                   @   s   e Zd ZdZdS )rn   z"Signals a stop as failed test run.Nr   rS   rS   rS   rT   rn     s   rn   c                   @   s*   e Zd ZU dZeed< eedddZdS )_bestrelpath_cache)rD   rD   rV   c                 C   s   t | j|}|| |< |S r   )r   rD   )r   rD   rrS   rS   rT   __missing__  s    z_bestrelpath_cache.__missing__N)r~   r   r   	__slots__r   __annotations__rN   r   rS   rS   rS   rT   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< 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d4eee e!j" d%d&d'Z#e$d5e%e e  d)e e!j& d*d+d,Z'e$d6e%e e  ee e	e!j&e!j"f  d*d-d,Z'd7e%e e  ee e	e!j&e!j"f  d*d.d,Z'e(e	e!j&e!j"f  dd/d0Z)e	e!j&e!j"f e(e!j& d1d2d3Z*  Z+S )8rb   zoThe root of the collection tree.

    ``Session`` collects the initial paths given as arguments to pytest.
    Z_setupstateZ_fixturemanagerrj   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   )rD   fspathr   rc   rf   r   r   FrC   rf   r   )superr   r   r   r   r   r   tracerootget	frozenset_initialpathsr   _bestrelpathcacherc   pluginmanagerregister)r   rc   	__class__rS   rT   r     s     zSession.__init__c                 C   s   | j |d}|S )Nr   )_create)clsrc   rf   rS   rS   rT   rk     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>rj   z<UNSET>)r   r~   r   getattrr   r   r   rS   rS   rT   __repr__  s    
zSession.__repr__c                 C   s
   | j jjS )zQThe path from which pytest was invoked.

        .. versionadded:: 7.0.0
        )rc   invocation_paramsrE   r   rS   rS   rT   r     s    zSession.startpath)	node_pathr(   c                 C   s
   | j | S r   )r   )r   r   rS   rS   rT   _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   rn   r   r   r   rS   rS   rT   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wasxfailr4   r3   zstopping after %d failures)failedhasattrr   rc   getvaluer   )r   r   r3   rS   rS   rT   pytest_runtest_logreport  s
    z Session.pytest_runtest_logreportzos.PathLike[str]rV   c                 C   s    t |tr|nt|}|| jv S r   )rt   r   r   )r   rD   Zpath_rS   rS   rT   
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 )NrK   )r   r4   )PathAwareHookProxy)rt   r   rc   r   Z_getconftestmodulesr   r   Z_conftest_plugins
differenceZconfig.compatr   r   rm   )r   r   rD   r   Zmy_conftestmodulesr   r   proxyrS   rS   rT   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   rc   T)r   r   rD   r   r   r   rc   )r   r   r   ihookrS   rS   rT   _recurse;  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   rS   rG   )	file_pathr   )is_fileformatr   exists
is_symlinkr   r   r   rc   r   r   Z_duplicatepathsaddZpytest_collect_file)r   r   r   r   rG   Zduplicate_pathsrS   rS   rT   _collectfileD  s$    



zSession._collectfile.zLiteral[True])r*   genitemsr(   c                 C   s   d S r   rS   r   r*   r   rS   rS   rT   r   \  s    zSession.perform_collectc                 C   s   d S r   rS   r   rS   rS   rT   r   b  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   r4   	as_pypathr   znot found: z

(no name z in any of )zfound no collectors for )rf   rc   r   re   )rc   r*   r   r   indent	_notfound_initial_partsr   rm   resolve_collection_argumentr   rE   r}   Zpyargsr9   r   r   r$   r   pytest_collectreportr   resultpassedr   r   r   Zcheck_pendingr   Zpytest_collection_finishr   r   )r   r*   r   rm   r   Zinitialpathsargr   partsreperrorsZ
collectorsnoderS   rS   rT   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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 argumentr4   ZdoctestmodulesFz__init__.py)r   zinvalid arg 
matchnodes[r   zmatchnodes finished -> r   ::)-Z_pytest.pythonr  r  r   r   r  rc   r   r   rY   Z_is_in_confcutdirr   r   r   rt   rD   setr!   r   r   r   r   r   r0   r   popr9   r   	Collectorr   r$   r  r  r   splitr   r  r   joinrN   r  nextiterrB   StopIteration)r   r  Znode_cache1Znode_cache2Zmatchnodes_cacheZ	pkg_rootsZargpathnamesr   r   ZpkginitcolZ	seen_dirsr   rD   dirpathr   key2Zcollect_rootZmatchingZworkr  Z
matchnamesr  keyr
  Zsubmatchnodesr   Z
report_argrS   rS   rT   rB     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   rt   r   Itemr   Zpytest_itemcollectedr  r$   r  r  r   r  )r   r  r
  ZsubnoderS   rS   rT   r   A  s    
zSession.genitems)T)..)..)NT),r~   r   r   r   r   rn   r%   r   r   r   rM   r   r   r   classmethodrk   rN   r   propertyr   r   r   r   r   r#   r"   r   r  r]   r   r   r   r	   r   r  r   r   r   r  r   r   rB   r   __classcell__rS   rS   r   rT   rb     sd   
	
	
    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)rJ   util	find_specAttributeErrorImportError
ValueErrororiginsubmodule_search_locationsr   rD   dirname)r"  specrS   rS   rT   search_pypathQ  s    
r-  Fr   )invocation_pathr  r   r(   c          
      C   s   t |d\}}}|d^}}|r>|d  | | |d< |rJt|}| | }t|}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})	rN   	partitionr  r-  r   r    r   r   r   )
r.  r  r   rW   ZsquacketrestZstrpathr	  r   ra   rS   rS   rT   r  b  s*    r  )Qr   r[   dataclassesr   rO   rJ   r   rw   pathlibr   typingr   r   r   r   r   r   r	   r
   r   r   r   r   Z_pytest._coderr   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    r!   Z_pytest.reportsr"   r#   Z_pytest.runnerr$   r%   Ztyping_extensionsr&   rU   rN   rQ   rM   r   r   r   r   r]   r   r   r   r  r   r   rp   r   rq   rn   	dataclassr   ZFSCollectorrb   r-  r  rS   rS   rS   rT   <module>   s    7
;#   