a
    7ñ»jØE  ã                   @   s¤   d Z 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m	Z	 ddl
mZ dd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedkr edƒ dS )a™  
Launches the SeleniumBase Case Plans Generator.

Usage:
      seleniumbase caseplans [OPTIONAL PATH or TEST FILE]
             sbase caseplans [OPTIONAL PATH or TEST FILE]

Examples:
      sbase caseplans
      sbase caseplans -k agent
      sbase caseplans -m marker2
      sbase caseplans test_suite.py
      sbase caseplans offline_examples/

Output:
      Launches the SeleniumBase Case Plans Generator.
é    N)Úshared_utils)Ú
messagebox)ÚScrolledTextc                 C   sš   d}d}d}d}d}d}d}| rˆt jjt jj }t jjt jj }t jjt jj }t jjt jj }t jjt jj }t jjt jj }t j	j
}|||||||fS )NÚ )ÚcoloramaZForeZBLUEZBackZLIGHTCYAN_EXZLIGHTGREEN_EXZREDZLIGHTYELLOW_EXZBLACKÚStyleZ	RESET_ALL)Ú
use_colorsÚc0Úc1Úc2Úc3Úc4Úc5Úcr© r   úOE:\soccer\ml_env\Lib\site-packages\seleniumbase/console_scripts/sb_caseplans.pyÚ
set_colors   s     r   c                 C   s(   |   ¡  |  dd¡ |  | jdd¡ d S )Nz-topmostTF)ZliftÚ
attributesZ
after_idle)Úrootr   r   r   Úsend_window_to_front/   s    r   c                   C   s   t  dd¡ d S )NzNo existing Case Plans found!z@
No existing Case Plans found!!

Create some boilerplates first!)r   Úshowwarningr   r   r   r   Úshow_no_case_plans_warning5   s    þr   c                 C   s   |   dd¡  dd¡  dd¡S )z8The id used in various places such as the test log path.z.py::Ú.ú::ú Ú_)Úreplace)Z
display_idr   r   r   Úget_test_id<   s    ÿr   c                 C   sv  t |ƒ}d}|D ]}||  ¡ r|d7 }qg }g }	|dkrRt dd¡ t| ƒ d S ||krp|D ]}
| |
¡ q^n(t|ƒD ]\}}
||  ¡ rx| |
¡ qx|D ]}||v rœ||vrœ|	 |¡ qœd}|	D �]^}| d¡}d }d }t |ƒdkrð|d }t |ƒdk�r|d }d |dd… ¡}t	|ƒ}|d }d }t |ƒdk�rXd}t
j |¡�s~t
 |¡ n&t
j |d¡}t
j |¡�s~t
 |¡ g }| d	| ¡ | d
¡ | d¡ | d¡ | d¡ | d¡ | d¡ |}t
j ||¡}t
j |¡sÄt|ddd�}| d |¡¡ | ¡  |d7 }td| ƒ qÄ|dk�rBt dd| ¡ n(|dk�r^t dd| ¡ nt dd¡ t| ƒ d S )Nr   é   zNo tests were selected!u<   
â„¹ï¸� No tests were selected!
Select tests for Case Plans!ú/éÿÿÿÿú.mdÚ
case_plansú``%s``z---z*| # | Step Description | Expected Result |z*| - | ---------------- | --------------- |ú*| 1 | Perform Action 1 | Verify Action 1 |z*| 2 | Perform Action 2 | Verify Action 2 |r   úw+úutf-8©ÚmodeÚencodingú
z
Created %szA new Case Plan was generated!u0   
âœ… %s new boilerplate Case Plan was generated!é   zNew Case Plans were generated!u2   
âœ… %s new boilerplate Case Plans were generated!z!No new Case Plans were generated!uX   
â„¹ï¸� No new boilerplates were generated!

The selected tests already have Case Plans!)ÚlenÚgetr   r   r   ÚappendÚ	enumerateÚsplitÚjoinr   ÚosÚpathÚexistsÚmakedirsÚopenÚ
writelinesÚcloseÚprintÚshowinfo)r   ÚtestsZselected_testsÚtests_with_case_planÚtests_without_case_planZtotal_testsZtotal_selected_testsZselected_testZ
test_casesZcase_plans_to_createÚtestZtest_numberZ	test_caseZ	new_plansZ	case_planÚpartsÚtest_addressÚfolder_pathÚtest_idÚcase_idZfull_folder_pathÚdataÚ	file_nameÚ	file_pathÚout_filer   r   r   Úgenerate_case_plan_boilerplatesC   sš    
þÿþ









þ
þþrH   c           #      C   s@  g }i }g }t |ƒD ]è\}}| |¡ | ¡  d¡}d }d }	t|ƒdkrT|d }d}	t|ƒdkrz|d }d |dd… ¡}	t|ƒ}
|
d }d }t|ƒdkrªtj d|¡}ntj |	d|¡}tj 	|¡rt
|dd	�}| ¡ }| ¡  | |¡ ||t|ƒd < qg }t|ƒdk�rl| d
¡ | d¡ | d¡ | d¡ | d¡ | d¡ | d¡ | d¡ | d¡ ntƒ  t| ƒ d S | d¡ | d¡ | d¡ g }d}d}d}t |ƒD �]ô\}}d}d}d|v �rÔd}| d¡dk �sô| d¡dk �rüd}d}| d¡}t|ƒdk�r(|�s(|d }| ¡ }| d¡�rB| d¡�s`d|||   }| d|¡ nd|||   }||d< | dd ¡ d!| |d"d#…  d$ |d< |d"  ¡  d¡�rÒ|d"  ¡  d¡�rÒd|d"< n|d"  ¡ dk�rð| d"d¡ |d  ¡ dk�r| d¡ | d%¡ | d& |¡¡ n<d}g }|||  }d'||f }| d|¡ | d& |¡¡ | d¡ |dk�r‚|d7 }n&|dk�r–|d7 }n|dk�r´|d7 }�q´d(| }|dk�rÂd)}d*| }|dk�rØd+}d,| }|dk�rîd-}d. | d.¡dd … ¡}d. | d.¡dd … ¡}d. | d.¡dd … ¡}g }t|ƒdk�r¼| d
¡ | d¡ | d/¡ | d0¡ | d1||f ¡ | d2||f ¡ | d3||f ¡ | d¡ | d¡ ntƒ  t| ƒ d S | d¡ | d¡ | d¡ |D ]}| |¡ �qð|}d4} t
| d5d6d7�}!|! d& |¡¡ |! ¡  |d8k �rBd9| }|d:k �rTd9| }|d8k �rfd9| }|d:k �rxd9| }|d8k �rŠd9| }|d:k �rœd9| }d;|||f }"t|"ƒ |d8k �rÄd9| }|d:k �rÖd9| }|d8k �rèd9| }|d:k �rúd9| }|d8k �rd9| }|d:k �rd9| }t d<d=|||f ¡ t| ƒ d S )>Nr   r   r   r   r    r!   r"   Úr)r(   z'<h2>Summary of existing Case Plans</h2>r   z	|   |   |z	| - | - |u4   |  ðŸ”µ  | Plans with customized step definitions. |u1   |  â­•  | Plans using default boilerplate code. |u4   |  ðŸš§  | Plans under construction with no table. |z--------u)   <h3>ðŸ”Ž (Click rows to expand) ðŸ”�</h3>u   ðŸ”µFr$   u   â­•ú|é	   ú-é   u   ðŸš§TÚ
z``r#   z	<details>z<summary> %s <code><b>r+   éþÿÿÿz</b></code></summary>z
</details>r*   z%s <code><b>%s</b></code>z$%s Case Plans with customized tablesz#1 Case Plan with a customized tablez$%s Case Plans using boilerplate codez"1 Case Plan using boilerplate codez%%s Case Plans that are missing tablesz#1 Case Plan that is missing a tabler   z|   |    |   |z| - | -: | - |u   | ðŸ”µ | %s | %s |u   | â­• | %s | %s |u   | ðŸš§ | %s | %s |zcase_summary.mdr%   r&   r'   é
   z %séd   uG   ðŸ—‚ï¸�  Summary generated at "case_summary.md":
ðŸ”µ %s
â­• %s
ðŸš§ %szCase Plans Summary generated!u>   
Summary generated at "case_summary.md"
ðŸ”µ %s
â­• %s
ðŸš§ %s)r/   r.   Ústripr0   r,   r1   r   r2   r3   r4   r6   Úreadr8   r   r   ÚcountÚ
startswithÚendswithÚinsertr7   r9   r   r:   )#r   r;   Zcase_data_storageZcase_to_test_hashZfull_tZ
test_indexr>   r?   r@   rA   rB   rC   Ú	case_pathÚfZ	case_dataZ	full_planZnum_ready_casesZnum_boilerplateZnum_in_progressZ
case_indexÚiconZtable_missingÚlinesÚ
first_lineZmsg_ready_casesZmsg_boilerplateZmsg_in_progressZmsg_rZmsg_bZmsg_iZ	plan_headÚrowrF   ÚfileZgen_messager   r   r   Ú#view_summary_of_existing_case_plans¢   sV   

ÿ










 

ÿþÿÿþ











ÿ












üÿ





üþr_   c                    s  t  ¡ ‰ˆ d¡ t ¡ r(ˆ dd¡ nˆ dd¡ t jˆdd� ¡  dtˆƒ }tˆƒdkrbd	}d
}t jˆ|ddd� ¡  t jˆ|ddd� ¡  t	ˆdddt j
d�}|jt jt jdd� d}i ‰ g ‰g ‰ˆD �]P}|d7 }t  ¡ ˆ |< d }t ¡ �rt j||ddddddˆ | d�	}nt j||ddddˆ | d�}| ¡  d¡}d }	d }
t|ƒdk�r`|d }	t|ƒdk�rˆ|d }	d |dd… ¡}
t|	ƒ}|d }d }t|ƒdk�rºtj d|¡}ntj |
d|¡}tj |¡�rð| ¡  ˆ | ¡ ¡ nˆ | ¡ ¡ |jd |d!� | d d"¡ |d7 }qÎt jˆdd� ¡  t jˆd#d‡ ‡‡‡‡fd$d%„d&� ¡  t jˆdd� ¡  z$t jˆd'd(‡‡fd)d%„d&� ¡  W n4 t�yÄ   t jˆd'd‡‡fd*d%„d&� ¡  Y n0 t jˆd"d� ¡  tˆƒ t  ¡ }| d+¡ | ¡  | ¡  |  ¡  | !¡  ˆ "¡  d S ),Nz!SeleniumBase Case Plans Generatori4  ij  iŒ  r   )ÚtextzQSelect from %s tests found:  (Boilerplate Case Plans will be generated as needed)r   zOSelect from 1 test found:  (Boilerplate Case Plans will be generated as needed)z4(Tests with existing Case Plans are already checked)ÚyellowÚgreen)r`   ÚbgÚfgÚmagentarQ   é   Úword)ÚwidthÚheightÚwrapÚstateT)ZsideÚfillÚexpandr   zÈ                                                                                                                                                                                                        ÚwhiteÚblackÚw)r`   rc   rd   ÚanchorÚpadyZborderwidthZhighlightthicknessÚvariable)r`   rc   rd   rq   rr   rs   r   r    r!   r"   Úend)ZwindowrN   z?Generate boilerplate Case Plans for selected tests missing themc                      s   t ˆˆˆ ˆˆƒS ©N)rH   r   ©Zarar   r;   r<   r=   r   r   Ú<lambda>Ã  s   ûz$create_tkinter_gui.<locals>.<lambda>)r`   rd   Úcommandz'Generate Summary of existing Case PlansÚtealc                      s
   t ˆ ˆƒS ru   ©r_   r   ©r   r;   r   r   rw   Ò  ó    c                      s
   t ˆ ˆƒS ru   rz   r   r{   r   r   rw   Ù  r|   Z1x1)#ÚtkZTkÚtitler   Ú
is_windowsZminsizeÚLabelÚpackr,   r   ZDISABLEDZTOPZBOTHZIntVarZCheckbuttonrR   r0   r1   r   r2   r3   r4   Úselectr.   Zwindow_createrW   ZButtonÚ	Exceptionr   ZgeometryZiconifyÚupdateZ	deiconifyÚdestroyZmainloop)r;   Úcommand_stringZrun_displayZrun_display_2Z	text_arearT   r]   Úcbr?   r@   rA   rB   rC   rX   Zdecoyr   rv   r   Úcreate_tkinter_guim  sÊ    
þÿÿÿ

÷ù	
ú
üü
rˆ   c                  C   sª  d} t  ¡ rd} t| ƒ\}}}}}}}tjdd … }d |¡}	d}
|
|7 }
|
d7 }
|
|7 }
|
d7 }
|
|7 }
|
d7 }
|
|7 }
|
d	7 }
|
|7 }
|
d7 }
|
|7 }
|
d
7 }
|
|7 }
|
d7 }
|
|7 }
|
d7 }
|
|7 }
t|
ƒ tjdtj	|	f tj
dd�}| ¡ \}}|�r$dt|ƒ }|| | }t|ƒ d S g }t  ¡ �r>| d¡}n
| d¡}| dd¡ d¡D ]}d|v �rZ| |¡ �qZ|�sœd}|d | | }t|ƒ d S t||	ƒ d S )NTFr+   r   r   Ú*z Starting the ZSeleniumZBasez
Case Plansz
 Generatorz...z2"%s" -m pytest --collect-only -q --rootdir="./" %s)ÚstdoutÚshellzError collecting tests: %sÚlatin1r&   úrN   r   z3No tests found! Exiting the Case Plans Generator...zERROR: )r   Zis_linuxr   ÚsysÚargvr1   r9   Ú
subprocessÚPopenÚ
executableÚPIPEÚcommunicateÚstrr   Údecoder   r0   r.   rˆ   )r   r	   r
   r   r   r   r   r   Úcommand_argsr†   ÚmessageÚprocÚoutputÚerrorÚ	error_msgr;   r]   r   r   r   Úmainê  sf    
ÿü


r�   Ú__main__z8To open the Case Plans Generator, type "sbase caseplans")Ú__doc__r   r2   r�   rŽ   Útkinterr}   Zseleniumbase.fixturesr   r   Ztkinter.scrolledtextr   r   r   r   r   rH   r_   rˆ   r�   Ú__name__r9   r   r   r   r   Ú<module>   s&   _ L}8