
    4                        S r SSKJr  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
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  \R0                   " S S\R2                  5      5       rg)zThe `gcloud meta test` command.    )absolute_import)division)print_function)unicode_literalsN)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._RunArgDictt       ==r1   c                     UR                   $ r3   )arg_listr5   s     r.   _RunArgListTest._RunArgListw   r:   r1   c                 *    [         R                  " SS9e)Nz--some-flag)argument)r
   RequiredErrorr5   s     r.    _RunArgumenterrorOutsideArgparse%Test._RunArgumenterrorOutsideArgparsez   s    

%
%}
==r1   c                 .    [         R                  " S5      e)NzSome core exception.)r   Errorr5   s     r.   _RunCoreExceptionTest._RunCoreException}   s    


1
22r1   c                 H    [         R                  " SUR                  /5        g )Nbash)r   Exec	exec_filer5   s     r.   _RunExecFileTest._RunExecFile   s    &$..12r1   c                 p    [         R                  " [        [        R                  " SS9(       + 5      5        g )NT)	heuristic)sysexitintr   IsInteractiver5   s     r.   _RunIsInteractiveTest._RunIsInteractive   s!    HHSZ--==>?r1   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   rE   r5   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)r6   r7   completer_classrd   responses        r.   _RunPromptCompleterTest._RunPromptCompleter   sB    !..t/D/DEO00GG(():GLH	(Or1   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   r]   format)remaining_timer7   
start_times    r.   message_callback2Test._RunProgressTracker.<locals>.message_callback   s/    ,,		j0HIn!((88r1   zThis is a progress tracker.)messagedetail_message_callback)r]   r   ProgressTrackerr^   )r6   r7   rs   rr   s    ` @r.   _RunProgressTrackerTest._RunProgressTracker   sM    J9 
	)	)- 0
2 jj&&'
2 
2 
2s   !A
A,c                 D    [         R                  " UR                  5        g r3   )r]   r^   r5   s     r.   	_RunSleepTest._RunSleep   s    JJtzzr1   c                     [        S5      e)NzCatch me if you can.)
ValueErrorr5   s     r.   _RunUncaughtExceptionTest._RunUncaughtException   s    
+
,,r1   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!rW   )r   StageStagedProgressTracker
StartStager]   r^   UpdateStageCompleteStage)r6   r7   	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$ r3   )r4   r8   r<   r=   argumenterror_outside_argparserB   core_exceptionrF   rK   rL   	interruptra   is_interactiverT   rf   rl   r   rx   r^   r{   uncaught_exceptionr   staged_progress_trackerr   )r6   r7   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Hr1    N)__name__
__module____qualname____firstlineno____doc__staticmethodr/   r8   r=   rB   rF   rL   rT   ra   rl   rx   r{   r   r   r   __static_attributes__r   r1   r.   r   r   '   s`    
 C3 C3J>33@	6(-$.!r1   r   )r   
__future__r   r   r   r   rX   r[   rP   r]   googlecloudsdk.callioper   r   r	   r
   "googlecloudsdk.command_lib.computer   googlecloudsdk.corer   r   r   googlecloudsdk.core.consoler   r   UniverseCompatibleCommandr   r   r1   r.   <module>r      sh    & &  % ' 	  
  / ( 4 1 9 * / + 2 8 x4<< x xr1   