
    ih;                         S SK Jr  S SKJr  S SKJr  S SKrS SKrS SKrS SK	r	S SK
r
S SKrS SKrSSKJr   " S S5      r " S	 S
\5      r " S S\5      r " S S\R&                  5      r " S S5      r\R,                  S 5       rS rS rS rg)    )print_function)OrderedDict)contextmanagerN   )	serializec                   ,   \ rS rSrSS jrS rS r\R                  " SS9S 5       r	\
S	 5       r\R                  " SS9S
 5       r\R                  " SS9S 5       r\R                  " SS9S 5       r\R                  " SS9S 5       r\S 5       rS rSrg)JSONReportBase   Nc                 D    Xl         [        R                  " 5       U l        g N)_configlogging	getLogger_loggerselfconfigs     W/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/pytest_jsonreport/plugin.py__init__JSONReportBase.__init__   s    ((*    c                 B   U R                   c  Xl         [        US5      (       d  X R                   l        U R                   R                  R                  S:X  aG  U R                  S5      (       d0  U R                   R                  R                  R                  S5        g g g )N_json_reportno	traceback)r   hasattrr   optiontbstyle
_must_omitjson_report_omitappendr   s     r   pytest_configureJSONReportBase.pytest_configure   sy     <<!Lv~..(,LL%<<&&$.{++LL0077D , /r   c                 .    UR                  [        5        g r   )add_hookspecsHooks)r   pluginmanagers     r   pytest_addhooksJSONReportBase.pytest_addhooks"   s    ##E*r   Thookwrapperc              #   &   #    0 Ul         S v   U? g 7fr   )_json_report_extra)r   itemnextitems      r   pytest_runtest_protocol&JSONReportBase.pytest_runtest_protocol%   s     "$#s   c              #     #    [        5       nU R                  R                  U5         S v   U R                  R                  U5        UR                  UR
                  U   S'   g ! U R                  R                  U5        f = f7f)Nlog)LoggingHandlerr   
addHandlerremoveHandlerrecordsr-   )r   r.   whenhandlers       r   _capture_logJSONReportBase._capture_log+   sg      "(	0LL&&w//6%e, LL&&w/s   &BA% 8B%BBc              #      #    0 UR                   S'   U R                  S5      (       a  S v   g U R                  US5         S v   S S S 5        g ! , (       d  f       g = f7f)Nsetupr3   r-   r   r:   r   r.   s     r   pytest_runtest_setup#JSONReportBase.pytest_runtest_setup5   sE     +-(??5!!""41 211   =AA	A
AAc              #      #    0 UR                   S'   U R                  S5      (       a  S v   g U R                  US5         S v   S S S 5        g ! , (       d  f       g = f7f)Ncallr3   r>   r?   s     r   pytest_runtest_call"JSONReportBase.pytest_runtest_call>   sE     *,'??5!!""40 100rB   c              #      #    0 UR                   S'   U R                  S5      (       a  S v   g U R                  US5         S v   S S S 5        g ! , (       d  f       g = f7f)Nteardownr3   r>   r?   s     r   pytest_runtest_teardown&JSONReportBase.pytest_runtest_teardownG   sE     .0
+??5!!""44 544rB   c              #   4  #    S v R                  5       nU R                  S5      (       dd  UR                   VVVs0 s H!  u  pEnXCR                  :X  d  M  US;   d  M  XV_M#     nnnnUR                  UR                     R                  U5        U R                  R                  R                  UUS9 H7  nU(       d  M  UR                  R                  S0 5      R                  U5        M9     U R                  U5        UR                  Ul        g s  snnnf 7f)Nstreams)stdoutstderr)r.   rD   metadata)
get_resultr   _report_sectionsr8   r-   updater   hookpytest_json_runtest_metadata
setdefault_validate_metadata)	r   r.   rD   reportwhen_keyvalrL   dict_s	            r   pytest_runtest_makereport(JSONReportBase.pytest_runtest_makereportP   s      ##%y))7;7L7L M7LOE+  037K0K  sx7LG M##DII.55g>\\&&CCIM D OE##..z2>EEeL	O
 	% %)$;$;!Ms   9DDDD#B5Dc                     SU R                   ;  a  g[        R                  " U R                   S   5      (       d=  [        R                  " SR                  U R                  5      5        U R                   S	 gg)zGEnsure that `item` has JSON-serializable metadata, otherwise delete
it.rO   Nz(Metadata of {} is not JSON-serializable.)r-   r   serializablewarningswarnformatnodeid)r.   s    r   rV   !JSONReportBase._validate_metadatac   sd     T444%%d&=&=j&IJJMM:AA$++NP''
3 Kr   c                 F    XR                   R                  R                  ;   $ r   )r   r   r    )r   rY   s     r   r   JSONReportBase._must_omitn   s    ll))::::r   )r   r   r   )__name__
__module____qualname____firstlineno__r   r"   r(   pytesthookimplr0   r   r:   r@   rE   rI   r\   staticmethodrV   r   __static_attributes__ r   r   r	   r	      s    +
E+ __&$ '$
 ? ? __& ' __& ' __& ' __&< '<$ 4 4;r   r	   c                      \ rS rSrSrS rS rS rS r\	R                  " SS9S	 5       rS
 r\	R                  " SS9S 5       r\	R                  " SS9S 5       rS rS r\" \R&                  S5      (       d  \rCS rSrg)
JSONReportr   zThe JSON report pytest plugin.c                     [         R                  " U /UQ70 UD6  S U l        [        5       U l        / U l        / U l        SU l        SU l        SU l	        S U l
        g )Nr    )r	   r   _start_timer   _json_tests_json_collectors_json_warnings_num_deselected_terminal_summary_terminal_min_verbosityrW   )r   argskwargss      r   r   JSONReport.__init__u   s[    6t6v6&= "  !#'($r   c                 8    [         R                   " 5       U l        g r   )timeru   )r   sessions     r   pytest_sessionstartJSONReport.pytest_sessionstart   s    99;r   c                    U R                  S5      (       a  g / nUR                   H0  n[        R                  " U5      nXCl        UR                  U5        M2     U R                  R                  [        R                  " UU5      5        g N
collectors)r   resultr   make_collectitem_json_collectitemr!   rw   make_collector)r   rW   json_resultr.   	json_items        r   pytest_collectreportJSONReport.pytest_collectreport   su    ??<((MMD!2248I%."y) " 	$$Y%=%=f>I&K 	Lr   c                     U =R                   [        U5      -  sl         U R                  S5      (       a  g U H  n SUR                  S'   M     g ! [         a     M%  f = f)Nr   T
deselected)ry   lenr   r   AttributeErrorr   itemsr.   s      r   pytest_deselectedJSONReport.pytest_deselected   s\    E
*??<((D7;&&|4 
 " s   A
AATr*   c              #   |   #    S v   U R                  S5      (       a  g U H  n U?M     g ! [         a     M  f = f7fr   )r   r   r   r   s      r   pytest_collection_modifyitems(JSONReport.pytest_collection_modifyitems   sB     ??<((D*  " s   !<+<
9<9<c                    [        US5      (       d  0 Ul        UR                  n U R                  U   nUR                  R                  S5      nU(       a  XCS'   UR                  S:X  a  [        USS 5      (       ap  UR                   VVs/ s H  u  pV[        U5      U0PM     nnn[
        R                   " U5      (       a  XsS'   O%["        R$                  " SR'                  U5      5        U R(                  R*                  R-                  XR(                  S9S   nUS	;  a  XS
'   U R(                  R*                  R/                  US9X1R                  '   g ! [         a_    [
        R                  " UU R                  S5      (       a  S O[        UR                  5      UR                  5      nX0R                  U'    GNf = fs  snnf )Nr-   keywordsrO   rH   user_propertiesz0User properties of {} are not JSON-serializable.)rW   r   r   )passedrt   outcome)rW   )r   r-   rc   rv   KeyErrorr   make_testitemr   listr   locationgetr8   getattrr   strr_   r`   ra   rb   r   rS   pytest_report_teststatuspytest_json_runtest_stage)	r   rW   rc   json_testitemrO   rY   rZ   r   r   s	            r   pytest_runtest_logreport#JSONReport.pytest_runtest_logreport   s    v344(*F%
	5 ,,V4M ,,00<(0*%;;*$9JD)Q)Q?E?U?UV?U83C#?UOV%%o663B/0PWWX^_` ,,##<<,, = 0013.('.)$LL77v7F 	kk"5  	5%33 
33foo9NM (5V$	5 Ws   E GA%G ?G )trylastc           	          UR                   R                  UR                  0 5      n[        R                  " UUR                  S5      UR                  S5      UR                  S5      U R                  S5      5      $ )NrM   rN   r3   r   )r-   r   r8   r   make_teststager   )r   rW   stage_detailss      r   r   $JSONReport.pytest_json_runtest_stage   sj    1155fkk2F''h'h'e$OOK(
 	
r   )tryfirstc                 2   SUR                   U R                  -   0nU R                  (       a  U R                  US'   [        R                  " [        R                  " 5       [        R                  " 5       U R
                  -
  UR                  [        UR                  5      [        U R                  S0 5      [        R                  " U R                  40 UD6S9nU R                  R                  R                  (       df  U R                  (       a  U R                  US'   [!        U R                  R#                  5       5      US'   U R$                  (       a  U R$                  US'   U R                  R&                  R)                  US9  X0l        U R                  R                  R,                  nU(       a)   U R/                  U5        S	R1                  U5      U l        g SU l        SU l        g ! [4         a   nS
R1                  U5      U l         S nAg S nAff = f)N	collectedr   	_metadata)createddurationexitcoderootenvironmentsummaryr   testsr`   )json_reportzreport saved to: {}zcould not save report: {}zreport auto-save skippedr   )testscollectedry   r   make_reportr   ru   
exitstatusr   fspathr   r   make_summaryrv   r   json_report_summaryrw   r   valuesrx   rS   pytest_json_modifyreportrW   json_report_filesave_reportrb   rz   OSErrorr{   )r   r   summary_datar   pathes         r   pytest_sessionfinishJSONReport.pytest_sessionfinish   s   
 //$2F2FF

 )-)=)=L&++IIKYY[4#3#33''W^^$k2>**4+;+;L|L
 ||""66$$,0,A,AL)#'(8(8(?(?(A#BK ""*.*=*=J'22{2K "||""33L  & *?)E)Ed)K&%?D"+,D(  O)D)K)KA)N&&Os   5G, ,
H6HHc                    U R                   c  [        S5      e[        R                  R	                  U5      nU(       a   [        R
                  " U5        [        USSS9 n[        R                  " U R                   U[        U R                  R                  R                  S9  SSS5        g! [         a)  nSSKnUR                  UR                  :w  a  e  SnANSnAff = f! , (       d  f       g= f)zGSave the JSON report to `path`.

Raises an exception if saving failed.
Nz*could not save report: no report availabler   wzutf-8)encoding)defaultindent)rW   	Exceptionosr   dirnamemakedirsr   errnoEEXISTopenjsondumpr   r   r   json_report_indent)r   r   r   r   r   fs         r   r   JSONReport.save_report  s    
 ;;HII''//$'G$ $g.!II||**==	 /.	  77ell* + /.s%    B. !AC$.
C!8CC!$
C2c                     U R                   c  g U R                  S5      (       d0  U R                  R                  [        R
                  " X5      5        g g )Nr`   )r   r   rx   r!   r   make_warning)r   warning_messager8   s      r   pytest_warning_recorded"JSONReport.pytest_warning_recorded  sG    << z**&&&&=? +r   r   c                    U R                   U R                  R                  R                  b   U R                  R                  R                  OUR                  :  a  g UR                  SS5        UR                  U R                  5        g )N-zJSON report)r{   r   r   json_report_verbosity	verbosity	write_sep
write_linerz   )r   terminalreporters     r   pytest_terminal_summary"JSONReport.pytest_terminal_summary(  sm    ''##99E ##99 **, ""36##D$:$:;r   )rw   rv   rx   ry   ru   r{   rz   rW   N)rg   rh   ri   rj   __doc__r   r   r   r   rk   rl   r   r   r   r   r   r   r   _pytesthookspecpytest_warning_capturedr   rn   ro   r   r   rq   rq   r   s    (
'	L
 __& '$GL __T"	
 #	
 __d#&- $&-P2? 7##%>??"9#<r   rq   c                       \ rS rSrSrg)JSONReportWorkeri2  ro   N)rg   rh   ri   rj   rn   ro   r   r   r   r   2  s    r   r   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )r4   i7  c                 0   > [         TU ]  5         / U l        g r   )superr   r7   )r   	__class__s    r   r   LoggingHandler.__init__9  s    r   c                     [        UR                  5      nUR                  5       US'   S US'   S US'   UR                  SS 5        U R                  R                  U5        g )Nmsgr|   exc_infomessage)dict__dict__
getMessagepopr7   r!   )r   recordds      r   emitLoggingHandler.emit=  sT    !$$&%&	*	iAr   )r7   )rg   rh   ri   rj   r   r   rn   __classcell__)r   s   @r   r4   r4   7  s     r   r4   c                   L    \ rS rSrS r\R                  " SS9S 5       rS rSr	g)	r&   iF  c                     g)z{Called after building JSON report and before saving it.

Plugins can use this hook to modify the report before it's saved.
Nro   )r   r   s     r   r   Hooks.pytest_json_modifyreportH      r   T)firstresultc                     g)a  Return a dict used as the JSON representation of `report` (the
`_pytest.runner.TestReport` of the current test stage).

Called from `pytest_runtest_logreport`. Plugins can use this hook to
overwrite how the result of a test stage run gets turned into JSON.
Nro   )r   rW   s     r   r   Hooks.pytest_json_runtest_stageN  r  r   c                     g)zReturn a dict which will be added to the current test item's JSON
metadata.

Called from `pytest_runtest_makereport`. Plugins can use this hook to
add metadata based on the current test run.
Nro   )r   r.   rD   s      r   rT   "Hooks.pytest_json_runtest_metadataW  r  r   ro   N)
rg   rh   ri   rj   r   rk   r   r   rT   rn   ro   r   r   r&   r&   F  s)     __& 'r   r&   c                      U R                   R                  R                  S0 5      $ ! [         a+    U R                  R
                  R                  (       d  0 s $ e f = f)z1Fixture to add metadata to the current test item.rO   )noder-   rU   r   r   r   r   )requests    r   json_metadatar  `  sP    ||..99*bII ~~$$00 Is   %( 1AAc                    U R                  SS5      nUR                  SSSSS9  UR                  SS	S
 SS9  UR                  S/ SSS9  UR                  SSSSS9  UR                  S[        SS9  UR                  S[        SS9  g )N
jsonreportzreporting test results as JSONz--json-reportF
store_truezcreate JSON report)r   actionhelpz--json-report-filez.report.jsonc                 2    U R                  5       S:X  a  S $ U $ )Nnone)lower)xs    r   <lambda>"pytest_addoption.<locals>.<lambda>v  s    qwwyF2t99r   zCtarget path to save JSON report (use "none" to not save the report))r   typer  z--json-report-omit+zklist of fields to omit in the report (choose from: collectors, log, traceback, streams, warnings, keywords))r   nargsr  z--json-report-summaryz.only create a summary without per-test detailsz--json-report-indentz2pretty-print JSON with specified indentation level)r  r  z--json-report-verbosityz/set verbosity (default is value of --verbosity))getgroup	addoptionint
_addoption)parsergroups     r   pytest_addoptionr$  n  s    OOL*JKE	OO|!  # 
OOn9	   
OOb ;'  ( 
OO #   
OOS 0&  ' 
! 3   !r   c                     U R                   R                  (       d  g [        U S5      (       a  [        nO[        nU" U 5      nX l        U R                  R                  U5        g )Nworkerinput)r   r   r   r   rq   r   r'   register)r   Pluginplugins      r   r"   r"     sL    ==$$v}%%!F^F 
!!&)r   c                 `    [        U SS 5      nUb  U ?U R                  R                  U5        g g )Nr   )r   r   r'   
unregister)r   r)  s     r   pytest_unconfigurer,    s5    V^T2F''/ r   )
__future__r   collectionsr   
contextlibr   r   r   r   r   r`   rk   _pytest.hookspecr   rt   r   r	   rq   r   Handlerr4   r&   fixturer  r$  r"   r,  ro   r   r   <module>r3     s    % # %   	     _; _;D}< }<@	~ 	
W__  4 
 
!6	*0r   