
                             S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  \R&                   " S S\R(                  5      5       rg)zThe `gcloud meta test` command.    N)arg_parsers)base)parser_completer)parser_errors)
completers)
exceptions)execution_utils)module_util)
console_io)progress_trackerc                   v    \ rS rSrSr\S 5       rS rS rS r	S r
S rS	 rS
 rS rS rS rS rS rS rSrg)Test#   zRun miscellaneous gcloud command and CLI test scenarios.

This command sets up scenarios for testing the gcloud command and CLI.
c                    U R                  SS[        R                  SS9  U R                  SSS9nUR                  S[        R
                  " 5       SS	S
9  UR                  S[        R                  " 5       SSS
9  UR                  SSSS9  UR                  SSSS9  UR                  SSSS9  UR                  SSSS9  UR                  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!S%S#9  UR                  S&SS'S9  UR                  S(SS)S9  UR                  S*SS+S9  g ),Nname*z5command_lib.compute.TestCompleter instance name test.)nargs	completerhelpT)mutexrequiredz
--arg-dict
ATTRIBUTESzArgDict flag value test.)typemetavarr   z
--arg-listITEMSzArgList flag value test.z --argumenterror-outside-argparse
store_truezMTrigger a calliope.parser_errors.ArgumentError exception outside of argparse.)actionr   z--core-exceptionzTrigger a core exception.z--exec-fileSCRIPT_FILEzRuns `bash SCRIPT_FILE`.)r   r   z--interruptzKill the command with SIGINT.z--is-interactivezaCall console_io.IsInteractive(heuristic=True) and exit 0 if the return value is True, 1 if False.z--prompt-completerMODULE_PATHzlCall console_io.PromptResponse() with a MODULE_PATH completer and print the response on the standard output.z--progress-trackerSECONDSg        z6Run the progress tracker for SECONDS seconds and exit.)r   r   defaultr   z--sleepz#Sleep for SECONDS seconds and exit.z--uncaught-exceptionz(Trigger an exception that is not caught.z--staged-progress-trackerz$Run example staged progress tracker.z--feature-flagz"Print the value of a feature flag.)add_argumentr   TestCompleter	add_groupr   ArgDictArgListfloat)parser	scenarioss     lib/surface/meta/test.pyArgs	Test.Args*   s   
**D	  F
   td ;I  "'	  )
   "'	  )
 *%  '
 (  * '  ) ,  . 9  ;
 ?  A
 E  G 2  4 7  9 #3  5 1  3    c                     UR                   $ N)arg_dictselfargss     r*   _RunArgDictTest._RunArgDictp       ==r-   c                     UR                   $ r/   )arg_listr1   s     r*   _RunArgListTest._RunArgLists   r6   r-   c                 *    [         R                  " SS9e)Nz--some-flag)argument)r   RequiredErrorr1   s     r*    _RunArgumenterrorOutsideArgparse%Test._RunArgumenterrorOutsideArgparsev   s    

%
%}
==r-   c                 .    [         R                  " S5      e)NzSome core exception.)r   Errorr1   s     r*   _RunCoreExceptionTest._RunCoreExceptiony   s    


1
22r-   c                 H    [         R                  " SUR                  /5        g )Nbash)r	   Exec	exec_filer1   s     r*   _RunExecFileTest._RunExecFile|   s    &$..12r-   c                 p    [         R                  " [        [        R                  " SS9(       + 5      5        g )NT)	heuristic)sysexitintr   IsInteractiver1   s     r*   _RunIsInteractiveTest._RunIsInteractive   s!    HHSZ--==>?r-   c                 \    [         R                  " [         R                  " 5       [        R                  5        [
        R                  " S5        [        R                  " S5      e! [         a;    [         R                  " [         R                  " 5       [        R                  5         NZf = f)N   zSIGINT delivery failed.)oskillgetpidsignalCTRL_C_EVENTtimesleepAttributeErrorSIGINTr   rA   r1   s     r*   _RunInterruptTest._RunInterrupt   sk    * 	ggbiik6../
jjm 

4
55  *ggbiik6==)*s   AA& &AB+*B+c                     [         R                  " UR                  5      n[        R                  " X!5      n[
        R                  " SUS9n[        U5        g )NzComplete this: )choices)r
   ImportModuleprompt_completerr   ArgumentCompleterr   PromptResponseprint)r2   r3   completer_classr`   responses        r*   _RunPromptCompleterTest._RunPromptCompleter   sB    !..t/D/DEO00GG(():GLH	(Or-   c                    ^^ [         R                   " 5       mUU4S jn[        R                  " SUS9   [         R                  " TR                  5        S S S 5        g ! , (       d  f       g = f)Nc                  p   > TR                   [        R                  " 5       T-
  -
  n SR                  U 5      $ )Nz{0:.1f}s remaining)r   rY   format)remaining_timer3   
start_times    r*   message_callback2Test._RunProgressTracker.<locals>.message_callback   s/    ,,		j0HIn!((88r-   zThis is a progress tracker.)messagedetail_message_callback)rY   r   ProgressTrackerrZ   )r2   r3   ro   rn   s    ` @r*   _RunProgressTrackerTest._RunProgressTracker   sM    J9 
	)	)- 0
2 jj&&'
2 
2 
2s   !A
A,c                 D    [         R                  " UR                  5        g r/   )rY   rZ   r1   s     r*   	_RunSleepTest._RunSleep   s    JJtzzr-   c                     [        S5      e)NzCatch me if you can.)
ValueErrorr1   s     r*   _RunUncaughtExceptionTest._RunUncaughtException   s    
+
,,r-   c                    [         R                  " SSS9n[         R                  " SSS9n[         R                  " SSS9nX#U/n[         R                  " SUSS	S
S9 nUR                  S5        [        R
                  " S5        UR                  SS5        [        R
                  " S5        UR                  SS5        UR                  S5        [        R
                  " S5        UR                  S5        UR                  S5        [        R
                  " S5        UR                  S5        S S S 5        g ! , (       d  f       g = f)NzGetting bread...bread)keyzGetting peanut butter...pbzMaking sandwich...makezTime to eat!zTime to order delivery..!zmeta.make_sandwich)success_messagefailure_message
tracker_idg      ?zLooking for bread in the pantryzGot some whole wheat bread!rS   )r   StageStagedProgressTracker
StartStagerY   rZ   UpdateStageCompleteStage)r2   r3   	get_breadget_pb_and_jmake_sandwichstagestrackers          r*   _RunStagedProgressTrackerTest._RunStagedProgressTracker   s    &&'9wGI#))*D$OL$**+?VLM}5F		/	/&3'
)
 -4!
jjo'#DE
jjoG%BC
jjmD! 
jjmF#!
) 
) 
)s   CD77
Ec                    UR                   (       a  U R                  U5      nU$ UR                  (       a  U R                  U5      nU$ UR                  (       a  U R                  U5      nU$ UR                  (       a  U R                  U5        S nU$ UR                  (       a  U R                  U5        S nU$ UR                  (       a  U R                  U5        S nU$ UR                  (       a  U R                  U5        S nU$ UR                  (       a  U R                  U5        S nU$ UR                   (       a  U R#                  U5        S nU$ UR$                  (       a  U R'                  U5        S nU$ UR(                  (       a  U R+                  U5      nU$ UR,                  (       a  U R/                  U5        S nW$ r/   )r0   r4   r8   r9   argumenterror_outside_argparser>   core_exceptionrB   rG   rH   	interruptr]   is_interactiverP   rb   rh   r   rt   rZ   rw   uncaught_exceptionr{   staged_progress_trackerr   )r2   r3   rs      r*   RunTest.Run   s   }}


4
 a> H= 



4
 a: H9 
	,	,

/
/
5a6 H5 
		
T"
a0 H/ 


a* H) 


a$ H# 
		
T"
a H 
		
t$
a H 
		
t$
a H 

nnT
a H 
	 	 

$
$T
*a H 
	%	%
$$T*
aHr-    N)__name__
__module____qualname____firstlineno____doc__staticmethodr+   r4   r9   r>   rB   rH   rP   r]   rh   rt   rw   r{   r   r   __static_attributes__r   r-   r*   r   r   #   s`    
 C3 C3J>33@	6(-$.!r-   r   )r   rT   rW   rL   rY   googlecloudsdk.callioper   r   r   r   "googlecloudsdk.command_lib.computer   googlecloudsdk.corer   r	   r
   googlecloudsdk.core.consoler   r   UniverseCompatibleCommandr   r   r-   r*   <module>r      s^    & 
  
  / ( 4 1 9 * / + 2 8 x4<< x xr-   