o
    v&iå                     @  s@  d 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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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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,m0Z0 ddl,m1Z1 ddl,m2Z2 ddl3m4Z4 dd l3m5Z5 dd!l6m7Z7 dd"l6m8Z8 dd#l9m:Z: erdd$l;m<Z< dd%l=m>Z> dyd*d+Z?dzd.d/Z@d{d5d6ZAd|d7d8ZBd}d<d=ZCd~d>d?ZDddAdBZEddDdEZFddHdIZGddMdNZHddQdRZIG dSdT dTZJG dUdV dVeKZLG dWdX dXeMZNejOG dYdZ dZePeeQf ZReG d[d\ d\ejSZTeG d]d: d:ejUZVd^d_ddcddZWejOdedfG dgdh dhZXd^d^diddodpZYddrdsZZddwdxZ[dS )zHCore implementation of the testing process: init, session, runtest loop.    )annotationsN)Callable)Iterable)Iterator)Sequence)Set)Path)final)Literal)overload)TYPE_CHECKING)nodes)Config)directory_arg)ExitCode)hookimpl)PytestPluginManager)
UsageError)OverrideIniAction)Parser)PathAwareHookProxy)exitabsolutepath)bestrelpath
fnmatch_ex)safe_exists)samefile_nofollow)scandir)CollectReport)
TestReport)collect_one_node)
SetupState)PytestWarning)Self)FixtureManagerparserr   returnNonec              	   C  s`  |  d}|jddddddd |jd	d
dtdddd |jdtdddd |jdtdddd |jdtdddd | jdddd d | jdddd d | jddddd |  d }|jd!d"d#d$d% | jd&d'd(d) |  d*d+}|jd,d-d.d/d0d% |jd1d/d2d% |jd3d#d4d5d6 |jd7d#d4d8d6 |jd9d#d:d;d6 |jd<d=d d>tjtd<d?d@dA |jdBd/dCddDdE |jdFdGd/dHddIdE |jdJd/dKddLdE |jdMd/ddNdOdP |jdQdRg dSdTdUdV | jdWdXdYg dZd | jd[d\dYg d | jd]d^dd_d | jd`dddadb |  dcdd}|jdedfdgt	dhdidj |jdkddldmdn |jdodpd t
d>dqdr d S )sNgeneralz-xz--exitfirststore_constmaxfail   z,Exit instantly on first error or failed test)actiondestconsthelpz	--maxfailnumstorer   z'Exit after first num failures or errors)metavarr.   typer/   defaultr1   z--strict-configstrict_configtruez Enables the strict_config option)r.   
ini_option	ini_valuer1   z--strict-markersstrict_markersz!Enables the strict_markers optionz--strictstrictzEnables the strict optionzbAny warnings encountered while parsing the `pytest` section of the configuration file raise errorsbool)r5   r6   zVMarkers not registered in the `markers` section of the configuration file raise errorszrEnables all strictness options, currently: strict_config, strict_markers, strict_xfail, strict_parametrization_idsFzpytest-warningsz-Wz--pythonwarningsappendz<Set which warnings to report, see -W option of Python itself)r.   r1   filterwarningslinelistz_Each line specifies a pattern for warnings.filterwarnings. Processed after -W/--pythonwarnings.)r5   r1   collect
collectionz--collectonlyz--collect-onlyz--co
store_truez&Only collect tests, don't execute themz--pyargsz1Try to interpret all arguments as Python packagesz--ignorepathz-Ignore path during collection (multi-allowed))r.   r4   r1   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)r/   r6   r4   r5   r1   z--noconftest
noconftestz Don't load any conftest.py files)r.   r/   r6   r1   z--keepduplicatesz--keep-duplicateskeepduplicateszKeep duplicate testsz--collect-in-virtualenvcollect_in_virtualenvz2Don't ignore tests in a local virtualenv directoryz--continue-on-collection-errorscontinue_on_collection_errorsz4Force test execution even if collection errors occur)r.   r6   r/   r1   z--import-modeprepend)rM   r>   	importlib
importmodez\Prepend/append to sys.path when importing test modules and conftest files. Default: prepend.)r6   choicesr/   r1   norecursedirsz)Directory patterns to avoid for recursionargs)	z*.eggz.*_darcsbuildCVSdistnode_modulesvenvz{arch}	testpathszZDirectories to search for tests when no files or directories are given on the command linecollect_imported_testsz@Whether to collect tests in imported modules outside `testpaths`Tconsider_namespace_packageszEConsider namespace packages when resolving module names during import)r5   r6   r1   debugconfigz(test session debugging and configurationz-cz--config-fileFILEinifilenamezcLoad configuration from `FILE` instead of trying to locate one of the implicit configuration files.)r4   r5   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   z
--basetempbasetempz^Base temporary directory for this test run. (Warning: this directory is removed if it exists.))r/   r6   r5   r4   r1   )getgroup
_addoption	addoptionintr   addini	functoolspartialr   strvalidate_basetemp)r'   group rk   R/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/_pytest/main.pypytest_addoption:   s~  
	
	
rm   rD   rh   c                 C  sd   d}| s	t |d	dd}|t t|  rt ||t  t|  r0t || S )
NzWbasetemp must not be empty, the current working directory or any parent directory of itbaser   queryr(   r=   c                 S  s   | |krdS || j v S )z,Return whether query is an ancestor of base.T)parents)rn   ro   rk   rk   rl   is_ancestor   s   
z&validate_basetemp.<locals>.is_ancestor)rn   r   ro   r   r(   r=   )argparseArgumentTypeErrorr   cwdabsoluteresolve)rD   msgrq   rk   rk   rl   ri     s   



ri   configr   doit2Callable[[Config, Session], int | ExitCode | None]int | ExitCodec                 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   r-   session   Nz: 
)excinfoz(mainloop: caught unexpected SystemExit!
)r}   
exitstatus))Sessionfrom_configr   OKr   _do_configurehookpytest_sessionstartr   USAGE_ERRORFailedTESTS_FAILEDKeyboardInterruptr   	Exception_pytest_codeExceptionInfofrom_currentINTERRUPTED
isinstancevalue
returncodesysstderrwritetypenamerw   pytest_keyboard_interruptBaseExceptionINTERNAL_ERRORnotify_exceptionoptionr5   __name__
SystemExitoschdir	startpathpytest_sessionfinish_ensure_unconfigure)rx   ry   r}   	initstater   r   excrk   rk   rl   wrap_session1  s   


*

*

*
r   c                 C  s
   t | tS N)r   _mainrx   rk   rk   rl   pytest_cmdline_mainl  s   
r   r}   r   int | ExitCode | Nonec                 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.r|   r   N)r   pytest_collectionpytest_runtestlooptestsfailedr   r   testscollectedNO_TESTS_COLLECTED)rx   r}   rk   rk   rl   r   p  s   
r   c                 C  s   |    d S r   )perform_collectr|   rk   rk   rl   r   }  s   r   r=   c                 C  s   | j r| jjjs| | j  d| j dkrdnd d| jjjr"dS t| jD ]1\}}|d t| jk r;| j|d  nd }|jj	j
||d | jrO| | j| jrX| | jq'dS )Nz errorr-   s z during collectionT)itemnextitem)r   rx   r   rL   Interruptedcollectonly	enumerateitemslenr   pytest_runtest_protocol
shouldfailr   
shouldstop)r}   ir   r   rk   rk   rl   r     s   
$r   r   c                 C  s6   z|  d p|  dd W S  ty   Y dS w )a  Attempt to detect if ``path`` is the root of a Virtual Environment by
    checking for the existence of the pyvenv.cfg file.

    [https://peps.python.org/pep-0405/]

    For regression protection we also check for conda environments that do not include pyenv.cfg yet --
    https://github.com/conda/conda/issues/13337 is the conda issue tracking adding pyenv.cfg.

    Checking for the `conda-meta/history` file per https://github.com/pytest-dev/pytest/issues/12652#issuecomment-2246336902.

    z
pyvenv.cfgz
conda-metahistoryF)joinpathis_fileOSErrorrD   rk   rk   rl   _in_venv  s   r   collection_pathbool | Nonec                   s    j dkrdS |jd jd}|pg }|d}|r$|dd |D   |v r*dS |jd jd}|p5g }|d	}|rG|d
d |D  t fdd|D rTdS |d}|sat radS   rw|d}t fdd|D rwdS d S )N__pycache__Tcollect_ignorer   ignorec                 s      | ]}t |V  qd S r   r   .0xrk   rk   rl   	<genexpr>      z(pytest_ignore_collect.<locals>.<genexpr>collect_ignore_globignore_globc                 s  r   r   r   r   rk   rk   rl   r     r   c                 3  s$    | ]}t  t t|V  qd S r   )fnmatchrh   )r   globr   rk   rl   r     s   " rK   rQ   c                 3  s    | ]}t | V  qd S r   r   )r   patr   rk   rl   r     s    )	name_getconftest_pathlistparent	getoptionextendanyr   is_dirgetini)r   rx   ignore_paths
excludeoptignore_globsexcludegloboptallow_in_venvnorecursepatternsrk   r   rl   pytest_ignore_collect  s8   




r   r   nodes.Collectornodes.Collector | Nonec                 C  s   t j|| dS )Nr   )Dirfrom_parentrD   r   rk   rk   rl   pytest_collect_directory  s   r   r   list[nodes.Item]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   nodeid
startswithr>   r   pytest_deselected)r   rx   deselect_prefixes	remaining
deselectedcolitemrk   rk   rl   pytest_collection_modifyitems  s   r   c                   @  s    e Zd ZdddZdddZdS )FSHookProxypmr   remove_modsAbstractSet[object]r(   r)   c                 C  s   || _ || _d S r   )r   r   )selfr   r   rk   rk   rl   __init__  s   
zFSHookProxy.__init__r   rh   pluggy.HookCallerc                 C  s    | j j|| jd}|| j|< |S )N)remove_plugins)r   subset_hook_callerr   __dict__)r   r   r   rk   rk   rl   __getattr__  s   
zFSHookProxy.__getattr__N)r   r   r   r   r(   r)   )r   rh   r(   r   )r   
__module____qualname__r   r  rk   rk   rk   rl   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__rk   rk   rk   rl   r     s    r   c                   @  s   e Zd ZdZdS )r   z"Signals a stop as failed test run.Nr  rk   rk   rk   rl   r     s    r   c                   @  s$   e Zd ZU dZded< d	ddZdS )
_bestrelpath_cacher   r   rD   r(   rh   c                 C  s   t | j|}|| |< |S r   )r   rD   )r   rD   rrk   rk   rl   __missing__  s   z_bestrelpath_cache.__missing__N)rD   r   r(   rh   )r   r  r  	__slots____annotations__r	  rk   rk   rk   rl   r     s   
 r  c                      s0   e Zd ZdZed fdd	ZdddZ  ZS )r   a  Collector of files in a file system directory.

    .. versionadded:: 8.0

    .. note::

        Python directories with an `__init__.py` file are instead collected by
        :class:`~pytest.Package` by default. Both are :class:`~pytest.Directory`
        collectors.
    r   r   rD   r   r(   r%   c                  s   t  j||dS )zThe public constructor.

        :param parent: The parent collector of this Dir.
        :param path: The directory's path.
        :type path: pathlib.Path
        )r   rD   )superr   )clsr   rD   	__class__rk   rl   r     s   zDir.from_parent&Iterable[nodes.Item | nodes.Collector]c                 c  s    | j }| j}t| jD ]M}| r6t|j}| jj|dds'|j||dr'q|j	|| d}|d ur5|V  q|
 rYt|j}| j|sM|j||drMq|j|| d}|E d H  qd S )NTwith_parents)r   rx   r   	file_pathr   )rx   ihookr   rD   r   r   r}   
isinitpathr   r   r   pytest_collect_file)r   rx   r  direntryrD   colcolsrk   rk   rl   rA   (  s,   


zDir.collect)r   r   rD   r   r(   r%   )r(   r  )r   r  r  r  classmethodr   rA   __classcell__rk   rk   r  rl   r     s
    r   c                      sT  e Zd ZU dZeZeZded< ded< ded< dT fddZedUddZ	dVddZ
edWddZejdXddZedWddZejdXddZedYddZdZdd Zed!d"d[d#d$Zed!d"d\d'd(ZeZd)d*d]d/d0Zd^d4d5Zd_d9d:Ze	;d`dadAdBZe	;d`dbdDdBZ	!dcdbdFdBZ	!dddedKdLZdfdNdOZdgdRdSZ  ZS )hr   zoThe root of the collection tree.

    ``Session`` collects the initial paths given as arguments to pytest.
    r#   _setupstater&   _fixturemanagerr{   r   rx   r   r(   r)   c              	     s   t  jd|jd d || dd d| _d| _d| _d| _|jj	d| _t
 | _t
 | _g | _g | _i | _g | _t|j| _| jjj| dd d S )Nr   )r   rD   fspathr   rx   r}   r   r   FrB   r}   )r   )r  r   rootpathr   r   _shouldstop_shouldfailtracerootget	frozenset_initialpaths_initialpaths_with_parents	_notfound_initial_parts_collection_cacher   r  _bestrelpathcacherx   pluginmanagerregister)r   rx   r  rk   rl   r   O  s,   	zSession.__init__c                 C  s   | j |d}|S )Nr   )_create)r  rx   r}   rk   rk   rl   r   i  s   zSession.from_configrh   c              	   C  s4   d| j j d| j d| j d| j d	t| dd S )N< z exitstatus=%r testsfailed=z testscollected=>r   z<UNSET>)r  r   r   r   r   getattrr   rk   rk   rl   __repr__n  s   
zSession.__repr__
bool | strc                 C     | j S r   )r!  r4  rk   rk   rl   r   v     zSession.shouldstopr   c                 C  .   |du r| j rtjtddd d S || _ d S )NFzCsession.shouldstop cannot be unset after it has been set; ignoring.r~   
stacklevel)r!  warningswarnr$   r   r   rk   rk   rl   r   z     
c                 C  r7  r   )r"  r4  rk   rk   rl   r     r8  zSession.shouldfailc                 C  r9  )NFzCsession.shouldfail cannot be unset after it has been set; ignoring.r~   r:  )r"  r<  r=  r$   r>  rk   rk   rl   r     r?  r   c                 C  s
   | j jjS )zQThe path from which pytest was invoked.

        .. versionadded:: 7.0.0
        )rx   invocation_paramsrG   r4  rk   rk   rl   r     s   
zSession.startpath	node_pathc                 C  s
   | j | S r   )r,  )r   rA  rk   rk   rl   _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   r4  rk   rk   rl   pytest_collectstart  s
   zSession.pytest_collectstartreportTestReport | CollectReportc                 C  s\   |j r&t|ds(|  jd7  _| jd}|r*| j|kr,d| j d| _d S d S d S d S d S )Nwasxfailr-   r,   zstopping after z	 failures)failedhasattrr   rx   getvaluer   )r   rE  r,   rk   rk   rl   pytest_runtest_logreport  s   z Session.pytest_runtest_logreportFr  rD   str | os.PathLike[str]r  r=   c                C  s.   t |tr|nt|}|r|| jv S || jv S )a>  Is path an initial path?

        An initial path is a path explicitly given to pytest on the command
        line.

        :param with_parents:
            If set, also return True if the path is a parent of an initial path.

        .. versionchanged:: 8.0
            Added the ``with_parents`` parameter.
        )r   r   r(  r'  )r   rD   r  path_rk   rk   rl   r    s   

zSession.isinitpathr  os.PathLike[str]pluggy.HookRelayc                 C  sV   t |tr|nt|}| jj}||}|j|}|r%tt||}|S | jj	}|S r   )
r   r   rx   r-  _getconftestmodules_conftest_plugins
differencer   r   r   )r   r  rD   r   my_conftestmodulesr   proxyrk   rk   rl   gethookproxy  s   
zSession.gethookproxy
path_cache%dict[Path, Sequence[nodes.Collector]]Sequence[nodes.Collector]c                 C  sx   ||v r|| S |  r#| |j}|j|| d}|dur |fnd}n| r4| |}|j|| d}nd}|||< |S )zCreate a Collector for the given path.

        `path_cache` makes it so the same Collectors are returned for the same
        path.
        r   Nrk   r  )r   rU  r   r   r   r  )r   rD   rV  r  r  r  rk   rk   rl   _collect_path  s   

zSession._collect_path.rR   Sequence[str] | NonegenitemsLiteral[True]Sequence[nodes.Item]c                 C     d S r   rk   r   rR   r[  rk   rk   rl   r        zSession.perform_collect&Sequence[nodes.Item | nodes.Collector]c                 C  r^  r   rk   r_  rk   rk   rl   r     r`  Nc              	     s  |du rj j}d| jj jd7  _j j}g _g _i _g _	j	}j 
d zg }g } fddt|D }j dsNt|_n|_jD ]}||j ||j ||jj qTt|_t|_t}	jj|	d jj jd8  _jrg }
jD ]\}}|r|
d	| d
|d q|
d|  qt|
 |s|	j}n|	jr|	jD ]}j	| qj j  |jj |d W g _g _i _|jd ng _g _i _|jd w |rt |_!|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   r-   r[   c              	     s.   g | ]\}}t jjj||jjj d qS )	as_pypathr[   )resolve_collection_argumentrx   r@  rG   r   pyargs)r   r   argr[   r   rk   rl   
<listcomp>-  s    z+Session.perform_collect.<locals>.<listcomp>rJ   rE  znot found: z
(no match in any of )zfound no collectors for )r}   rx   r   r|   )"rx   rR   r#  r$  indentr   r)  r*  r+  r   r   r   r   normalize_collection_argumentsr>   rD   r   rp   r&  r'  r(  r"   r  pytest_collectreportr   resultpassedr[  r-  check_pendingr   pytest_collection_finishr   r   )r   rR   r[  r   r   initialpathsinitialpaths_with_parentscollection_argscollection_argumentreperrorsrf  
collectorsnoderk   rg  rl   r   	  sx   




ry  r   handle_dupestuple[CollectReport, bool]c                 C  s:   || j v r|r| j | }|dfS t|}|| j |< |dfS )NTF)r+  r"   )r   ry  rz  rv  rk   rk   rl   _collect_one_nodej  s   

zSession._collect_one_node&Iterator[nodes.Item | nodes.Collector]c                 c  s   i }| j j}| jD ]e}| d| | jj jd7  _|j}|j}|j}|j	}|
 r7|r7J d||f|g}|d u rR|jD ]}	||	sJ n|d|	 qAn&|d}
t|jdD ]\}}	|t|
kso|	j|
|  krq n|d|	 q]d}g }| g ||fg}|rQ| \}}|s|V  d}qt|tjsqt|trt|d tsJ ||d |}n/t|dkot|d to|d   }| ||\}}|s|js|jj|d	 |jsq|j}d}t|D ]]}t|d tr|j|d k}t j!d
kr|st"|j|d }n*t|dkr/|d ur"|j#|d | k}n|j#dd |d k}n|j#|d k}|rF|$||dd  f d}q|sO|$| |s|sgd%t&|g|R }| j'$||f | jj jd8  _q
d S )Nzprocessing argumentr-   zinvalid arg r   .r~   FTri  win32[::)(rx   r-  r*  r#  r$  rk  rD   partsparametrizationmodule_namer   rp   _is_in_confcutdirinsertsplitr   r   stempopr   r   	Collectorr   r   rY  r   r|  ro  r  rm  rn  reversedr   platformr   r   r>   joinrh   r)  )r   rV  r   ru  argpathnamesr  r  pathsrD   module_name_partsr   any_matched_in_initial_partnotfound_collectorswork	matchnode
matchpartssubnodesrz  rv  	duplicateany_matched_in_collectorry  is_match
report_argrk   rk   rl   rA   w  s   







HzSession.collectnodes.Item | nodes.CollectorIterator[nodes.Item]c                 c  s    |  d| t|tjr|jj|d |V  d S t|tjs!J t|tj }| ||\}}|j	rA|j
D ]
}| |E d H  q6|sL|jj|d d S d S )Nr[  )r   ri  )r#  r   r   Itemr  pytest_itemcollectedr  Filer|  ro  rn  r[  rm  )r   ry  rz  rv  r  subnoderk   rk   rl   r[    s   

zSession.genitems)rx   r   r(   r)   )rx   r   r(   r   )r(   rh   )r(   r6  )r   r6  r(   r)   )r(   r   )rA  r   r(   rh   )r(   r)   )rE  rF  r(   r)   )rD   rL  r  r=   r(   r=   )r  rN  r(   rO  )rD   r   rV  rW  r(   rX  )..)rR   rZ  r[  r\  r(   r]  )rR   rZ  r[  r=   r(   ra  )NT)T)ry  r   rz  r=   r(   r{  )r(   r}  )ry  r  r(   r  )r   r  r  r  r   r   r  r   r  r   r5  propertyr   setterr   r   rB  r   rD  rK  rm  r  rU  rY  r   r   r|  rA   r[  r  rk   rk   r  rl   r   @  sV   
 



d
|Fr[   r  r[   
str | Nonec             
   C  s   zt j| }W n tttfy   Y dS w |du rdS |jdu s(t|jdkr+|jS |r2|jd S |jdu r9dS t	j
|jS )zaSearch sys.path for the given a dotted module name, and return its file
    system path if found.Nr   )rN   util	find_specAttributeErrorImportError
ValueErrorsubmodule_search_locationsr   originr   rD   dirname)r  r[   specrk   rk   rl   search_pypath  s   


r  T)frozenc                   @  s:   e Zd ZU dZded< ded< ded< ded< d	ed
< dS )CollectionArgumentzA resolved collection argument.r   rD   zSequence[str]r  r  r  r  rd   original_indexN)r   r  r  r  r  rk   rk   rk   rl   r  (  s   
 r  rb  invocation_pathrf  	arg_indexrd   rc  c                C  s   | d\}}}|d^}}	|r|	std| |r"| | nd}
d}|r6t||d}|dur6|}|}| | }t|}t|sP|rFdnd}t|j|d|	rd| rd|rZd	nd
}t|j|dt||	|
||d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 resolved `CollectionArgument`:

        CollectionArgument(
            path=Path("/full/path/to/pkg/tests/test_foo.py"),
            parts=["TestClass", "test_foo"],
            module_name=None,
        )

    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[a,b]"

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

        CollectionArgument(
            path=Path("/home/u/myvenv/lib/site-packages/pkg/tests/test_foo.py"),
            parts=["TestClass", "test_foo"],
            parametrization="[a,b]",
            module_name="pkg.tests.test_foo",
        )

    If the path doesn't exist, raise UsageError.
    If the path is a directory and selection parts are present, raise UsageError.
    r  r  z(path cannot contain [] parametrization: Nr  z9module or package not found: {arg} (missing __init__.py?)z"file or directory not found: {arg}rf  z9package argument cannot contain :: selection parts: {arg}z;directory argument cannot contain :: selection parts: {arg})rD   r  r  r  r  )		partitionr  r   r  r   r   formatr   r  )r  rf  r  rc  r[   rn   squacketreststrpathr  r  r  pyarg_strpathr  rw   rk   rk   rl   rd  3  sD   )rd  byc                 C  st   |j | j kr|js| j |j S dS t|jt| jks)| jdt|j |jkr+dS |jdur8|j| jkr8dS dS )z/Check if `arg` is subsumed (contained) by `by`.FNT)rD   r  is_relative_tor   r  )rf  r  rk   rk   rl   "is_collection_argument_subsumed_by  s   .r  rt  Sequence[CollectionArgument]list[CollectionArgument]c                 C  sV   t | dd d}g }d}|D ]}|du st||s || |}q|jdd d |S )a  Normalize collection arguments to eliminate overlapping paths and parts.

    Detects when collection arguments overlap in either paths or parts and only
    keeps the shorter prefix, or the earliest argument if duplicate, preserving
    order. The result is prefix-free.
    c                 S  s   | j | j| jpdfS )Nr   )rD   r  r  r  rk   rk   rl   <lambda>  s    z0normalize_collection_arguments.<locals>.<lambda>)keyNc                 S  r7  r   )r  r  rk   rk   rl   r    s    )sortedr  r>   sort)rt  collection_args_sorted
normalized	last_keptrf  rk   rk   rl   rl    s   
rl  )r'   r   r(   r)   )rD   rh   r(   rh   )rx   r   ry   rz   r(   r{   )rx   r   r(   r{   )rx   r   r}   r   r(   r   )r}   r   r(   r)   )r}   r   r(   r=   )rD   r   r(   r=   )r   r   rx   r   r(   r   )rD   r   r   r   r(   r   )r   r   rx   r   r(   r)   )r  rh   r[   r=   r(   r  )r  r   rf  rh   r  rd   rc  r=   r[   r=   r(   r  )rf  r  r  r  r(   r=   )rt  r  r(   r  )\r  
__future__r   rr   collections.abcr   r   r   r   r   AbstractSetdataclassesr   rf   rN   importlib.utilr   pathlibr   r   typingr	   r
   r   r   r<  pluggyr   r   _pytest._code_pytest.configr   r   r   r   r   r   _pytest.config.argparsingr   r   _pytest.config.compatr   _pytest.outcomesr   _pytest.pathlibr   r   r   r   r   r   _pytest.reportsr    r!   _pytest.runnerr"   r#   _pytest.warning_typesr$   typing_extensionsr%   _pytest.fixturesr&   rm   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	dataclassdictrh   r  	Directoryr   r  r   r  r  rd  r  rl  rk   rk   rk   rl   <module>   s    
 
_

;





&
3   G
$
O