
    L-PhA                        d 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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 e
rd	dlmZ  ej        dej                  Zd Zd Zd Z G d dej                   Z!d Z"d Z# ej$        d          d             Z% G d d          Z& G d d          Z'ej(        d             Z)ej(        d              Z*d! Z+dS )"zCoverage plugin for pytest.    N)StringIO)Path)TYPE_CHECKING)CoverageWarning)display_covered)should_fail_under   )CovDisabledWarning)CovReportWarning)PytestCovWarning)compat)embed)CovController2unclosed database in <sqlite3.Connection object atc                    g d}ddg}dg}||z   }|                      dd          }|d         }|g |dvrd	|  d
| d}t          j        |          |dk    r$t          j        dk    rt          j        d          t          |          dk    r|d fS |d         }||v r||v r||fS ||vrd|  d
| d}t          j        |          |S )N)annotatehtmlxmljsonlcovtermzterm-missingzskip-covered:r	   r    zinvalid choice: "z" (choose from "z")r   )      z5LCOV output is only supported with coverage.py >= 6.3z%output specifier not supported for: ")splitargparseArgumentTypeErrorcoverageversion_infolen)	argfile_choicesterm_choicesterm_modifier_choicesall_choicesvaluesreport_typemsgreport_modifiers	            Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pytest_cov/plugin.pyvalidate_reportr,      s.   >>>LN+L+,-KYYsAF)K,K,,,,F#FF{FFF(---f!6&!@!@()`aaa
6{{aD  QiOl"":O'O'OO++,&&[c[[<[[[(---M    c                     	 t          |           }nD# t          $ r7 	 t          |           }n## t          $ r t          j        d          d w xY wY nw xY w|dk    rt          j        d          |S )Nz&An integer or float value is required.d   z|Your desire for over-achievement is admirable but misplaced. The maximum value is 100. Perhaps write more integration tests?)int
ValueErrorfloatr   r   )num_strvalues     r+   validate_fail_underr5   9   s    aG a a a	a'NNEE 	a 	a 	a,-UVV\``	a Ea
 s{{( K
 
 	
 Ls#    
A-A AAAc                     t           j        dk    rt          j        d          | dk    rt          j        d          | S )N)   r   z3Contexts are only supported with coverage.py >= 5.xtestz#The only supported value is "test".)r   r    r   r   )r"   s    r+   validate_contextr9   H   sB    &&()^___
f}}()NOOOJr-   c                       e Zd ZddZdS )StoreReportNc                 $    |\  }}||j         |<   d S N)
cov_report)selfparser	namespacer'   option_stringr(   files          r+   __call__zStoreReport.__call__Q   s    "T,0	[)))r-   r=   )__name__
__module____qualname__rD    r-   r+   r;   r;   P   s(        1 1 1 1 1 1r-   r;   c           
         |                      dd          }|                    ddg ddddd	
           |                    ddg dd           |                    dt          i dt          d           |                    ddddd           |                    dddd           |                    dddd           |                    d dd!t          d"#           |                    d$ddd%           |                    d&dd'd(           |                    d)t
          d'd*+           |                    d,dd-t          d.#           d'S )/z Add options to control coverage.covz3coverage reporting with distributed testing support--covappendSOURCE?T
cov_sourcezPath or package name to measure during execution (multi-allowed). Use --cov= to not do any source filtering and record everything.)actiondefaultmetavarnargsconstdesthelpz--cov-resetstore_constz1Reset cov sources accumulated in options so far. )rP   rT   rU   rV   z--cov-reportTYPEa-  Type of report to generate: term, term-missing, annotate, html, xml, json, lcov (multi-allowed). term, term-missing may be followed by ":skip-covered". annotate, html, xml, json and lcov may be followed by ":DEST" where DEST specifies the output location. Use --cov-report= to not generate any output.)rP   rQ   rR   typerV   z--cov-configstorez.coveragercPATHz.Config file for coverage. Default: .coveragerc)rP   rQ   rR   rV   z--no-cov-on-fail
store_trueFz8Do not report coverage if test run fails. Default: False)rP   rQ   rV   --no-covzIDisable coverage report completely (useful for debuggers). Default: Falsez--cov-fail-underMINz,Fail if the total coverage is less than MIN.)rP   rR   rY   rV   z--cov-appendz<Do not delete coverage but append to current. Default: Falsez--cov-branchNzEnable branch coverage.z--cov-precisionz!Override the reporting precision.)rY   rQ   rV   z--cov-contextCONTEXTz(Dynamic contexts to use. "test" for now.)getgroup	addoptionr;   r,   r5   r0   r9   )r@   groups     r+   pytest_addoptionrc   V   s    OOE#XYYE	OOK  
 
 
 
OO@     
OO8     
OO=     
OOG	     
OOX	     
OO ;     
OOK	     
OO&	     
OO0	     
OO7      r-   c                 &    d| v rdnd | D             S )z
    Prepare cov_source so that:

     --cov --cov=foobar is equivalent to --cov (cov_source=None)
     --cov=foo --cov=bar is equivalent to cov_source=['foo', 'bar']
    TNc                     g | ]}|d u|	S )TrH   ).0paths     r+   
<listcomp>z'_prepare_cov_source.<locals>.<listcomp>   s#    +\+\+\T4W[K[K[DK[K[K[r-   rH   )rO   s    r+   _prepare_cov_sourceri      s'     :%%44+\+\Z+\+\+\\r-   T)tryfirstc                    | j         }dx}|_        |D ]:}t          |          }|dk    rd}|                    d          r|r	d|_         n;| j         j        r2t          || j                  }| j                            |d           d S d S )NFr]   TrK   _cov)known_args_namespaceno_cov_should_warnstr
startswithrO   	CovPluginpluginmanagerregister)early_configr@   argsoptionsno_covr"   plugins          r+   pytest_load_initial_conftestsry      s    /G*//FW'  #hh*FF^^G$$ 	 	)-G&E(3 <7L$>??"++FF;;;;;< <r-   c                   >   e Zd ZdZddej        fdZdded         fd	Zd
 Z	d Z
 ej        d          d             Z ej        d          d             Zd Z ej        d          d             Zd Zd Zd Zd Z ej        d          d             ZdS )rq   zUse coverage package to produce code coverage reports.

    Delegates all work to a particular implementation based on whether
    this test process is centralised, a distributed master or a
    distributed worker.
    TFrv   c                    d| _         d| _        t                      | _        d| _        d| _        d| _        d| _        d| _        || _	        d| _
        t          |dd          p%t          |dd          pt          |dd          dk    }t          |dd          r	d| _        dS | j	        j        sd	g| j	        _        n7t          | j	        j                  d
k    rd| j	        j        v ri | j	        _        t          | j	        j                  | j	        _        d
dlm} |r|r|                     |j                   dS |r|                     |j                   dS dS )zCreates a coverage pytest plugin.

        We read the rc file that coverage uses to get the data file
        name.  This is needed since we give coverage through it's API
        the data file name.
        NFnumprocessesdistloaddistnorw   Tr   r	   r   engine)pidcov_controllerr   r>   	cov_totalfailed_started_start_path	_disabledrv   _wrote_headinggetattrr!   ri   rO   r   r   start
DistMasterCentral)r?   rv   rr   r   rn   is_distr   s          r+   __init__zCovPlugin.__init__   s    ""**#'>599  KWWjZ_=`=`  Kdklsu{  ~B  eC  eC  GK  eK7He,, 	!DNF|& 	)'-hDL##())Q..29P3P3P&(DL#"5dl6M"N"N 	 	'u 	'JJv())))) 	'JJv~&&&&&	' 	'r-   Ncontroller_clsr   c                     | G  fdd          } |            } | j         ||           _         j                                         d _        t	          j                     _         j        j        j        } j         j	        !t          |d          r|j         j         _	         j         j        t          |dd           j         _        d S d S )Nc                       e Zd Z j        ZdS )CovPlugin.start.<locals>.ConfigN)rE   rF   rG   rv   option)r?   s   r+   Configr      s        r-   r   T
fail_under	precisionr   )rv   r   r   r   r   cwdr   rJ   configcov_fail_underhasattrr   cov_precisionr   )r?   r   r   nodeidr   
cov_configs   `     r+   r   zCovPlugin.start   s    >& & & & & & & & & & VXXF,nT\66JJ!!###8::(,3
<&.7:|3T3T.*4*?DL'<%-)0[!)L)LDL&&& .-r-   c                 2    t          |j        dd           d uS )Nworkerinput)r   r   )r?   sessions     r+   
_is_workerzCovPlugin._is_worker  s    w~}d;;4GGr-   c                    | j         j        r	d| _        dS ddlm} t          j                    | _        |                     |          rG|j	        j
                            d|j                  }|                     |j        |j	        |           n!| j        s|                     |j                   | j         j        dk    r4|j	        j                            t)          | j                  d           dS dS )zAAt session start determine our implementation and delegate to it.TNr	   r   workeridr8   _cov_contexts)rv   rw   r   r   r   osgetpidr   r   r   r   getr   r   
DistWorkerr   r   cov_contextrr   rs   TestContextPluginr   )r?   r   r   r   s       r+   pytest_sessionstartzCovPlugin.pytest_sessionstart  s     < 	!DNF 	9;;??7## 	'^/33JOOFJJv('.&AAAA 	'JJv~&&&<#v--N(112CDDW2X2XZijjjjj .-r-   )optionalhookc                 L    | j         s| j                            |           dS dS zlDelegate to our implementation.

        Mark this hook as optional in case xdist is not installed.
        N)r   r   configure_node)r?   nodes     r+   pytest_configure_nodezCovPlugin.pytest_configure_node&  s5     ~ 	5..t44444	5 	5r-   c                 N    | j         s| j                            ||           dS dS r   )r   r   testnodedown)r?   r   errors      r+   pytest_testnodedownzCovPlugin.pytest_testnodedown/  s7     ~ 	:,,T599999	: 	:r-   c                 ^    | j         j        p| j         j        }|o| j        o| j         j         S r=   )rv   r>   r   r   no_cov_on_fail)r?   neededs     r+   _should_reportzCovPlugin._should_report8  s0    (GDL,GKt{Jt|/JKKr-   )wrapperc              #   `  K   | j         rd V S t          j        D ]\  }}}}}|t          u r|t          k    r nt          j        ddt                     t          j        D ]\  }}}}}|t          u r nt          j        dt                     t          j        D ]\  }}}}}|t          u r nt          j        dt                     d V }t          j
        |          }t          |j                  | _        | j        | j                                         |                     |          s|                                 rjddlm} 	 | j                            | j                  | _        n{# |$ rs}d| d}|j        j                            d                              d	| dd
d
           t          j        t9          |          d           d| _        Y d }~nd }~ww xY w| j        
J d            | j        j        }	| j        j        }
|	| j        j         rd S tC          | j        |	|
          rtd"                    tG          | j        |
          |	|
          }|j        j                            d                              d| dd
d
           |xj        dz  c_        |S )NrQ   r   oncer   )CoverageExceptionzFailed to generate report: 
terminalreporterz

WARNING: Tredboldr	   
stacklevelz$Test coverage should never be `None`zMCoverage failure: total of {total} is less than fail-under={fail_under:.{p}f})totalr   pz
ERROR: )$r   warningsfiltersResourceWarningCOVERAGE_SQLITE_WARNING_REfilterwarningsr   simplefilterr   r   SessionWrapperbooltestsfailedr   r   finishr   r   coverage.miscr   summaryr>   r   r   rr   	getpluginwritewarnr   rv   r   r   collectonlyr   formatr   )r?   r   _messagecategoryresultcompat_sessionr   excr   r   s              r+   pytest_runtestloopzCovPlugin.pytest_runtestloop>  s(     > 	EEN +3*: 	v 	v&Aw!Q?**w:T/T/T#I/cetuuu$,$4 	< 	< Aq(Aq+++ , !&*:;;;$,$4 	; 	; Aq(Aq?** + !&/:::.w77>566*&&(((w'' 	0D,?,?,A,A 	0 877777#!%!4!<!<T_!M!M$ # # #????,667IJJPPQj_fQjQjQjpt{P  A  A  A.w77AFFFF!"	#
 >--/U---!\8N L6M%)A% OO 0ipp)$.-HH-# q  
 ,667IJJPPQh]dQhQhQhnry}P~~~**a/**s   $E0 0G(5A)G##G(c                 R    | j         s|                    dd           d| _         d S d S )N=ztests coverageT)r   	write_sep)r?   r   s     r+   write_headingzCovPlugin.write_headingy  s<    " 	'&&s,<==="&D	' 	'r-   c                    | j         rd| j        j        rV|                     |           d}|                    d| ddd           t          j        t          |          d           d S | j        d S | j	        d S | j
                                        }|r*|                     |           |                    |           | j        j        | j        j        dk    rw|                     |           | j	        | j        j        k     }|rdddnd	di}d
                    | j        j        | j	        |rdnd|rdnd          } |j        |fi | d S d S d S )Nz&Coverage disabled via --no-cov switch!z	WARNING: r   Tr   r	   r   r   greenzU{fail}Required test coverage of {required}% {reached}. Total coverage: {actual:.2f}%
zFAIL r   znot reachedreached)requiredactualfailr   )r   rv   rn   r   r   r   r   r
   r   r   r>   getvaluer   r   )r?   r   r   reportr   markups         r+   pytest_terminal_summaryz!CovPlugin.pytest_terminal_summary~  s   > 	|. I""#3444B &&'>7'>'>'>Dt&TTT099aHHHHF&F>!F))++ 	+/000""6***<&2t|7RUV7V7V/000^dl&AAF4:OT4000$Fnuu4~ &.WWB)/>Y	 v  G #"755f55555 327V7Vr-   c                 h    t          j                    | j        k    rt          j                     d S d S r=   )r   r   r   r   initr?   items     r+   pytest_runtest_setupzCovPlugin.pytest_runtest_setup  s.    9;;$("" JLLLLL #"r-   c                 ,    t          j                     d S r=   )r   cleanupr   s     r+   pytest_runtest_teardownz!CovPlugin.pytest_runtest_teardown  s    r-   )hookwrapperc              #      K   |                     d          sdt          |dd          v r8| j                                         d V  | j                                         d S d V  d S )Nno_coverfixturenamesrH   )get_closest_markerr   r   pauseresumer   s     r+   pytest_runtest_callzCovPlugin.pytest_runtest_call  sy      "":.. 	*n^`@a@a2a2a%%'''EEE&&(((((EEEEEr-   )TF)NN)rE   rF   rG   __doc__r   	Namespacer   rY   r   r   r   pytesthookimplr   r   r   r   r   r   r   r   r   rH   r-   r+   rq   rq      s        &' &' 2 &' &' &' &'TM MD$9 M M M M$H H Hk k k, V_$'''5 5 ('5 V_$''': : (':L L L V_T"""8 8 #"8t' ' '
6 6 6B     V_&&&  '&  r-   rq   c                   8    e Zd ZU ded<   d Zd Zd Zd Zd ZdS )	r   r   r   c                     || _         d S r=   )r   )r?   r   s     r+   r   zTestContextPlugin.__init__  s    ,r-   c                 2    |                      |d           d S )Nsetupswitch_contextr   s     r+   r   z&TestContextPlugin.pytest_runtest_setup  s    D'*****r-   c                 2    |                      |d           d S )Nteardownr  r   s     r+   r   z)TestContextPlugin.pytest_runtest_teardown  s    D*-----r-   c                 2    |                      |d           d S )Nrunr  r   s     r+   r   z%TestContextPlugin.pytest_runtest_call  s    D%(((((r-   c                     | j         j        r<|j         d| }| j         j                            |           |t
          j        d<   d S d S )N|COV_CORE_CONTEXT)r   startedr   rJ   r  r   environ)r?   r   whencontexts       r+   r  z TestContextPlugin.switch_context  s\    & 	5--t--G#227;;;-4BJ)***	5 	5r-   N)	rE   rF   rG   __annotations__r   r   r   r   r  rH   r-   r+   r   r     sm         ####- - -+ + +. . .) ) )5 5 5 5 5r-   r   c                      dS )z%A pytest fixture to disable coverage.NrH   rH   r-   r+   r   r     s      r-   c                     | j         j                            d          r2| j         j                            d          }|j        r|j        j        S dS )zEA pytest fixture to provide access to the underlying coverage object.rl   N)r   rr   	haspluginr   r   rJ   )requestrx   s     r+   rJ   rJ     sS    
 ~#--f55 --77??  	-(,,4r-   c                 2    |                      dd           d S )Nmarkersz)no_cover: disable coverage for this test.)addinivalue_line)r   s    r+   pytest_configurer    s    
I'RSSSSSr-   ),r   r   r   rer   ior   pathlibr   typingr   r   r   coverage.exceptionsr   coverage.resultsr   r   r   r
   r   r   r   r   r   r   compileIr   r,   r5   r9   Actionr;   rc   ri   r  ry   rq   r   fixturer   rJ   r  rH   r-   r+   <module>r&     s   ! !  				 				                            / / / / / / , , , , , , . . . . . .                                     &%%%%%%'RZ(\^`^bcc   8    1 1 1 1 1(/ 1 1 1U U Up] ] ] $< <  < f f f f f f f fR5 5 5 5 5 5 5 5, 0 0 0   T T T T Tr-   