B
    `,|                 @   sl  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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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/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.d/d0Z<ed*eee:e!f  d1d2d3Z=d*dd4d5d6Z>d*e?d4d7d8Z@ejAjBe?d'd9d:ZCejAjBeee? d;d<d=ZDeejE edd>d?d@ZFG dAdB dBZGG dCdD dDeHZIG dEdF dFeJZKejLG dGdH dHeee8f ZMeG dId* d*ejNZOe8e8dJdKdLZPdMdNee8e?eejAjBee8 f dOdPdQZQdS )RzHCore implementation of the testing process: init, session, runtest loop.    N)Path)Callable)Dict)	FrozenSet)Iterator)List)Optional)overload)Sequence)Set)Tuple)Type)TYPE_CHECKING)Union)nodes)final)Config)directory_arg)ExitCode)hookimpl)PytestPluginManager)
UsageError)Parser)FixtureManager)exit)absolutepath)bestrelpath)visit)CollectReport)
TestReport)collect_one_node)
SetupState)Literal)parserreturnc             C   s
  | j ddddddddd	d
ddg	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d0d1td2d3d4 |jd5d*d6d7d8d9 |jd:d%d;d<d= | d>d?}|jd@dAdBd*dCd |jdDd*dEd |jdFddGdHdI |jdJddGdKdI |jdLddMdNdI |jdOdPd dQtjtdOdRdSdT |jdUd*dVd6dWdX |jdYdZd*d[d6d\dX |jd]d*d^d6d_dX |jd`dadaddbgdcddde | dfdg}|jdhdid t	dQdjdk d S )lNnorecursedirsz)directory patterns to avoid for recursionargsz*.eggz.*Z_darcsbuildZCVSdistZnode_modulesZvenvz{arch})typedefaultZ	testpathsz[directories to search for tests when no files or directories are given in the command line.Z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.)r.   r1   filterwarningsZlinelistz_Each line specifies a pattern for warnings.filterwarnings. Processed after -W/--pythonwarnings.)r)   r1   z	--maxfailnumstorer   z(exit after first num failures or errors.)metavarr.   r)   r/   r*   r1   z--strict-config
store_truezcany warnings encountered while parsing the `pytest` section of the configuration file raise errors.z--strict-markerszWmarkers not registered in the `markers` section of the configuration file raise errors.z--strictz'(deprecated) alias to --strict-markers.z-cfileZinifilenamezcload configuration from `file` instead of trying to locate one of the implicit configuration files.)r6   r)   r/   r1   z--continue-on-collection-errorsFcontinue_on_collection_errorsz5Force test execution even if collection errors occur.)r.   r*   r/   r1   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'.)r.   r/   r1   collect
collectionz--collectonlyz--collect-onlyz--coz'only collect tests, don't execute them.z--pyargsz2try to interpret all arguments as python packages.z--ignorepathz.ignore path during collection (multi-allowed).)r.   r6   r1   z--ignore-globz6ignore path pattern during collection (multi-allowed).z
--deselectZnodeid_prefixzEdeselect item (via node id prefix) during collection (multi-allowed).z--confcutdirZ
confcutdirdir)optnamez2only load conftest.py's relative to specified dir.)r/   r*   r6   r)   r1   z--noconftestZ
noconftestz!Don't load any conftest.py files.)r.   r/   r*   r1   z--keepduplicatesz--keep-duplicateskeepduplicateszKeep duplicate tests.z--collect-in-virtualenvcollect_in_virtualenvz2Don't ignore tests in a local virtualenv directoryz--import-modeprepend	importlib
importmodezaprepend/append to sys.path when importing test modules and conftest files, default is to prepend.)r*   choicesr/   r1   Zdebugconfigz(test session debugging and configurationz
--basetempZbasetempz\base temporary directory for this test run.(warning: this directory is removed if it exists))r/   r*   r)   r6   r1   )
ZaddiniZgetgroupZ
_addoptionZ	addoptionintstr	functoolspartialr   validate_basetemp)r#   group rL   T/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/_pytest/main.pypytest_addoption3   s   

rN   )r=   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 x| j D ]}||krdS qW dS )z,Return whether query is an ancestor of base.TF)parents)rO   rP   parentrL   rL   rM   is_ancestor   s    z&validate_basetemp.<locals>.is_ancestor)argparseArgumentTypeErrorr   boolcwdabsoluteresolve)r=   msgrS   rL   rL   rM   rJ      s    



rJ   Session)configdoitr$   c             C   sV  t | }tj|_d}zy4|   d}| jj|d d}|| |pFd|_W nn tk
rn   tj	|_ Y nP t
k
r   tj|_Y n4 ttjfk
r   tjj }tj}t|jtjr|jjdk	r|jj}|dk rtj|j d|jj d | jj|d ||_Y n tk
r   tj|_tjj }y| || j  W nT tjk
r } z2|jdk	rr|j|_tjd	!t"|j#| W dd}~X Y nX t|jt$rtjd
 Y nX W dd}|j%&  |dkrFy| jj'||jd W nT tjk
rD } z2|jdk	r|j|_tjd	!t"|j#| W dd}~X Y nX | (  X |jS )zSkeleton command line program.r   r-   )session   Nz: 
)excinfoz{}: {}
z(mainloop: caught unexpected SystemExit!
)r^   
exitstatus))r[   from_configr   OKrb   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typenamerZ   Zpytest_keyboard_interruptBaseExceptionINTERNAL_ERRORZnotify_exceptionoptionformatr)   __name__
SystemExitstartdirchdirZpytest_sessionfinishZ_ensure_unconfigure)r\   r]   r^   Z	initstatera   rb   excrL   rL   rM   wrap_session   s`    

,

,
r|   )r\   r$   c             C   s
   t | tS )N)r|   _main)r\   rL   rL   rM   pytest_cmdline_main;  s    r~   )r\   r^   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.)r^   r   N)re   pytest_collectionpytest_runtestlooptestsfailedr   rg   testscollectedZNO_TESTS_COLLECTED)r\   r^   rL   rL   rM   r}   ?  s    
r}   )r^   r$   c             C   s   |    d S )N)perform_collect)r^   rL   rL   rM   r   L  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 xpt| jD ]b\}}|d t| jk rt| j|d  nd }|jj	j
||d | jr| | j| jrL| | jqLW dS )Nz%d error%s during collectionr-   s T)itemnextitem)r   r\   ru   r9   InterruptedZcollectonly	enumerateitemslenre   Zpytest_runtest_protocol
shouldfailrf   
shouldstop)r^   ir   r   rL   rL   rM   r   P  s    
$r   c                sD   |  tjdrdnd}| s&dS 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                s   g | ]}|j  kqS rL   )basename).0fname)	activatesrL   rM   
<listcomp>r  s    z_in_venv.<locals>.<listcomp>)joinro   platform
startswithisdiranylistdir)r=   ZbindirrL   )r   rM   _in_venvd  s
    r   )r=   r\   r$   c                s   |j d  d}|pg }|d}|r<|dd |D  tj |krPdS |j d  d}|phg }|d}|r|d	d |D  t fd
d|D rdS |d}|st rdS d S )NZcollect_ignore)r=   ignorec             S   s   g | ]}t j|qS rL   )pyr=   local)r   xrL   rL   rM   r   z  s    z)pytest_ignore_collect.<locals>.<listcomp>TZcollect_ignore_globZignore_globc             S   s   g | ]}t j|qS rL   )r   r=   r   )r   r   rL   rL   rM   r     s    c             3   s"   | ]}t  t t|V  qd S )N)fnmatchrG   )r   glob)r=   rL   rM   	<genexpr>  s    z(pytest_ignore_collect.<locals>.<genexpr>rA   )	Z_getconftest_pathlistdirpath	getoptionextendr   r=   r   r   r   )r=   r\   Zignore_pathsZ
excludeoptZignore_globsZexcludegloboptZallow_in_venvrL   )r=   rM   pytest_ignore_collectu  s&    


r   )r   r\   r$   c             C   st   t |dpg }|sd S g }g }x.| D ]&}|j|rD|| q(|| q(W |rp|jj|d || d d < d S )NZdeselect)r   )tupler   nodeidr   r2   re   Zpytest_deselected)r   r\   Zdeselect_prefixes	remainingZ
deselectedZcolitemrL   rL   rM   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 )N)r   remove_mods)selfr   r   rL   rL   rM   __init__  s    zFSHookProxy.__init__)namec             C   s    | j j|| jd}|| j|< |S )N)Zremove_plugins)r   Zsubset_hook_callerr   __dict__)r   r   r   rL   rL   rM   __getattr__  s    
zFSHookProxy.__getattr__)rw   
__module____qualname__r   r   rG   r   rL   rL   rL   rM   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)rw   r   r   __doc__rL   rL   rL   rM   r     s   r   c               @   s   e Zd ZdZdS )rf   z"Signals a stop as failed test run.N)rw   r   r   r   rL   rL   rL   rM   rf     s   rf   c               @   s(   e Zd ZejedZeedddZdS )_bestrelpath_cache)r)   )r=   r$   c             C   s   t | j|}|| |< |S )N)r   r=   )r   r=   rrL   rL   rM   __missing__  s    z_bestrelpath_cache.__missing__N)	rw   r   r   attribr   r=   rG   r   rL   rL   rL   rM   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dddd
ddZeddeeef ddddZeZejjedddZejjdddZdeddd Zd0ejjee e!j" d!d"d#Z#e$d1e%e e  d%e e!j& d&d'd(Z'e$d2e%e e  ee ee!j&e!j"f  d&d)d(Z'd3e%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& d-d.d/Z*  Z+S )4r[   Z_setupstateZ_fixturemanagerrb   N)r\   r$   c                sr   t  j|jd || dd d| _d| _d| _d| _|jj	d| _|j
| _t | _t|j| _| jjj| dd d S )Nr   )rR   r\   r^   r   r   Fr<   r^   )r   )superr   r:   r   r   r   r   tracerootgetZinvocation_dirry   	frozenset_initialpathsr   Zrootpath_bestrelpathcacher\   pluginmanagerregister)r   r\   )	__class__rL   rM   r     s    zSession.__init__c             C   s   |  |}|S )N)_create)clsr\   r^   rL   rL   rM   rc     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>rb   z<UNSET>)r   rw   r   getattrr   r   )r   rL   rL   rM   __repr__  s    
zSession.__repr__)	node_pathr$   c             C   s
   | j | S )N)r   )r   r   rL   rL   rM   _node_location_to_relpath  s    z!Session._node_location_to_relpathT)Ztryfirstc             C   s(   | j r| | j | jr$| | jd S )N)r   rf   r   r   )r   rL   rL   rM   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wasxfailr-   r,   zstopping after %d failures)failedhasattrr   r\   getvaluer   )r   r   r,   rL   rL   rM   pytest_runtest_logreport  s
    z Session.pytest_runtest_logreport)r=   r$   c             C   s
   || j kS )N)r   )r   r=   rL   rL   rM   
isinitpath   s    zSession.isinitpath)fspathc             C   sD   | j j}||| j d}|j|}|r8t||}n| j j}|S )NrD   )r\   r   Z_getconftestmodulesr   Z_conftest_plugins
differencer   re   )r   r   r   Zmy_conftestmodulesr   proxyrL   rL   rM   gethookproxy  s    zSession.gethookproxyzos.DirEntry[str])direntryr$   c                sh   |j dkrdS tj|j |   }|j | jdr>dS | jd}t	 fdd|D rddS dS )N__pycache__F)r=   r\   r%   c             3   s   | ]} j |d V  qdS ))r   N)check)r   pat)r=   rL   rM   r     s    z#Session._recurse.<locals>.<genexpr>T)
r   r   r=   r   r   r   r   r\   Zgetinir   )r   r   ihookZnorecursepatternsrL   )r=   rM   _recurse  s    
zSession._recurse)r=   handle_dupesr$   c             C   s   |  s(td|| | | | |}| |sP|j|| j	drPdS |r| j	
d}|s| j	jj}||krzdS || |j|| dS )Nz9{!r} is not a file (isdir={!r}, exists={!r}, islink={!r}))r=   r\   rL   r@   )r=   rR   )isfileAssertionErrorrv   r   existsislinkr   r   r   r\   r   r   Z_duplicatepathsaddZpytest_collect_file)r   r=   r   r   r@   Zduplicate_pathsrL   rL   rM   _collectfile  s    




zSession._collectfile.zLiteral[True])r&   genitemsr$   c             C   s   d S )NrL   )r   r&   r   rL   rL   rM   r   7  s    zSession.perform_collectc             C   s   d S )NrL   )r   r&   r   rL   rL   rM   r   =  s    c          	   C   s  |dkr| j j}| d| | | jj jd7  _g | _g | _g | _| j j}| j}z(g }xD|D ]<}t	| j j
j|| j jjd\}}| j||f || q^W t|| _t| }	| jj|	d | jj jd8  _| jr g }
x:| jD ]0\}}d|d|d}|
d	| d
|  qW t|
 |s.|	j}n,|	jrZx"|	jD ]}| j| | q>W | j j  |j| | j |d W d|j| d X t|| _|S )a  Perform the collection phase for this session.

        This is called by the default
        :func:`pytest_collection <_pytest.hookspec.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   r-   )	as_pypath)r   z	(no name z in any of )znot found: r`   )r^   r\   r   )r^   )r\   r&   r   r   indent	_notfound_initial_partsr   re   resolve_collection_argumentZinvocation_paramsr>   ru   Zpyargsr2   r   r   r    r   pytest_collectreportr   resultpassedr   r   r   Zcheck_pendingr   Zpytest_collection_finishr   r   )r   r&   r   re   r   Zinitialpathsargr   partsreperrorscolslinenoderL   rL   rM   r   C  sN    


c          	   c   s  ddl m} i }i }i }i }xv| jD ]j\}}| d||f | jj jd7  _| jdds| jj}xt	|
 D ]~}	|jr|j|	rP |	 rv|	d}
|
 rv|
|krv| j|
dd}|rvt|d |r|d |t|	< |d g||d j< qvW |jdd	r|rtd
||ft }xtt|| jD ]}| sHq6tj|j}| }||kr|| |d}
|
  rx2| |
D ]$}|V  t||r||t|< qW t||kr̐q6xF| |D ]8}t!||jf}||kr || V  n|||< |V  qW q6W nb|jdds0t||krD|| }n*|"|j#| }|j|dd}|rn|||< g }||fg}xz|r| d|| | jj jd7  _|$ \}}x|D ]}|s|%| qt|t&j'sqt!||j(f}||kr|| }nt)|}|||< |j*rg }xD|j+D ]:}|j,|d ksZ|j,-dd |d kr,|%| q,W |r|%||dd  f n2t.|j+dkr|j+d j,dkr|%|j+|f n|j/j0|d qW | dt.|d | jj jd8  _qW |s&dt|f|}| j1%||f q&|j2dkrvt|d |rvyt3t4|d 5 V  W q& t6k
rr   Y q&X q&|E d H  | jj jd8  _q&W d S )Nr   )Packagezprocessing argumentr-   ZdoctestmodulesFz__init__.py)r   )r>   zinvalid arg {!r})r8   
matchnodes[z())r   zmatchnodes finished -> r   z::)7Z_pytest.pythonr   r   r   r   r   r\   r   r   reversedr   Z_confcutdirZreltor   r   r   r   rl   rG   r   r   r   rv   setr   r   is_filer   r=   r   r   r   r   r)   r   dirnamepopr2   r   	Collectorr   r    r   r   r   splitr   r   r   r   r   nextiterr;   StopIteration)r   r   Znode_cache1Znode_cache2Zmatchnodes_cacheZ	pkg_rootsZargpathnamesr   rR   ZpkginitcolZ	seen_dirsr   r=   r   r   keyZcollect_rootZmatchingZworkr   Z
matchnamesr   r   Zsubmatchnodesr   Z
report_argrL   rL   rM   r;     s    













"
zSession.collect)r   r$   c             c   s~   |  d| t|tjr.|jj|d |V  nLt|tjs>tt|}|j	rlx|j
D ]}| |E d H  qTW |jj|d d S )Nr   )r   )r   )r   rl   r   Itemr   Zpytest_itemcollectedr   r   r    r   r   r   r   )r   r   r   ZsubnoderL   rL   rM   r     s    zSession.genitems)T)..)..)NT),rw   r   r   r   rf   r!   __annotations__r   r   rF   r   r   r   classmethodrc   rG   r   r   r   r   r   r   r   r   r   r   r=   r   rV   r   r   r   r
   r   r   r   r	   r   r  r   r   r;   r   __classcell__rL   rL   )r   rM   r[     sB   
	

 A )module_namer$   c          
   C   sj   yt j| }W n tttfk
r*   | S X |dksH|jdksH|jdkrL| S |jr`t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)rC   util	find_specAttributeErrorImportError
ValueErrororiginsubmodule_search_locationsosr=   r   )r  specrL   rL   rM   search_pypath/  s    r  F)r   )invocation_pathr   r   r$   c            C   s   t |d^}}|rt|}| | }t|}| sR|r>dnd}t|j|d|rz| rz|rfdnd}t|j|dtj	
t ||fS )ah  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:

        (py.path.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.
    z::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})rG   r  r  r   r   r   rv   is_dirr   r=   r   )r  r   r   Zstrpathr   r   rZ   rL   rL   rM   r   @  s    r   )Rr   rT   r   rH   rC   r  ro   pathlibr   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   Z_pytest._coderj   r   Z_pytest.compatr   Z_pytest.configr   r   r   r   r   r   Z_pytest.config.argparsingr   Z_pytest.fixturesr   Z_pytest.outcomesr   Z_pytest.pathlibr   r   r   Z_pytest.reportsr   r   Z_pytest.runnerr    r!   Ztyping_extensionsr"   rN   rG   rJ   rF   r|   r~   r}   r   rV   r   r=   r   r   r   r  r   r   rh   r   ri   rf   r   r   ZFSCollectorr[   r  r   rL   rL   rL   rM   <module>   s    29	
  o