
    עi3                    |   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rdd"l4m5Z5 d<d#Z6 ejn                  d$d$d$%       G d& d'             Z8 ejn                  d()       G d* d+e-             Z9e&d=d-       Z: G d. d,      Z;ejn                   G d/ d0             Z<ed>d1       Z=e	 	 	 	 d?d2       Z>ejn                   G d3 d4             Z?ejn                   G d5 d6             Z@d@d7ZAdAd8ZB e3eeCeDf             ZEdBd9ZF e d$:      	 	 	 	 	 	 dCd;       ZGy)Dz*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)Selfc                P    t        j                  | t         j                  d       y )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)parsers    Q/sites/domain-asset-master/.venv/lib/python3.12/site-packages/_pytest/subtests.pypytest_addoptionr*   .   s"    
!!k	    T)frozenslotskw_onlyc                  @    e Zd ZU dZded<   ded<   d	dZed
d       Zy)SubtestContextzJThe values passed to Subtests.test() that are included in the test report.
str | NonemsgzMapping[str, Any]kwargsc                ,    t        j                  |       S N)dataclassesasdict)selfs    r)   _to_jsonzSubtestContext._to_json@   s    !!$''r+   c                "     | |d   |d         S )Nr2   r3   r2   r3    )clsds     r)   
_from_jsonzSubtestContext._from_jsonC   s    qx(44r+   Nreturndict[str, Any])r>   rB   rA   r#   )__name__
__module____qualname____doc____annotations__r9   classmethodr?   r<   r+   r)   r0   r0   9   s)    T	O( 5 5r+   r0   F)initc                       e Zd ZU ded<   edd       ZddZd	 fdZed
 fd       Z	e	 	 	 	 	 	 	 	 	 	 d fd       Z
 xZS )SubtestReportr0   contextc                L    | j                   \  }}}| d| j                          S )N )location_sub_test_description)r8   _domains      r)   	head_linezSubtestReport.head_lineL   s,    }}1f4557899r+   c                x   g }| j                   j                  )|j                  d| j                   j                   d       | j                   j                  rOdj	                  d | j                   j                  j                         D              }|j                  d| d       dj	                  |      xs dS )	N[]z, c              3  B   K   | ]  \  }}| d t        |         yw)=Nr   ).0kvs      r)   	<genexpr>z6SubtestReport._sub_test_description.<locals>.<genexpr>V   s(      $)/!Q1#Qx{m$$s   ()rN   z(<subtest>))rL   r2   appendr3   joinitems)r8   partsparams_descs      r)   rP   z#SubtestReport._sub_test_descriptionQ   s    <<'LL1T\\--.a01<<)) $37<<3F3F3L3L3N$ K LL1[M+,xx/-/r+   c                n    t         |          }|d= d|d<   | j                  j                         |d<   |S )NrL   SubTestReport_report_type_subtest.context)superr9   rL   )r8   data	__class__s     r)   r9   zSubtestReport._to_json\   s>    w!O.^#'<<#8#8#: r+   c                `    t         |   |      }t        j                  |d         |_        |S )Nrg   )rh   r?   r0   rL   )r=   
reportdictreportrj   s      r)   r?   zSubtestReport._from_jsonc   s/    #J/'22:>P3QRr+   c                   t         |   |j                               }||_        |rf|j                  r'|j
                  j                  d|j                  f       |j                  r'|j
                  j                  d|j                  f       |rC|j                  j                  j                         x}r|j
                  j                  d|f       |S )NzCaptured stdout callzCaptured stderr callzCaptured log call)rh   r?   r9   rL   outsectionsr_   errhandlerstreamgetvalue)r=   test_reportrL   captured_outputcaptured_logsresultlogrj   s          r)   _newzSubtestReport._newi   s     #K$8$8$:; ""&&(>@S@S'TU""&&(>@S@S'TU]%:%:%A%A%J%J%LLcLOO""$7#=>r+   )rA   strr@   )rl   rB   rA   rK   )
ru   r   rL   r0   rv   zCaptured | Nonerw   zCapturedLogs | NonerA   r#   )rC   rD   rE   rG   propertyrS   rP   r9   rH   r?   rz   __classcell__)rj   s   @r)   rK   rK   H   s}    : :	0  
    )	
 + 
 r+   rK   Subtestsc                    | j                   j                  j                  j                  d      }||j                  nt
        }t        | j                   j                  || d      S )z Provides subtests functionality.capturemanagerT	_ispytest)nodeconfigpluginmanager
get_pluginglobal_and_fixture_disabledr   r~   ihook)requestcapmamsuspend_capture_ctxs      r)   subtestsr      sY     \\  ..99:JKF.4.@**k  GLL&&(;WPTUUr+   c                  F    e Zd ZdZdd	 	 	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 d	dZy)
r~   z_Subtests fixture, enables declaring subtests inside test functions via the :meth:`test` method.Fr   c               D    t        |       || _        || _        || _        y r5   )r   _ihook_suspend_capture_ctx_request)r8   r   r   r   r   s        r)   __init__zSubtests.__init__   s"     	y!$7!r+   Nc                    t        | j                  ||| j                  | j                  | j                  j                        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.
        )r   r   r   )_SubTestContextManagerr   r   r   r   )r8   r2   r3   s      r)   testzSubtests.test   s;    2 &KKMM $ 9 9==''
 	
r+   )
r   pluggy.HookRelayr   *Callable[[], AbstractContextManager[None]]r   r   r   boolrA   Noner5   )r2   r1   r3   r   rA   r   )rC   rD   rE   rF   r   r   r<   r+   r)   r~   r~      sf    i     H  	    
   
 
  
 
 	 
r+   c                  n    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Z	 	 	 	 	 	 	 	 ddZy)r   z
    Context manager for subtests, capturing exceptions raised inside the subtest scope and handling
    them through the pytest machinery.
    r   r   r1   r2   rB   r3   r   r   r   r   r   r   c                d   d}t        j                          | _        t        j                         | _        d | _        t               | _        | j                  j                  t        | j                              | _
        | j                  j                  t        | j                              | _        y )NT)time_startperf_counter_precise_start	_exc_infor
   _exit_stackenter_contextcapturing_outputr   _captured_outputcapturing_logs_captured_logs)r8   __tracebackhide__s     r)   	__enter__z _SubTestContextManager.__enter__   s     iik"//1$; $ 0 0 > >T\\*!
 #..<<4<<(
r+   c           	     B   d}|t        j                  |      }nd }| j                  j                          t	        j
                         }|| j                  z
  }t	        j                         }t        d    d || j                  ||dd      }	| j                  j                  | j                  j                  |	      }
t        j                  |
t        | j                   | j"                        | j$                  | j&                        }|j(                  rH| j*                  j,                  t.           }|| j                  j                  j0                  xx   dz  cc<   | j3                         5  | j                  j5                  |       d d d        t7        |	|      r2| j                  j9                  | j                  j                  |	|	       |At;        |t=        | j*                              ry
| j                  j>                  j@                  ry
y# 1 sw Y   xY w)NTcall)startstopdurationwhenr   )itemr   r;   )rv   rw      rm   )r   r   rm   F)!r   from_exceptionr   closer   r   r   r   r   r   pytest_runtest_makereportr   r   rK   rz   r0   r2   r3   r   r   failedr   stashfailed_subtests_keynodeidr   pytest_runtest_logreportr    pytest_exception_interact
isinstancer!   session
shouldfail)r8   exc_typeexc_valexc_tbr   exc_infoprecise_stopr   r   	call_inform   
sub_reportfailed_subtestss                r)   __exit__z_SubTestContextManager.__exit__   s    !$33G<HH ((*$"5"55yy{TN++
	 55"" 6 
 #''txx< 11--	 ( 

 "kk//0CDODLL--445:5%%' 	CJJ//z/B	C 'y*=JJ00\\&&Yz 1  '#9$++#FG||##..	C 	Cs   .HHN)rA   r   )r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | NonerA   r   )rC   rD   rE   rF   rG   r   r   r<   r+   r)   r   r      s[     	OCCN
6,6 &6 %	6
 
6r+   r   c              #  8  K   | j                   j                  dd       }| j                   j                  j                  d      }t	        |dd       rd }n2|dk(  rt        t        | d      }n|dk(  rt        t        | d      }nd }| |j                          t               }	 | |4 |j                         \  }} |j                          ||_        ||_        y y # |4 |j                         \  }} |j                          ||_        ||_        w w xY ww)Ncapturer   _capture_fixturesysTr   fd)r   	getoptionr   	getplugingetattrr   r   r   r   Captured
readouterrr   ro   rq   )r   optioncapmanr   capturedro   rq   s          r)   r   r     s    ^^%%i6F^^))334DEFv)40	5 WE	4 GtDzH)w))+HCGMMOHLHL	 7)w))+HCGMMOHLHL	 s   B!D$C (7D8DDc              #  $  K   | j                   j                  j                  d      }|d  y t               }|j	                  |j
                         t        |      }t        ||j                        5  | d d d        y # 1 sw Y   y xY ww)Nzlogging-plugin)level)	r   r   r   r   setFormatter	formatterCapturedLogsr   	log_level)r   logging_pluginrr   rw   s       r)   r   r   5  s      ,3>>+G+G+Q+Q,N 
#%^556$W-7.*B*BC 	 	  	  	 s   A4B6B;	BB	Bc                  *    e Zd ZU dZded<   dZded<   y)r    r{   ro   rq   N)rC   rD   rE   ro   rG   rq   r<   r+   r)   r   r   G  s    CMCMr+   r   c                      e Zd ZU ded<   y)r   r   rr   N)rC   rD   rE   rG   r<   r+   r)   r   r   M  s    r+   r   c                D    t        | t              r| j                         S y r5   )r   rK   r9   r   s    r)   pytest_report_to_serializabler   R  s    &-(  r+   c                V    | j                  d      dk(  rt        j                  |       S y )Nrf   re   )getrK   r?   )ri   s    r)   pytest_report_from_serializabler   X  s'    xx?2''--r+   c                >    t        d       | j                  t        <   y )Nc                      y)Nr   r<   r<   r+   r)   <lambda>z"pytest_configure.<locals>.<lambda>d  s    r+   )r   r   r   )r   s    r)   pytest_configurer   c  s    (3I(>FLL$%r+   )tryfirstc                2   | j                   dk7  ry |j                  t        j                        dk(  }t	        | t
              r| j                  }| j                         }t        | d      r|ry|dk(  rd}d}d}ny ||| | fS | j                  r|d	d
| fS | j                  r|ryd| d	d| fS | j                  r|ry|dd| fS y |j                  t           | j                     }| j                  r"|dkD  rd| _        |dkD  rdnd}	d| d|	 | _        y )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   rK   outcomerP   hasattrr   passedr   r   r   r   longrepr)
rm   r   quietr   descriptioncategoryshortstatusfailed_subtests_countsuffixs
             r)   pytest_report_teststatusr   g  sS   
 {{f  !:!:;q@E&-(..2246:&!I%$# Uvh{m$<<<==C9[M!:::}}%&wi0#;-7PPP%"C:k])CCC  !'-@ A&-- P==2Q6%FN1A5S2F )*?)@PVxXFOr+   )r(   r   rA   r   )r   r   rA   r~   )r   r   rA   zIterator[Captured])r   r   rA   zIterator[CapturedLogs | None])rm   r   rA   zdict[str, Any] | None)ri   rB   rA   zSubtestReport | None)r   r   rA   r   )rm   r   r   r   rA   z0tuple[str, str, str | Mapping[str, bool]] | None)HrF   
__future__r   collectionsr   collections.abcr   r   r   
contextlibr   r	   r
   r   r6   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*   	dataclassr0   rK   r   r~   r   r   r   r   r   r   r   r{   intr   r   r   r<   r+   r)   <module>r     s   0 " # $ $ # - %   "        ' ) * % & ! # , - $ ' ) - ) & # 6 1 " & d$=5 5 >5 E"4J 4 #4n 	V 	V0
 0
f W W Wt  8   "   "   
    6h{38457 ? 
4333 63 3r+   