o
    v&i3                     @  s  d 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mZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddl%m'Z' ddl(m)Z) ddl(m*Z* ddl(m+Z+ ddl,m-Z- ddl.m/Z/ ddl.m0Z0 dd l.m1Z1 dd!l2m3Z3 erdd"l4m5Z5 dUd'd(Z6ej7d)d)d)d*G d+d, d,Z8ej7d-d.G d/d0 d0e-Z9e&dVd4d5Z:G d6d3 d3Z;ej7G d7d8 d8Z<edWd:d;Z=edXd=d>Z>ej7G d?d@ d@Z?ej7G dAdB dBZ@dYdFdGZAdZdKdLZBe3eeCeDf   ZEd[dOdPZFe d)dQd\dSdTZGdS )]z*Builtin plugin that adds subtests support.    )annotations)defaultdict)Callable)Iterator)Mapping)AbstractContextManager)contextmanager)	ExitStack)nullcontextN)TracebackType)Any)TYPE_CHECKING)ExceptionInfosaferepr)CaptureFixture)	FDCapture)
SysCapture)Config)hookimpl)Parser)check_ispytest)fixture)
SubRequest)catching_logs)LogCaptureHandler)LoggingPlugin)
TestReport)CallInfo)check_interactive_exception)get_reraise_exceptions)StashKey)Selfparserr   returnNonec                 C  s   t j| t jdd d S )NzSpecify verbosity level for subtests. Higher levels will generate output for passed subtests. Failed subtests are always reported.)help)r   _add_verbosity_iniVERBOSITY_SUBTESTS)r#    r)   V/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/_pytest/subtests.pypytest_addoption.   s
   
r+   T)frozenslotskw_onlyc                   @  s:   e Zd ZU dZded< ded< ddd	ZedddZdS )SubtestContextzJThe values passed to Subtests.test() that are included in the test report.
str | NonemsgzMapping[str, Any]kwargsr$   dict[str, Any]c                 C  s
   t | S N)dataclassesasdict)selfr)   r)   r*   _to_json@   s   
zSubtestContext._to_jsondr"   c                 C  s   | |d |d dS )Nr1   r2   r1   r2   r)   )clsr9   r)   r)   r*   
_from_jsonC   s   zSubtestContext._from_jsonNr$   r3   )r9   r3   r$   r"   )__name__
__module____qualname____doc____annotations__r8   classmethodr<   r)   r)   r)   r*   r/   9   s   
 
r/   F)initc                      sd   e Zd ZU ded< edddZdddZd fd
dZed fddZ	ed fddZ
  ZS )SubtestReportr/   contextr$   strc                 C  s   | j \}}}| d|   S )N )location_sub_test_description)r7   _domainr)   r)   r*   	head_lineL   s   zSubtestReport.head_linec                 C  sj   g }| j jd ur|d| j j d | j jr.ddd | j j D }|d| d d|p4d	S )
N[]z, c                 s  s&    | ]\}}| d t | V  qdS )=Nr   ).0kvr)   r)   r*   	<genexpr>V   s    
z6SubtestReport._sub_test_description.<locals>.<genexpr>()rH   z(<subtest>))rF   r1   appendr2   joinitems)r7   partsparams_descr)   r)   r*   rJ   Q   s   

z#SubtestReport._sub_test_descriptionr3   c                   s*   t   }|d= d|d< | j |d< |S )NrF   SubTestReport_report_type_subtest.context)superr8   rF   )r7   data	__class__r)   r*   r8   \   s
   
zSubtestReport._to_json
reportdictc                   s    t  |}t|d |_|S )Nr^   )r_   r<   r/   rF   )r;   rc   reportra   r)   r*   r<   c   s   zSubtestReport._from_jsontest_reportr   captured_outputCaptured | Nonecaptured_logsCapturedLogs | Noner"   c                   sr   t  | }||_|r%|jr|jd|jf |jr%|jd|jf |r7|jj	
  }r7|jd|f |S )NzCaptured stdout callzCaptured stderr callzCaptured log call)r_   r<   r8   rF   outsectionsrW   errhandlerstreamgetvalue)r;   re   rF   rf   rh   resultlogra   r)   r*   _newi   s   zSubtestReport._new)r$   rG   r=   )rc   r3   r$   rE   )
re   r   rF   r/   rf   rg   rh   ri   r$   r"   )r>   r?   r@   rB   propertyrM   rJ   r8   rC   r<   rr   __classcell__r)   r)   ra   r*   rE   H   s   
 
rE   requestr   Subtestsc                 C  s6   | j jjd}|dur|jnt}t| j j|| ddS )z Provides subtests functionality.capturemanagerNT	_ispytest)nodeconfigpluginmanager
get_pluginglobal_and_fixture_disabledr
   rv   ihook)ru   capmamsuspend_capture_ctxr)   r)   r*   subtests   s   r   c                   @  s.   e Zd ZdZdddddZ	ddddZdS )rv   z_Subtests fixture, enables declaring subtests inside test functions via the :meth:`test` method.Frx   r   pluggy.HookRelayr   *Callable[[], AbstractContextManager[None]]ru   r   ry   boolr$   r%   c                C  s   t | || _|| _|| _d S r4   )r   _ihook_suspend_capture_ctx_request)r7   r   r   ru   ry   r)   r)   r*   __init__   s   
zSubtests.__init__Nr1   r0   r2   r   _SubTestContextManagerc                 K  s   t | j||| j| j| jjdS )ad  
        Context manager for subtests, capturing exceptions raised inside the subtest scope and
        reporting assertion failures and errors individually.

        Usage
        -----

        .. code-block:: python

            def test(subtests):
                for i in range(5):
                    with subtests.test("custom message", i=i):
                        assert i % 2 == 0

        :param msg:
            If given, the message will be shown in the test report in case of subtest failure.

        :param kwargs:
            Arbitrary values that are also added to the subtest report.
        )ru   r   r{   )r   r   r   r   r{   )r7   r1   r2   r)   r)   r*   test   s   zSubtests.test)
r   r   r   r   ru   r   ry   r   r$   r%   r4   )r1   r0   r2   r   r$   r   )r>   r?   r@   rA   r   r   r)   r)   r)   r*   rv      s    c                   @  sV   e Zd ZU dZded< ded< ded< ded	< d
ed< ded< dddZdddZdS )r   z
    Context manager for subtests, capturing exceptions raised inside the subtest scope and handling
    them through the pytest machinery.
    r   r   r0   r1   r3   r2   r   r   r   ru   r   r{   r$   r%   c                 C  sR   d}t   | _t  | _d | _t | _| jt| j	| _
| jt| j	| _d S )NT)time_startperf_counter_precise_start	_exc_infor	   _exit_stackenter_contextcapturing_outputru   _captured_outputcapturing_logs_captured_logs)r7   __tracebackhide__r)   r)   r*   	__enter__   s   


z _SubTestContextManager.__enter__exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | Noner   c              	   C  s>  d}|d urt |}nd }| j  t }|| j }t }td  d || j||ddd}	| j	j
| jj|	d}
tj|
t| j| jd| j| jd}|jr]| jjt }|| jjj  d7  < |   | j	j|d W d    n1 ssw   Y  t|	|r| j	j| jj|	|d	 |d urt|t| jrd
S | jjj rd
S dS )NTcall)startstopdurationwhenry   )itemr   r:   )rf   rh      rd   )rz   r   rd   F)!r   from_exceptionr   closer   r   r   r   r   r   pytest_runtest_makereportru   rz   rE   rr   r/   r1   r2   r   r   failedr{   stashfailed_subtests_keynodeidr   pytest_runtest_logreportr   pytest_exception_interact
isinstancer    session
shouldfail)r7   r   r   r   r   exc_infoprecise_stopr   r   	call_inford   
sub_reportfailed_subtestsr)   r)   r*   __exit__   sT   

	



z_SubTestContextManager.__exit__N)r$   r%   )r   r   r   r   r   r   r$   r   )r>   r?   r@   rA   rB   r   r   r)   r)   r)   r*   r      s   
 

r   Iterator[Captured]c                 c  s    | j dd }| j jd}t|dd rd }n|dkr$tt| dd}n|dkr0tt| dd}nd }|d ur:|  t	 }z|V  W |d urX|
 \}}|  ||_||_d S d S |d urn|
 \}}|  ||_||_w )Ncapturerw   _capture_fixturesysTrx   fd)r{   	getoptionr|   	getplugingetattrr   r   r   r   Captured
readouterrr   rj   rl   )ru   optioncapmanr   capturedrj   rl   r)   r)   r*   r     s2   
r   Iterator[CapturedLogs | None]c                 c  sv    | j jd}|d u rd V  d S t }||j t|}t||jd |V  W d    d S 1 s4w   Y  d S )Nzlogging-plugin)level)	r{   r|   r   r   setFormatter	formatterCapturedLogsr   	log_level)ru   logging_pluginrm   rh   r)   r)   r*   r   5  s   
"r   c                   @  s&   e Zd ZU dZded< dZded< dS )r    rG   rj   rl   N)r>   r?   r@   rj   rB   rl   r)   r)   r)   r*   r   G  s   
 r   c                   @  s   e Zd ZU ded< dS )r   r   rm   N)r>   r?   r@   rB   r)   r)   r)   r*   r   M  s   
 r   rd   r   dict[str, Any] | Nonec                 C  s   t | tr	|  S d S r4   )r   rE   r8   r   r)   r)   r*   pytest_report_to_serializableR  s   
r   r`   r3   SubtestReport | Nonec                 C  s   |  ddkrt| S d S )Nr]   r\   )getrE   r<   )r`   r)   r)   r*   pytest_report_from_serializableX  s   
r   r{   r   c                 C  s   t dd | jt< d S )Nc                   S  s   dS )Nr   r)   r)   r)   r)   r*   <lambda>d  s    z"pytest_configure.<locals>.<lambda>)r   r   r   )r{   r)   r)   r*   pytest_configurec  s   r   )tryfirst0tuple[str, str, str | Mapping[str, bool]] | Nonec           
      C  s  | j dkrd S |tjdk}t| trh| j}|  }t| dr:|r$dS |dkr/d}d}d}nd S ||| | fS | j	rE|d	d
| fS | j
rW|rLdS d| d	d| fS | jrf|r^dS |dd| fS d S |jt | j }| j
r|dkrd| _|dkrdnd}	d| d|	 | _d S )Nr   r   wasxfail)r   r   r   skippedxfailedySUBXFAILu	SUBFAILEDz	subtests 	SUBPASSED-
SUBSKIPPEDr   r   sr   z	contains z failed subtest)r   get_verbosityr   r(   r   rE   outcomerJ   hasattrr   passedr   r   r   r   longrepr)
rd   r{   quietr   descriptioncategoryshortstatusfailed_subtests_countsuffixr)   r)   r*   pytest_report_teststatusg  s@   



r   )r#   r   r$   r%   )ru   r   r$   rv   )ru   r   r$   r   )ru   r   r$   r   )rd   r   r$   r   )r`   r3   r$   r   )r{   r   r$   r%   )rd   r   r{   r   r$   r   )HrA   
__future__r   collectionsr   collections.abcr   r   r   
contextlibr   r   r	   r
   r5   r   typesr   typingr   r   pluggy_pytest._coder   _pytest._io.safereprr   _pytest.capturer   r   r   _pytest.configr   r   _pytest.config.argparsingr   _pytest.deprecatedr   _pytest.fixturesr   r   _pytest.loggingr   r   r   _pytest.reportsr   _pytest.runnerr   r   r    _pytest.stashr!   typing_extensionsr"   r+   	dataclassr/   rE   r   rv   r   r   r   r   r   r   r   rG   intr   r   r   r)   r)   r)   r*   <module>   sz    

7	3Z


