
    -c h4                         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Zd dl	m
Z
mZmZ  G d d      Z G d d      Z G d d	e      Z G d
 d      Z G d d      Z G d de      Z G d de      Zy)    N)unified_diff)codegen	termcolorutilsc                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	ViewNotifiernotify_c                     || _         y N)viewsselfr   s     /home/xtuchyna/.var/app/com.visualstudio.code/data/virtualenvs/gen-test-bench-v8TMe8KL/lib/python3.12/site-packages/mutpy/views.py__init__zViewNotifier.__init__   s	    
    c                 :    | j                   j                  |       y r   )r   appendr   s     r   add_viewzViewNotifier.add_view       

% r   c                 :    | j                   j                  |       y r   )r   remover   s     r   del_viewzViewNotifier.del_view   r   r   c                    t        dj                  t        |                   t        dj                  dj                  |D cg c]  }|j                  dz    c}                   t        dj                  t        |                   t        dj                  dj                  |D cg c]  }|j                  dz    c}                   y c c}w c c}w )NzPASSED: [{}]z{}, z
zFAILED: [{}])printformatlenjoinname)r   passedfailedtests       r   print_test_resultszViewNotifier.print_test_results   s    n##CK01fmmDIIf&Mfdtyy6'9f&MNOPn##CK01fmmDIIf&Mfdtyy6'9f&MNOP 'N&Ms   C*Cc                 h    | j                   D ]#  }t        ||      st        ||      } ||i | % y r   )r   hasattrgetattr)r   notifyargskwargsr   attrs         r   notify_all_viewszViewNotifier.notify_all_views!   s3    ZZEuf%uf-d%f%  r   c                      |j                  t        j                        r"|t        t        j                        d   fdS t	        |      )Nc                  0     j                   g| i |S r   )r+   )r(   r)   r'   r   s     r   <lambda>z*ViewNotifier.__getattr__.<locals>.<lambda>*   s    +@4+@+@+Y$+YRX+Yr   )
startswithr   PREFIXr   AttributeError)r   r   r'   s   ` @r   __getattr__zViewNotifier.__getattr__'   s>    ??<../#l11234FYY &&r   N)
__name__
__module____qualname__r0   r   r   r   r#   r+   r2    r   r   r   r      s&    F!!Q&'r   r   c                   <    e Zd ZddZd ZddZd	dZed
d       Zy)QuietTextViewc                     || _         y r   )colored_output)r   r:   s     r   r   zQuietTextView.__init__1   s
    ,r   c                     | j                  dj                  | j                  |      | j                  dj                  |j	                               ddg                   y )NzMutation score {}: {}z{:.1f}%blueboldattrs)level_printr   time_formatdecoratecount)r   scoredurations      r   endzQuietTextView.end4   sQ    077X&MM)**5;;=96&MR
 	r   c                     |rdnd}|rt        ||       y |dk(  r| j                  dd      }n|dk(  r| j                  dd	      }t        d
j                  |      |       y )N
 )rF      z[*]r<      z   -cyan{} {})r   rB   r   )r   msglevelendedcontinuationrF   prefixs          r   r@   zQuietTextView.level_print:   s[    d#3zuf5!vv6'..-37r   Nc                 N    | j                   rt        j                  ||||      S |S r   )r:   r   colored)r   textcoloron_colorr?   s        r   rB   zQuietTextView.decorateG   s'    $$T5(EBBKr   c                 *    | ydj                  |       S )Nz[    -    ]z
[{:.5f} s])r   times    r   rA   zQuietTextView.time_formatM   s    < &&t,,r   )F)rJ   TF)NNNr   )	r3   r4   r5   r   rF   r@   rB   staticmethodrA   r6   r   r   r8   r8   /   s*    -8 - -r   r8   c                        e Zd Zd fd	Zd Zd Zd Z fdZd Zd Z	d Z
d	 Zd
 Zd Zed        Zd Zd Zd Zd Z xZS )TextViewc                 2    t         |   |       || _        y r   )superr   show_mutants)r   r:   r`   	__class__s      r   r   zTextView.__init__W   s    ((r   c                     | j                  d       | j                  dj                  dj                  |            d       | j                  dj                  dj                  |            d       y )NzStart mutation process:ztargets: {}r   rK   z	tests: {})r@   r   r   )r   targetstestss      r   
initializezTextView.initialize[   sY    23--dii.@A1E++DIIe,<=qAr   c                 &    | j                  d       y )Nz'Start mutants generation and execution:)r@   r   s    r   startzTextView.start`   s    BCr   c                    | j                  dd       |j                  j                         D ]C  \  }}t        |      }||j                  z  dz  }| j                  dj                  ||             E | j                  dd       | j                  dj                  |j                         dz               | j                  dj                  |j                         dz               y )Nz=== Per test metrics ===rK   d   z per test score: ({:.1f}%) for {}zD=== Realtive Average Percentage of Faults Detected (RAPFD) SCORE ===z'RAPFD score (original order): ({:.1f}%)z%RAPFD score (random order): ({:.1f}%))r@   killer_matrixitemsr   all_mutantsr   get_rapfd_scoreget_random_rapfd_score)r   rD   	test_namekilled_operators
kill_countper_test_scores         r   custom_printzTextView.custom_printc   s     	3Q7+0+>+>+D+D+F'I'-.J'%*;*;;cAN?FF~W`ab ,G 	_abcBII%J_J_JadgJghi@GGHdHdHfilHlmnr   c                    t         |   ||       | j                  dj                  |j                        d       |j                  r| j                  dj                  |j
                  d|j
                  z  |j                  z        d       | j                  dj                  |j                  d|j                  z  |j                  z        d       | j                  dj                  |j                  d|j                  z  |j                  z        d       | j                  dj                  |j                  d|j                  z  |j                  z        d       | j                  |       |j                  rQ| j                  dj                  |j                  |j                  d|j                  z  |j                  z               y y y )	Nzall: {}rK   zkilled: {} ({:.1f}%)rj   zsurvived: {} ({:.1f}%)zincompetent: {} ({:.1f}%)ztimeout: {} ({:.1f}%)z&Coverage: {} of {} AST nodes ({:.1f}%))r_   rF   r@   r   rm   killed_mutantssurvived_mutantsincompetent_mutantstimeout_mutantsrt   	all_nodescovered_nodes)r   rD   rE   ra   s      r   rF   zTextView.endy   s   E8$))%*;*;<a@3::5;O;O;>AUAU;UX]XiXi;iklmo5<<U=S=S=@5CYCY=Y\a\m\m=mopqs8??@Y@Y@CeF_F_@_bgbsbs@suvwy4;;E<Q<Q<?%BWBW<WZ_ZkZk<kmnoqe$  !I!P!P''%---?"   r   c           	          | j                  dj                  |             |D ]N  \  }}}}|j                  |rd|z   ndz   }| j                  dj                  || j                  |            d       P y )Nz{} tests passed:.rI   rM   rK   )r@   r   r3   rA   )r   rd   number_of_testsr"   resulttargetrZ   rp   s           r   r    zTextView.passed   sl    +22?CD*/&D&&$vRHIW^^It7G7G7MNPQR +0r   c                 N   | j                  | j                  dddg             |j                  D ]8  }| j                  dj                  |j                  |j
                        d       : |j                         r*| j                  t        |j                               d       y y )NzTests failed:redr=   r>   zfail in {} - {}rK   )	r@   rB   r!   r   r   short_messageis_incompetentstrget_exception)r   r   fails      r   original_tests_failzTextView.original_tests_fail   s    fXNOMMD.55diiASASTVWX "  "S!5!5!78!< #r   c           	      N   |D ]  }| j                  dj                  ||j                  j                         |j                        dd       ||d   k7  r
t                | j                  si| j                  |t        j                  t        j                  |                    y )Nz[#{:>4}] {:<3} {}: FrK   )rP   rO   )r@   r   operatorr   r3   r   r`   
print_codeastparseinspect	getsourcer   number	mutationsmodulemutantmutations         r   r   zTextView.mutation   s    !H%,,VX5F5F5K5K5Mv_  
 9R=(  		'2C2CF2K(LM "r   c                     | j                  | j                  dddg      dj                  ||j                  j                  |      z          y )NzCan't load module: r   r=   r>   z{} ({}: {}))r@   rB   r   ra   r3   )r   r   	exceptions      r   	cant_loadzTextView.cant_load   s`    '=uVHUXeXlXlmqmv  nA  nA  nJ  nJmvYx x 	yr   c                     t        j                  |      }t        j                  |      }t        j                  |      }t        j                  |      }| j                  ||       y r   )r   	to_sourceadd_line_numbers_print_diff)r   r   original
mutant_srcoriginal_srcs        r   r   zTextView.print_code   sR    &&v.
--j9
((2//=\2r   c                    | j                  ||      }|D cg c]  }|j                  d      r| }}|D cg c]'  }|j                  d      r| j                  |d      n|) }}|D cg c]'  }|j                  d      r| j                  |d      n|) }}t        dj	                  d      dj                  |      z   d	j	                  d      z          y c c}w c c}w c c}w )
N)z---z+++z@@z- r<   z+ greenz
{}
zP--------------------------------------------------------------------------------rH   z
{})_create_diffr/   rB   r   r   r   )r   r   r   difflines        r   r   zTextView._print_diff   s      \:!%ST__=Q-RS[_`[_SWtt/DdF+$N[_`\`a\`TX0EdG,4O\`ahooh'$))D/9FMM(<SST T`as   CC,C*,C!c                 n    t        t        |j                  d      | j                  d      dd            S )NrH      rI   )nlineterm)listr   split)r   r   s     r   r   zTextView._create_diff   s0    L!3!3D!9:;K;KD;QUVacdeer   c                     | j                  | j                  |      dz   | j                  dd      z   dz   t        |      z   d       y )N killedr   z by TrQ   )r@   rA   rB   r   )r   rZ   killerr(   r)   s        r   r   zTextView.killed   sM    ))$/#5hPW8XX[aadghndoo&* 	 	,r   c                 t    | j                  | j                  |      dz   | j                  dd      z   d       y )Nr   survivedr   Tr   r@   rA   rB   r   rZ   r(   r)   s       r   r   zTextView.survived   s7    ))$/#5jRW8XXgklr   c                 t    | j                  | j                  |      dz   | j                  dd      z   d       y )Nr   timeoutyellowTr   r   r   s       r   r   zTextView.timeout   s7    ))$/#5iQY8ZZimnr   c                 t    | j                  | j                  |      dz   | j                  dd      z   d       y )Nr   incompetentrL   Tr   r   r   s       r   r   zTextView.incompetent   s7    ))$/#5mU[8\\kopr   )FF)r3   r4   r5   r   re   rh   rt   rF   r    r   r   r   r   r   r[   r   r   r   r   r   __classcell__ra   s   @r   r]   r]   U   sn    )B
Do,*S=
Ny
3U f f,moqr   r]   c                       e Zd Zd Zd Zd Zy)	DebugViewc           
      h    t        ddj                  t        j                  d |d             z          y )NrH   rI   )r   r   	tracebackformat_exception)r   r   s     r   print_exceptionzDebugView.print_exception   s'    dRWWY77iNOOPr   c                 &    | j                  |       y r   )r   r   rZ   r   	tests_runr(   r)   s         r   r   zDebugView.incompetent   s    Y'r   c                      t        d|z          y )NrH   )r   )r   rZ   r   exception_tracebackr(   r)   s         r   r   zDebugView.killed   s    d(()r   N)r3   r4   r5   r   r   r   r6   r   r   r   r      s    Q(*r   r   c                   D    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
dd
Zy	)AccReportViewc                     g | _         y r   )mutation_inforg   s    r   r   zAccReportView.__init__   s
    r   c                     || _         y r   )r   )r   r   rd   s      r   re   zAccReportView.initialize   s	    r   c                      || _         || _        y r   )rd   r~   )r   rd   r~   s      r   r    zAccReportView.passed   s    
.r   c                     |D cg c]3  }|j                   j                         |j                  j                  d5 }}|||d| _        y c c}w )N)r   lineno)r   r   r   )r   r   noder   current_mutationr   s         r   r   zAccReportView.mutation   sP    luvlu`h("3"3"8"8":hmmFZFZ[lu	v"!
 ws   8Ac                 B    | j                  d|t        |      ||       y )Nr   )rZ   r   r   r   )end_mutationr   )r   rZ   r   r   r   r(   r)   s          r   r   zAccReportView.killed   s(    v; 3 	 	
r   c                 ,    | j                  d||       y )Nr   rZ   r   r   )r   rZ   r   r(   r)   s        r   r   zAccReportView.survived   s    *49Er   c                 ,    | j                  d||       y )Nr   r   r   r   s         r   r   zAccReportView.incompetent   s    -diHr   c                 *    | j                  d|       y )Nr   rY   r   r   s       r   r   zAccReportView.timeout   s    )$/r   Nc                     || j                   d<   || j                   d<   || j                   d<   || j                   d<   || j                   d<   | j                  j                  | j                          y )NstatusrZ   r   r   r   )r   r   r   )r   r   rZ   r   r   r   s         r   r   zAccReportView.end_mutation  sm    *0h'(,f%*0h'-6k*7J34!!$"7"78r   )NNNN)r3   r4   r5   r   re   r    r   r   r   r   r   r   r6   r   r   r   r      s1     /

FI09r   r   c                   $     e Zd Z fdZd Z xZS )YAMLReportViewc                 0    t         |           || _        y r   )r_   r   	file_name)r   r   ra   s     r   r   zYAMLReportView.__init__  s    "r   c                    t        | j                  d      5 }t        j                  | j                  | j
                  D cg c]  \  }}}}|j                  ||d c}}}}| j                  | j                  |t        t        j                  j                        |j                         |j                  |j                  dd|d       d d d        y c c}}}}w # 1 sw Y   y xY w)Nw)r   r   rZ   )r{   rz   )rc   rd   r~   r   
total_time
time_statsmutation_scorecoverageF)default_flow_style)openr   yamldumpr   rd   r3   r~   r   dictr   TimeRegister
executionsrC   r{   rz   )r   rD   rE   report_filer"   _r   rZ   s           r   rF   zYAMLReportView.end  s    $..#&+II;;osoyoyzoyVkVZ\]_egk4==FDQoyz#'#7#7!//&"5#5#5#@#@A"'++-%*%8%8!& u6 '& {	 '&s   ,CCA/CCC()r3   r4   r5   r   rF   r   r   s   @r   r   r   
  s    #6r   r   c                   8     e Zd Z fdZ fdZ fdZd Z xZS )HTMLReportViewc                    t         |           || _        t        j                  |d       t        j                  t        j
                  j                  |d      d       t        j
                  j                  t        j
                  j                  t              d      }t        j                  t        j                  |            | _        y )NT)exist_okmutants	templates)
searchpath)loader)r_   r   dir_nameosmakedirspathr   dirname__file__jinja2EnvironmentFileSystemLoaderenv)r   r   templates_pathra   s      r   r   zHTMLReportView.__init__$  s     
Ht,
BGGLL95Ebggooh&?M%%V-D-DP^-_`r   c                 H    t         |   ||||       || j                  d<   y )Nr   )r_   r   r   )r   r   r   r   r   ra   s        r   r   zHTMLReportView.mutation,  s&    FF;*0h'r   c                    t        |   |i | | j                  j                  d      }dt	        j
                  | j                  d         i}|j                  | j                         |j                  |      }t        j                  j                  | j                  ddj                  | j                  d               }t        |d      5 }|j                  |       d d d        y # 1 sw Y   y xY w)Nzdetail.htmlmutant_coder   r   z{}.htmlr   r   )r_   r   r   get_templater   r   r   updaterenderr   r   r   r   r   r   write)	r   r(   r)   templatecontextreport	file_pathr   ra   s	           r   r   zHTMLReportView.end_mutation0  s    d-f-88((77,,T-B-B8-LM
 	t,,-)GGLL	9;K;KDLaLabjLk;lm	)S![f% "!!s   C**C3c                    | j                   j                  d      }| j                  | j                  | j                  ||| j
                  t        j                  j                         d}|j                  |      }t        j                  j                  | j                  d      }t        |d      5 }|j                  |       d d d        y # 1 sw Y   y xY w)Nz
index.html)rc   rd   r~   rD   rE   r   date_nowr   )r   r  r   rd   r~   r   datetimenowr  r   r   r   r   r   r  )r   rD   rE   r  r  r	  r
  r   s           r   rF   zHTMLReportView.end<  s    88((6{{ZZ#33 ++ ))--/
 )GGLL=	)S![f% "!!s   1CC)r3   r4   r5   r   r   r   rF   r   r   s   @r   r   r   "  s    a1
&&r   r   )r   r  r   r   r   difflibr   r   r   mutpyr   r   r   r   r8   r]   r   r   r   r   r6   r   r   <module>r     sw    
   	      + +' 'B#- #-Lwq} wqt	* 	*,9 ,9^6] 60(&] (&r   