
                         P   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	J
r
  SSKJr  SS	KJr  SSKJs  Jr  SS
KJr  SSKJr  SSKJs  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r! " S S\RD                  5      r# " S S\RH                  5      r%g)!Integration tests for rm command.    )absolute_import)print_function)division)unicode_literalsN)mock)NO_URLS_MATCHED_PREFIX)NO_URLS_MATCHED_TARGET)MAX_BUCKET_LENGTH)	SkipForS3)GenerationFromURI)ObjectToURI)SetBotoConfigForTest)SetEnvironmentForTest)	shim_util)Retrya]  If you experience problems with multiprocessing on MacOS, they might be related to https://bugs.python.org/issue33725. You can disable multiprocessing by editing your .boto config or by adding the following flag to your command: `-o "GSUtil:parallel_process_count=1"`. Note that multithreading is still available even if you disable multiprocessing.c                      \ rS rSrSrS rS r   S#S j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\" S5      S 5       rS rS r\" S5      S 5       rS r\" S5      S 5       r\" S5      S 5       rS rS  rS! r S"r!g)$TestRm0   r   c                     U R                   (       a  U R                  U5      $ SnSn/ SQn[        R                  " X!5      [        R                  " X15      -   U-   nU H  nUR	                  US5      nM     U$ )zExcludes everything coming from the UI to avoid assert errors.

Args:
  stderr: The cumulative stderr output.
Returns:
  The cumulative stderr output without the expected UI output.
z[^
]*objects][^
]*[
]zOperation completed over[^
]*)z\z|z/z- )_use_gcloud_storage!_CleanOutputLinesForGcloudStoragerefindallreplace)selfstderrui_output_patternfinal_message_patternui_spinner_listui_lines_listui_lines          &platform/gsutil/gslib/tests/test_rm.py_CleanRmUiOutputBeforeChecking%TestRm._CleanRmUiOutputBeforeChecking3   sy     33F;;8<3OZZ 1:ZZ 5>?$%M !~~gr*f !M    c                     UR                  5       n/ n[        / SQ5      nU H5  nXT;   a  M
  UR                  S5      nU(       d  M$  UR                  U5        M7     [        R
                  R                  U5      $ )z.Remove irrelevant lines from the output lines.)zRemoving objects:zRemoving Buckets:z  .)
splitlinessetlstripappendoslinesepjoin)r   r   stderr_linesvalid_linesstrings_to_removelinecleaned_lines          r$   r   (TestRm._CleanOutputLinesForGcloudStorageG   sl    $$&LKLM		" [[%l	<(  ::??;''r'   Nc                 v  ^ ^^^^^ / nT=(       d    /  H  nUR                  SU-  5        M     / nU=(       d    /  H  nUR                  SU-  5        M     [        Xu-   5      mT R                  (       Gd  T R                  S:X  Ga  T R	                  TSSTS9n	[        U5      n
ST;  aC  T R                  (       d2  ST;   a  T R                  S	X4-  U	5        OT R                  S
U
-  U	5        T R                  U	5      n	[        U	R                  5       5      nSU;   a  UR                  S5        [        U;   a  UR                  [        5        T R                  (       a  T H  nT R                  X5        M     gT R                  UT5        g[        5       m[        [        SSS9UUUUU U4S j5       nU" 5         g)a  Tests a remove command in the presence of eventual listing consistency.

Eventual listing consistency means that a remove command may not see all
of the objects to be removed at once. When removing multiple objects
(or buckets via -r), some calls may return no matches and multiple calls
to the rm command may be necessary to reach the desired state. This function
retries the rm command, incrementally tracking what has been removed and
ensuring that the exact set of objects/buckets are removed across all
retried calls.

The caller is responsible for confirming the existence of buckets/objects
prior to calling this function.

Args:
  command_and_args: List of strings representing the rm command+args to run.
  objects_to_remove: List of object URL strings (optionally including
      generation) that should be removed by the command, if any.
  buckets_to_remove: List of bucket URL strings that should be removed by
     the command, if any.
  stdin: String of data to pipe to the process as standard input (for
     testing -I option).
Removing %s/...zRemoving %s...gsTNreturn_stderrexpected_statusstdin-q-mz[%d/%d objects]z[%d objects]r         triestimeout_secsc                  B  > TR                  TSSTS9n TR                  U 5      n Sn[        U ;   d  SU ;   d  SU ;   a  SnTR                  (       a  SnOSnS	T;   af  SU ;   a`  T HZ  n[        R
                  " S
[        R                  " U5      -  U 5      nU(       d  M:  T	 H  nSU-  U;   d  M      g   SU-  U ;   d  MZ    g   U(       aA  T	R                  [        U R                  5        Vs/ s H  of(       d  M  UPM     sn5      5        TR                  T	T
5        gs  snf )z=Runs/retries the command updating+checking cumulative output.TNr:   z409 BucketNotEmptyz409 VersionedBucketNotEmptyFz	not foundbucket does not exist-rz".*404\s+%s\s+bucket does not existr8   )	RunGsUtilr%   r	   r   r   matchescapeupdater+   r*   assertEqual)r   update_linesbucket_not_found_stringbucket_to_removematching_bucketr4   sbuckets_to_removecommand_and_argscumulative_stderr_linesexpected_stderr_linesr   r=   s          r$   _RunRmCommandAndCheck?TestRm._RunRemoveCommandAndCheck.<locals>._RunRmCommandAndCheck   s8     0.204&+   - 44V< #f, F*)V3, ##$/
!$;
!##(?6(I"3 hh5		*+,-35O 1$$'774? 2 #%55? #4 
!
(
(f//171Q1178: 	02GH 8s   *
D8D)r-   r+   multiregional_bucketsdefault_providerrH   lenr   assertInr%   r*   removeMACOS_WARNINGrL   r   AssertionError)r   rS   objects_to_removerR   r=   bucket_stringsrO   object_stringsobject_to_remover   num_objects
stderr_setto_checkrV   rT   rU   s   `` ``         @@r$   _RunRemoveCommandAndCheck TestRm._RunRemoveCommandAndCheckW   s   6 N-33-0@@A 4N-33,/??@ 4 ?@%%%$*?*?4*G~~.,0.2$)  +f 'k	%	%d.F.F##
--)[,FF
O
--4f
=226:fv((*+j	z	"	*	$-(		!	!-H
--
) . 	%:; #^115)I )I 6)IV r'   c                   ^ ^^^^ T R                  5       nT R                  US5      mT R                  TS5        [        T5      mT R                  TS5        [        T5      mUUUU 4S jm[	        5       nT R
                  (       a2  T R                  USSS9  [        [        SS	S
9U4S j5       nU" U5        OT" U5        T R                  USSS9  g)z=Test that 'rm -a' for an object with a current version works.foobarbazc                   > TR                  SSS[        T5      /SS9nU R                  [        UR	                  5       5      5        SR                  U 5      nTR                  UR                  STR                  -  5      S5        TR                  S	[        T5      < S
T< S3U5        TR                  S	[        T5      < S
T< S3U5        g )Nr?   rm-aTr;   
Removing %s://   z	Removing #z...)
rH   surirK   r+   r*   r0   rL   countrY   r[   )r1   r   g1g2key_urir   s     r$   _Check11TestRm.test_all_versions_current.<locals>._Check1   s    ~~tT']
+4  Af#f//123yy&f
v||$4t7L7L$LM
mm4="=vF
mm4="=vFr'   rr   T	versioned   rA   rB   c                    > T" U 5        g N )r1   ry   s    r$   _CheckWithRetries;TestRm.test_all_versions_current.<locals>._CheckWithRetries   s     	r'   r   N)	CreateVersionedBucketStorageUriCloneReplaceNameStorageUriSetContentsFromStringurigenr+   rX   AssertNObjectsInBucketr   r^   )r   
bucket_uriall_stderr_linesr   ry   rv   rw   rx   s   `   @@@@r$   test_all_versions_current TestRm.test_all_versions_current   s    ++-J--j%@G((%8	B((%8	BG G u!!
!!*a4!@^115 6 ()
A>r'   c                 \   U R                  5       nU R                  US5      nU R                  US5        [        U5      nU R                  US5        [        U5      nU R	                  SSS[        U5      /[        U5      < SU< 3[        U5      < SU< 3/S9  U R                  US	S
S9  g)z@Test that 'rm -a' for an object without a current version works.ri   rj   rk   r?   rm   rn   rs   r_   r   Tr{   N)r   r   r   r   rf   rt   r   )r   r   rx   rv   rw   s        r$   test_all_versions_no_current#TestRm.test_all_versions_no_current   s    ++-J--j%@G((%8	B((%8	B""	tT4=)G}b)G}b)
 #  	
A>r'   c           	          U R                  5       nU R                  SSS[        US5      -  /SSS9nU R                  (       a  SnO[        nU R                  U[        US5      -  U5        g )	Nrm   rn   %sri   TrA   r;   r<   2The following URLs matched no objects or files:
%s)r   rH   rt   r   r
   r[   )r   r   r   no_url_matched_targets       r$   test_fails_for_missing_obj!TestRm.test_fails_for_missing_obj   su    ++-J^^	tTDU334  F 
? 4 5MM'$z5*AA6Jr'   c                    U R                  5       nU R                  USSS9nU R                  (       a  U R                  US5        U R	                  SS[        US5      /SS	9nU R                  S
[        U5      -  U5        g )Nza/b/c   foor   object_namecontentsrA   rm   rG   aTro   zRemoving %s)CreateBucketCreateObjectrX   r   rH   rt   r[   )r   r   obj_urir   s       r$   test_remove_recursive_prefix#TestRm.test_remove_recursive_prefix  s    ""$J:,3)/   1G !!
!!*a0^^T4j#)>?*.  0FMM-$w-/8r'   c           	        ^ ^ T R                  5       mT R                  TS5      nT R                  TS5      nT R                  US5        T R                  US5        [        U5      n[        U5      nT R                  US5        T R                  US5        [        U5      n[        U5      nT R                  (       a  T R                  TSSS	9  T R                  S
S[        T5      /[        U5      < SU< 3[        U5      < SU< 3[        U5      < SU< 3[        U5      < SU< 3/[        T5      /S9  [        [        SSS9UU 4S j5       nU" 5         g)z"Test that 'rm -r' works on bucket.ri   foo2rj   bar2rk   baz2   Tr{   rm   rG   rs   r_   rR   r}   rA   rB   c                     > TR                  SS[        T5      /SSS9n TR                  (       a3  TR                  (       a!  TR                  SU ;   =(       d    SU ;   5        g g TR	                  SU 5        g )	Nlsrn   TrA   r   not found: 404NoSuchBucketrF   )rH   rt   r   
assertTruer[   r   r   r   s    r$   _CheckCTestRm.test_remove_all_versions_recursive_on_bucket.<locals>._Check)  sw     ~~tT4
+;<,0./  1f 
	!	!##
//*f4 3(F24 $
 	-v6r'   N)
r   r   r   r   rX   r   rf   rt   r   r^   )	r   k1_urik2_urik1g1k2g1k1g2k2g2r   r   s	   `       @r$   ,test_remove_all_versions_recursive_on_bucket3TestRm.test_remove_all_versions_recursive_on_bucket  s?   ++-J,,Z?F,,Z@F((7((8&>D&>D((7((8&>D&>D!!
!!*a4!@""D$Z0@#A26v,'E26v,'E26v,'E26v,'E	6% 7;:6F5G # I >37 47 Hr'   c           	         U R                  5       nU R                  US5      nU R                  US5      nU R                  US5        U R                  US5        [        U5      n[        U5      nU R                  US5        U R                  US5        [        U5      n[        U5      nU R                  (       a  U R                  USSS	9  U R                  S
SS[        US5      -  /[        U5      < SU< 3[        U5      < SU< 3[        U5      < SU< 3[        U5      < SU< 3/S9  U R                  USSS	9  g)z"Test that 'rm -r' works on subdir.zdir/foozdir/foo2rj   r   rk   r   r   Tr{   rm   rG   r   dirrs   r   r   N)r   r   r   r   rX   r   rf   rt   )r   r   r   r   r   r   r   r   s           r$   ,test_remove_all_versions_recursive_on_subdir3TestRm.test_remove_all_versions_recursive_on_subdir9  s+   ++-J,,ZCF,,ZDF((7((8&>D&>D((7((8&>D&>D!!
!!*a4!@""	tTDU334F|T*F|T*F|T*F|T*	
 #  	
A>r'   c                     U R                  SS9n[        SS/5         U R                  SS[        U5      /SS9nU R	                  S	U5        S S S 5        g ! , (       d  f       g = f)
Nr   r   GSUtiltask_estimation_threshold1r   task_estimation_forceTruer?   rm   Tro   z,Estimated work for this command: objects: 1
)r   r   rH   rt   r[   r   
object_urir   s      r$   test_rm_seek_aheadTestRm.test_rm_seek_aheadT  sp    ""F"3J	KJL 
M~~tT4
+;<,0  2f
mmCVL	
M 
M 
M   /A
A#c                     U R                  SS9n[        SS/5         U R                  / SQ[        U5      SS9nU R	                  SU5        S S S 5        g ! , (       d  f       g = f)	Nr   r   r   r   )r?   rm   -IT)r=   r;   zEstimated work)r   r   rH   rt   assertNotInr   s      r$   test_rm_seek_ahead_stdin_args$TestRm.test_rm_seek_ahead_stdin_args\  sq    ""F"3J	KJL 
M~~0$($4,0  2f '0
M 
M 
Mr   c           	         U R                  5       nU R                  USSS9nU R                  (       a  U R                  US5        U R                  (       d)  U R                  SS[        US5      -  [        U5      /SS9  U R                  SS	S[        US5      -  [        U5      /S
SS9nU R                  UR                  SU R                  -  5      S5        U R                  S[        U5      /SS9  g )Npresentr   r   rA   rm   r   missingr<   -fTr   rq   stat)
r   r   rX   r   r   rH   rt   rL   ru   rY   r   r   r   r   s       r$   test_missing_first_forceTestRm.test_missing_first_forcee  s   ""$J""j/8,2 # 4J !!
!!*a0## nnZ33
   ^^	t	Z+	+	j		   F 	V\\"2T5J5J"JKQONNFD,-qNAr'   c           
      
   U R                  5       nU R                  US5      nU R                  US5        U R                  (       a  U R	                  USSS9  U R                  SS[        U5      S[        US	5      -  /SSS
9nU R                  UR                  SU R                  -  5      S5        U R                  (       a   U R                  S[        US	5      -  U5        gU R                  [        [        US	5      -  U5        g)z?Test that 'rm -a' fails when some but not all uris don't exist.ri   rj   rA   Tr{   rm   rn   r   r   r   rq   r   N)r   r   r   rX   r   rH   rt   rL   ru   rY   r   r[   r
   r   r   rx   r   s       r$   test_some_missingTestRm.test_some_missing|  s    ++-J--j%@G((%8!!
!!*a4!@^^	t	g	Z+	+	-   F 	V\\"2T5J5J"JKQO
mm
?
z9
%&'-/ mm*T*i-HHr'   c           
         U R                  5       nU R                  US5      nU R                  US5        U R                  (       a  U R	                  USSS9  U R                  SS[        U5      S[        US	5      -  /SSS
9nU R                  UR                  SU R                  -  5      S5        U R	                  US5        g)z5Test that 'rm -af' succeeds despite hidden first uri.ri   rj   rA   Tr{   rm   z-afr   r   r   rq   r   N)
r   r   r   rX   r   rH   rt   rL   ru   rY   r   s       r$   test_some_missing_forceTestRm.test_some_missing_force  s    ++-J--j%@G((%8!!
!!*a4!@^^	u	g	Z+	+	-   F 	V\\"2T5J5J"JKQO
A.r'   c                 x  ^ ^^ T R                  5       mT R                  TS5      nT R                  US5        T R                  TS5      nT R                  US5        UU 4S jmT R                  (       a1  T R	                  TSSS9  [        [        S	S
S9U4S j5       nU" 5         OT" 5         TR                  SS9  g)8Test for 'rm -r' of a folder with a dir_$folder$ marker.abc/o1foobarabc_$folder$r   c            	      h   > TR                  SSS[        T S5      -  /S S9  TR                  T SSS9  g )	Nrm   rG   r   abcr   r   Tr{   )rH   rt   r   )r   r   s   r$   _RemoveAndCheck;TestRm.test_folder_objects_deleted.<locals>._RemoveAndCheck  sA    
nndD$j%)@"@A%)  +
!!*a4!@r'   rr   Tr{   r}   rA   rB   c                     > T " 5         g r   r   )r   s   r$   _RemoveAndCheckWrapperBTestRm.test_folder_objects_deleted.<locals>._RemoveAndCheckWrapper  s	    r'   FvalidateN)r   r   r   rX   r   r   r^   get_location)r   rx   
folder_urir   r   r   s   `   @@r$   test_folder_objects_deleted"TestRm.test_folder_objects_deleted  s    ++-J--j(CG(((;00^LJ((R8A
 !!
!!*a4!@ ^115 6 U+r'   c           	         U R                  5       nU R                  US5      nU R                  US5        U R                  US5      nU R                  US5        U R                  (       a  U R	                  USSS9  U R                  SS	S
[        US5      -  /[        U5      < S[        U5      < 3[        U5      < S[        U5      < 3/S9  U R	                  USSS9  UR                  SS9  g)r   r   r   r   r   rr   Tr{   rm   rG   r   *rs   r   r   Fr   N	r   r   r   rX   r   rf   rt   r   r   r   r   rx   r   s       r$   )test_folder_objects_deleted_with_wildcard0TestRm.test_folder_objects_deleted_with_wildcard  s    ++-J--j(CG(((;00^LJ((R8!!
!!*a4!@""	tTDS112G}fWo6J'
);<
 #  	
A>U+r'   c           	         U R                  5       nU R                  US5      nU R                  US5        U R                  US5      nU R                  US5        U R                  (       a  U R	                  USSS9  U R                  SS	S
[        US5      -  /[        U5      < S[        U5      < 3[        U5      < S[        U5      < 3/S9  U R	                  USSS9  UR                  SS9  g)r   r   r   r   r   rr   Tr{   rm   rG   r   **rs   r   r   Fr   Nr   r   s       r$   0test_folder_objects_deleted_with_double_wildcard7TestRm.test_folder_objects_deleted_with_double_wildcard  s    ++-J--j(CG(((;00^LJ((R8!!
!!*a4!@""	tTDT223G}fWo6J'
);<
 #  	
A>U+r'   z2Listing/removing S3 DeleteMarkers is not supportedc                   ^ ^ T R                  5       mT R                  TSS9nT R                  (       a  T R                  TS5        T R	                  SS[        T5      /[        U5      < S[        U5      < 3/[        T5      /S9  [        [        SSS	9UU 4S
 j5       nU" 5         T R                  5       mT R                  TSSS9  T R                  TSSS9  T R                  TSSS9nT R                  (       a  T R                  TSSS9  T R	                  S[        TS5      /SU-  /S9  T R                  S[        T5      /SSSS9nT R                  SU5        [        [        SSS	9UU 4S j5       nU" 5         g)zTest for 'rm -r' of a bucket.r   r   rA   rm   rG   rs   r   r}   rB   c                  f   > TR                  SS[        T5      /SSSS9n TR                  SU 5        g )Nr   -LbTrA   r;   r<   force_gsutilrF   rH   rt   r[   r   s    r$   ry   0TestRm.test_recursive_bucket_rm.<locals>._Check1  s@     ~~tUD,<=,0./+/  1f mm+V4r'   obj   zTr{   r   r   r   rbr   z	not emptyc                     > TR                  SS[        T5      /5        TR                  SS[        T5      /SSSS9n TR                  SU 5        g )	Nrm   rG   r   r   TrA   r   rF   r   r   s    r$   _Check20TestRm.test_recursive_bucket_rm.<locals>._Check2  sV    
nndD$z"234~~tUD,<=,0./+/  1f mm+V4r'   N)r   r   rX   r   rf   rt   r   r   r^   r   rH   r[   )r   r   ry   	final_urir   r  r   s   `     @r$   test_recursive_bucket_rmTestRm.test_recursive_bucket_rm  s    ""$J"":"?J!!
!!*a0""	tT*%&&*:&6z8JKL
+, # . >35 45 I ++-Jj%$7j%$7!!*ed!CI!!
!!*a4!@""D$z4*@#A6:Y6F5G # I ^^T4
#34*.,-)-  /F 	MM+v& >35 45 Ir'   c           	         SU R                  5       -  nUS[        S-
   nU< SU R                  5       < 3nSU-   n[        R                  " U5      nU R                  SU-  S9nU R                  SU-  S9nU R                  S	U-  S9nU R                  US
SS9nU R                  USSS9nU R                  USSS9  U R                  (       a6  U R                  US5        U R                  US5        U R                  US5        U R                  SSU R                  < SU< S3/[        U5      < S[        U5      < 3[        U5      < S[        U5      < 3/[        U5      [        U5      /S9  U R                  US5        g)zBTests removing all objects and buckets matching a bucket wildcard.zgsutil-test-%sN   -zaaa-z	%s-tbuck1)bucket_namez	%s-tbuck2z%s-tb3o1r  r   o2o3rA   rm   rG   ://z-tbu*rs   r   )GetTestMethodNamer   MakeRandomTestStringutilMakeBucketNameValidr   r   rX   r   rf   rY   rt   r   )r   	buri_baseburi1buri2buri3ouri1ouri2s          r$   )test_recursive_bucket_rm_with_wildcarding0TestRm.test_recursive_bucket_rm_with_wildcarding  s    4#9#9#;;I1,r12I$d&?&?&ABI"I((3I+	*ABE+	*ABE(Y*>?ED4PED4PED4H!!
!!%+
!!%+
!!%+""	t00)	<	> E{F5M2E{F5M2
  ;U4 # 6 	q)r'   c                     U R                  5       nU R                  USS9nU R                  (       a  U R                  US5        U R	                  SS[        U5      // 5        U R                  US5        g)z2Test that 'rm -q' outputs no progress indications.r   )r   r   rA   r>   rm   r   N)r   r   rX   r   rf   rt   )r   r   rx   s      r$   test_rm_quietTestRm.test_rm_quiet9  si    ""$J:GG!!
!!*a0""D$W#>C
A.r'   z]The boto lib used for S3 does not handle objects starting with slashes if we use V4 signaturec                    U R                  5       nU R                  USSS9nU R                  (       a  U R                  USSS9  U R	                  SS[        U5      /[        U5      < S	[        U5      < 3/[        U5      /S
9  g)zTests removing a bucket that has an object starting with slash.

The boto lib used for S3 does not handle objects starting with slashes
if we use V4 signature. Hence we are testing objects with prefix
slashes separately.
z/dirwithslash/foor  r   rA   Tr{   rm   rG   rs   r   Nr   r   rX   r   rf   rt   r   )r   r   r  s      r$    test_rm_object_with_prefix_slash'TestRm.test_rm_object_with_prefix_slashB  s     ++-J*='+  -E !!
!!*a4!@""	tT*%&&*5k6%=AB
+, # .r'   c           
         U R                  5       nU R                  USSS9nU R                  USSS9nU R                  USSS9nU R                  (       a  U R                  USSS9  U R	                  S	S
[        U5      /[        U5      < S[        U5      < 3[        U5      < S[        U5      < 3[        U5      < S[        U5      < 3/[        U5      /S9  g)z6Tests removing a bucket that has objects with slashes.	h/e/l//lor  r   zdirnoslash/foozdirnoslash/foo2r}   Tr{   rm   rG   rs   r   Nr#  )r   r   r  r  ouri3s        r$   test_rm_object_with_slashes"TestRm.test_rm_object_with_slashesW  s    ++-J*5'+  -E *:'+  -E *;'+  -E !!
!!*a4!@""D$Z0@#A26u+ve}'M26u+ve}'M26u+ve}'M6%
 7;:6F5G # Ir'   c                    U R                  5       nU R                  USSS9nU R                  USSS9nU R                  USSS9nU R                  USS	S9nU R                  US
SS9nU R                  USSS9nU R                  USSS9nU R                  USSS9n	U R                  USSS9n
U R                  (       a  U R                  USSS9  [	        U5      < S[        U5      < 3[	        U5      < S[        U5      < 3[	        U5      < S[        U5      < 3[	        U5      < S[        U5      < 3[	        U5      S
-   < S[        U5      < 3[	        U5      S
-   < S[        U5      < 3[	        U5      S
-   < S[        U5      < 3[	        U	5      S
-   < S[        U	5      < 3[	        U
5      S
-   < S[        U
5      < 3/	nU R                  SSS[	        U5      /U[	        U5      /S9  g)zBTests removing a bucket with objects that are filled with slashes.r'  s	   Halloweenr   z
/h/e/l/l/os   A Nightmare on Elm Streetz//h//e/l//l/os   Friday the 13thz//h//e//l//l//os   I Know What You Did Last Summer/s   Screamz//s   Child's Playz///s   The Prowlerz////s   Black Christmasz(everything/is/better/with/slashes///////s   Maniac	   Tr{   rs   r?   rm   rG   r   N)r   r   rX   r   rt   r   rf   )r   r   r  r  r(  ouri4ouri5ouri6ouri7ouri8ouri9r_   s               r$   test_slasher_horror_filmTestRm.test_slasher_horror_filmn  s1    ++-J*5'3  5E *6'C  EE *9'9  ;E *;'I  KE *-'0  2E *.'7  9E */'5  7E *0'9  ;E >  E
 !!
!!*a4!@
 ;u.;u.;u.;u.;$fUm4;$fUm4;$fUm4;$fUm4;$fUm4
 	""	tT4
+,+
+, # .r'   z*GCS versioning headers not supported by S3c                     U R                  5       nU R                  USS9nU R                  SSS[        U5      /SSS9nU R                  (       a  U R                  US	5        gU R                  US
5        g)z?Test for '-h x-goog-if-generation-match:value rm' of an object.r   r   z-hz x-goog-if-generation-match:12345rm   TrA   r   z)pre-conditions you specified did not holdzPreconditionException: 412N)r   r   rH   rt   r   assertRegexr   s       r$   test_rm_failing_precondition#TestRm.test_rm_failing_precondition  s     ""$J"":"?J^^	14	j			  F
 
vKL
v<=r'   c                 ^   U R                  5       nU R                  USSS9nU R                  USSS9  U R                  USSS9nU R                  5       nU R                  USS	S9nU R                  (       a"  U R                  US
SS9  U R                  USSS9  [	        U5      < S[        U5      < 3[	        U5      < S[        U5      < 3[	        U5      < S[        U5      < 3/nSR                  U5      nU R                  SS/UUS9  U R                  USSS9  U R                  USSS9  g)zTests rm with the -I option.ri   s   foocontentsr   rj   s   barcontentsrk   s   bazcontentsmoos   moocontentsr}   Tr{   rA   rs   rp   rm   r   )r_   r=   r   N)r   r   rX   r   rt   r   r0   rf   )r   r  r  r(  r  r.  r_   r=   s           r$   test_stdin_argsTestRm.test_stdin_args  sa   &&(E*/'5  7E 	"'-  / */'5  7E &&(E*/'5  7E !!
!!%d!;
!!%d!; ;u.;u.;u.
 II'(E""D$<5F). # 0 	qD9qD9r'   c                     U R                  SSU R                  < SU R                  < 3/SSS9nU R                  (       a!  U R	                  SU;   =(       d    SU;   5        g U R                  S	U5        g )
Nrm   -rfr  TrA   r   r   r   zEncountered non-existent bucket)rH   rY   nonexistent_bucket_namer   r   r[   )r   r   s     r$   $test_rm_nonexistent_bucket_recursive+TestRm.test_rm_nonexistent_bucket_recursive  sq    ^^e**D,H,HI +/,-  /F 
oo&&0LNf4LM
mm5v>r'   c                    U R                  5       n[        US5      n[        US5      nU R                  SSX#/SSS9nU R                  (       a"  U R	                  SR                  X#5      U5        g U R	                  S	U5        g )
Nnonexistent1nonexistent2rm   r?  TrA   r   z5The following URLs matched no objects or files:
{}
{}z%2 files/objects could not be removed.)r   rt   rH   r   r[   format)r   r   nonexistent_object1nonexistent_object2r   s        r$   $test_rm_multiple_nonexistent_objects+TestRm.test_rm_multiple_nonexistent_objects  s    ""$Jz>:z>:^^	u)?  F 
mm
C
J
J!89?A mm;VDr'   r   )NNN)"__name__
__module____qualname____firstlineno____doc__r%   r   rf   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r  r   r$  r)  r4  r8  r<  rA  rI  __static_attributes__r   r'   r$   r   r   0   s    )(($ 3726&*	jX ?D? K
9)V?6M1B.,/ ,6,(,( AB3 C3j*</  < =.=.&I.  < =4.=4.l 9:> ;>:@?Er'   r   c                   b    \ rS rSrSrS r\R                  R                  \	S5      S 5       r
Srg)TestRmUnitTestsWithShimi  z#Unit tests for gsutil rm with shim.c                    U R                  5       n[        SS/5         [        SSS.5         U R                  SSSS	S
[	        U5      /SS9nSR                  UR                  S   5      nU R                  SR                  [        R                  " S5      [	        U5      5      U5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nr   use_gcloud_storager   r   hidden_shim_modedry_runr   fake_dir(CLOUDSDK_CORE_PASS_CREDENTIALS_TO_GSUTILCLOUDSDK_ROOT_DIRrm   rG   z-Rrn   r   Treturn_log_handlerrp   infozEGcloud Storage Command: {} storage rm -r -r -a --continue-on-error {})r   r   r   
RunCommandrt   r0   messagesr[   rF  r   _get_gcloud_binary_path)r   r   mock_log_handler
info_liness       r$   test_shim_translates_flags2TestRmUnitTestsWithShim.test_shim_translates_flags  s    ""$J	GHJ 
K 6<)" 	  ??4tT*%56# + % YY/88@A
//5v11*=Z 0"#-		/	
K 
K	 	
K 
Ks#   CA=B;*C;
C		C
Cr=   c           	         U R                  5       nU R                  USS5      n[        U5      /UR                  l        [        SS/5         [        SSS.5         U R                  SS	/S
S9nSR                  UR                  S   5      nU R                  SR                  [        R                  " S5      5      U5        S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nri   abcdrT  rV  r   rY  rZ  rm   r   Tr]  rp   r_  z(Gcloud Storage Command: {} storage rm -I)r   r   rt   __iter__return_valuer   r   r`  r0   ra  r[   rF  r   rb  )r   
mock_stdinr   r   rc  rd  s         r$   test_shim_translates_stdin_flag7TestRmUnitTestsWithShim.test_shim_translates_stdin_flag  s    ""$J"":uf=J(,Z(8'9J$	GHJ 
K 6<)" 	
  ??4$>B + DYY/88@A
&:::FG		
K 
K	 	
K 
Ks%   C#A&CC#
C 	C##
C1r   N)rK  rL  rM  rN  rO  re  r   patchobjectsysrl  rP  r   r'   r$   rR  rR    s/    +/& ::S'" #r'   rR  )&rO  
__future__r   r   r   r   r.   r   rp  unittestr   gslib.exceptionr	   r
   gslib.tests.testcaseteststestcasegslib.tests.testcase.baser   )gslib.tests.testcase.integration_testcaser   gslib.tests.utilr  r   r   r   rt   r   r   gslib.utilsr   gslib.utils.retry_utilr   r]   GsUtilIntegrationTestCaser   ShimUnitTestBaserR  r   r'   r$   <module>r~     s    ( & %  ' 	 	 
  2 2 ' ' 7 ?   8 0 1 2 ! (M 
EX// 
ED(h77 (r'   