
    s                     j   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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r  SSKJr  SSKJr  SSKJr  SSKJ r   S r!S r" " S S\RF                  5      r$ " S S\RF                  5      r%g)a  Tests for gsutil naming logic.

The test code in this file runs against an in-memory storage service mock,
so runs very quickly. This is valuable for testing changes that impact the
naming rules, since those rules are complex and it's useful to be able to
make small incremental changes and rerun the tests frequently. Additional
end-to-end tests (which send traffic to the production Google Cloud Storage
service) are available via the gsutil test command.
    )absolute_import)division)print_function)unicode_literalsN)NotFoundException)ServiceException)CommandException)InvalidUrlError)NO_URLS_MATCHED_GENERIC)NO_URLS_MATCHED_TARGET)StorageUrlFromString)ObjectToURI)SetBotoConfigForTest)SetDummyProjectForUnitTest)unittest)UTF8)copy_helper)system_utilc                 h    U R                  S5        U R                  S5        U R                  5         g)z8Overwrite first byte in an open file and flush contents.r   xNseekwriteflushfps    *platform/gsutil/gslib/tests/test_naming.py
_Overwriter   ;   s!    ''!*((3-((*    c                 j    U R                  SS5        U R                  S5        U R                  5         g)z8Append a byte at end of an open file and flush contents.r      r   Nr   r   s    r   _Appendr"   B   s#    ''!Q-((3-((*r   c                       \ 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 rS rS r\R(                  " \R,                  S5      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%S! r&S" r'S# r(S$ r)S% r*S& r+S' r,S( r-S) r.S* r/S+ r0S, r1S- r2S. r3S/ r4S0 r5S1 r6S2 r7S3 r8S4 r9S5 r:S6 r;S7 r<S8 r=S9 r>S: r?S; r@S< rAS= rBS> rCS? rDS@ rESA rFSB rGSC rHSD rISE rJSF rKSG rLSH rMSI rNSJ rOSK rPSL rQSM rRSN rSSO rTSPrUgQ)RGsutilNamingTestsK   z#Unit tests for gsutil naming logic.c                    U R                  S[        R                  " [        S5      [        S5      5      5        U R                  S[        R                  " [        S5      [        S5      5      5        U R                  S[        R                  " [        S5      [        S5      5      5        U R                  S[        R                  " [        S5      [        S5      5      5        U R                  S[        R                  " [        S	5      [        S
5      5      5        U R                  S[        R                  " [        S5      [        S5      5      5        U R	                  5       n[
        R                  R                  US5      n[
        R                  " U5        U R                  [        U5      [        R                  " [        [        U5      5      [        [        US5      5      5      5        g)z*Tests GetPathBeforeFinalDir() (unit test).gs://zgs://bucket/zgs://bucket/objzgs://bucketzgs://bucket/dir/zgs://bucket/dir/objzgs://bucket/dirzgs://bucket/dir1zgs://bucket/*/dir2zgs://bucket/dir1/dir2/objzgs://bucket/dir1/dir2/dir3zgs://bucket/*/dir2/*/dir4z#gs://bucket/dir1/dir2/dir3/dir4/objsubdirobjN)
assertEqualr   GetPathBeforeFinalDirr   CreateTempDirospathjoinmkdirsuri)selfsrc_dirr(   s      r   testGetPathBeforeFinalDir+GsutilNamingTests.testGetPathBeforeFinalDirN   s   )) 0 !23	56
 	)) !34 !67	9:
 	)) !23 !67	9:
 	)) !67 !67	9:
 	)) !56 !<=	?@
 	$)) !<= !FG	IJ
   "GWW\\'8,FHHVW)) f. fe!45	78r   c                 f   U R                  SS9nU R                  5       nU R                  SU[        U5      /5        [	        U R                  [        US5      5      R                  SS95      nU R                  S[        U5      5        U R                  SUS   R                  R                  5        g	)
z-Tests copying one top-level file to a bucket.f0	file_namecp**Texpand_top_level_buckets   r   NCreateTempFileCreateBucket
RunCommandr1   list_test_wildcard_iteratorIterAllr*   lenroot_objectnamer2   src_filedst_bucket_uriactuals       r   testCopyingTopLevelFileToBucket1GsutilNamingTests.testCopyingTopLevelFileToBucketx   s    ""T"2H&&(NOOD8T.%9:;$$TD&" 	##*7D7#IKF 	QF$T6!900556r   c           	      n   U R                  SS9nU R                  SS9nU R                  5       nU R                  SX[        U5      /5        [	        S U R                  [        US5      5      R                  SS9 5       5      n[	        [        US5      [        US5      /5      nU R                  XT5        g	)
z)Tests copying multiple files to a bucket.r7   r8   f1r:   c              3   8   #    U  H  n[        U5      v   M     g 7fNstr.0us     r   	<genexpr>EGsutilNamingTests.testCopyingMultipleFilesToBucket.<locals>.<genexpr>   !      KJ1A J   r;   Tr<   Nr@   rA   rB   r1   setrD   rE   r*   )r2   	src_file0	src_file1rK   rL   expecteds         r    testCopyingMultipleFilesToBucket2GsutilNamingTests.testCopyingMultipleFilesToBucket   s    ##d#3I##d#3I&&(NOOD9n1EFG K44TD6" ##*7D7#IJK KF ^T"^T" H 	X&r   c           	      $   U R                  5       n[        R                  R                  US5      n[        R                  " U5        U R                  USSS9nU R                  5       nU R                  SU[        US5      /5        U R                  SU[        US5      /5        [        S U R                  [        US5      5      R                  5        5       5      n[        [        USS	5      [        USS5      /5      nU R                  Xe5        g
)zTests copying a nested file to a bucket subdir.

Tests that we correctly translate local FS-specific delimiters (\ on
Windows) to bucket delimiter (/).
r(   r)   r   )tmpdirr9   contentsr:   zsubdir/ac              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   HGsutilNamingTests.testCopyingNestedFileToBucketSubdir.<locals>.<genexpr>   s!      PO1A Or[   r;   aN)r,   r-   r.   r/   r0   r@   rA   rB   r1   r]   rD   IterObjectsr*   )r2   rd   r(   rJ   rK   rL   r`   s          r   #testCopyingNestedFileToBucketSubdir5GsutilNamingTests.testCopyingNestedFileToBucketSubdir   s    !FWW\\&(+FHHV""&EC"PH&&(NOOD8T.*%EFGOOD8T.(%CDE P44T.:>6@ AALOP PF ^Xs+^Xu- H 	X&r   c                    U R                  5       nU R                  5       nU R                  SSS9nU R                  SU[        US5      /5        U R                  SU[        US5      /5        U R                  SU[        US5      /5        U R                  SS[        US	S
5      [        U5      /5        [	        S U R                  [        US5      5      R                  SS9 5       5      n[	        [        US
S5      /5      nU R                  XT5        U R                  5       nU R                  5       nU R                  SU[        US5      /5        U R                  SU[        US5      /5        U R                  SU[        US5      /5        U R                  SS[        US	SS5      [        U5      /5        [	        S U R                  [        US5      5      R                  SS9 5       5      n[	        [        USS5      [        USS5      /5      nU R                  XT5        U R                  5       nU R                  SS[        USS	S5      [        U5      /5        [	        S U R                  [        US5      5      R                  SS9 5       5      n[	        [        USS5      [        USS5      /5      nU R                  XT5        U R                  5       n	U R                  5       n
U R                  SU[        U	S5      /5        U R                  SU[        U	S5      /5        U R                  SU[        U	S5      /5        U R                  SS[        U	SS	SS5      [        U
5      /5        [	        S U R                  [        U
S5      5      R                  SS9 5       5      n[	        [        U
SS5      [        U
SS5      /5      nU R                  XT5        g)zCEnsure wildcarded recursive cp in bucket subdirs behaves like Unix.foos   bar)r9   re   r:   zTest/sub-test/foozTest2/sub-test/foozTest3/sub-test/foo-R*zsub-testc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   EGsutilNamingTests.testCopyingBucketSubdirsToBucket.<locals>.<genexpr>   rZ   r[   r;   Tr<   zTest/dir1/dir2/foozTest2/dir1/dir2/foozTest3/dir1/dir2/bardir1dir2c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   rq      !      LK1A Kr[   barzTest*c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   rq      ru   r[   zdir1/test1/dir2/dir3/foozdir1/test2/dir2/dir3/foozdir1/test3/dir2/dir3/bardir3c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   rq      ru   r[   N)rA   r@   rB   r1   r]   rD   rE   r*   )r2   src_bucket_urirK   fpathrL   r`   src_bucket_uri2dst_bucket_uri2dst_bucket_uri3src_bucket_uri3dst_bucket_uri4s              r    testCopyingBucketSubdirsToBucket2GsutilNamingTests.testCopyingBucketSubdirsToBucket   s   &&(N&&(N%&AEOOD5$~7J"KLMOOD5$~7K"LMNOOD5$~7K"LMNOO		nc:	.	n		 
  K44TD6" ##*7D7#IJK KF DU;<=HX&'')O'')OOOD5$8L"MNOOOD5$8M"NOPOOD5$8M"NOPOOD_c662_ 
  L44TT6# $$+GTG$JKL LF _fe,_fe, H 	X&'')OOOD_gsF3_ 
  L44TT6# $$+GTG$JKL LF _fe,_fe, H 	X&'')O'')OOOud?,FGHJOOud?,FGHJOOud?,FGHJOOD_fc66:_ 
  L44TT6# $$+GTG$JKL LF _fe,_fe, H 	X&r   c                    U R                  5       nU R                  / SQS9nU R                  SSU[        U5      /5        [	        S U R                  [        US5      5      R                  SS9 5       5      n[        R                  R                  U5      S	   n[	        [        XS
5      [        XS5      [        XS5      [        XSSS5      /5      nU R                  XS5        g)z>Tests recursively copying absolute path directory to a bucket.)r7   rP   f2.txt)dir0rr   nested
test_filesr:   rn   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   GGsutilNamingTests.testCopyingAbsolutePathDirToBucket.<locals>.<genexpr>   rZ   r[   r;   Tr<   r>   r7   rP   r   r   rr   r   N)rA   r,   rB   r1   r]   rD   rE   r-   r.   splitr*   )r2   rK   src_dir_rootrL   
src_tmpdirr`   s         r   "testCopyingAbsolutePathDirToBucket4GsutilNamingTests.testCopyingAbsolutePathDirToBucket   s    &&(N%%E & GLOOD4tN/CDE K44TD6" ##*7D7#IJK KF |,Q/J^.^.^2^B	 H 	X&r   c           	      >   U R                  5       nU R                  S/S9nU R                  SSS[        U5      /US9  [	        S U R                  [        US5      5      R                  S	S
9 5       5      n[	        [        USS5      /5      nU R                  XC5        g)z9Tests recursively copying relative directory to a bucket.)r   rP   r   r:   rn   r   cwdc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   GGsutilNamingTests.testCopyingRelativePathDirToBucket.<locals>.<genexpr>  rZ   r[   r;   Tr<   rP   N)rA   r,   rB   r1   r]   rD   rE   r*   r2   rK   r3   rL   r`   s        r   "testCopyingRelativePathDirToBucket4GsutilNamingTests.testCopyingRelativePathDirToBucket  s    &&(N  ^,< =GOOD4n)=>GOL K44TD6" ##*7D7#IJK KF D678HX&r   c           	         U R                  5       nU R                  USSS9  U R                  S/S9nU R                  SS[        R
                  R                  SS	5      [        US
5      /US9  [        S U R                  [        US5      5      R                  SS9 5       5      n[        [        US5      [        US
S	S5      /5      nU R                  XC5        g)znTests recursively copying relative sub-directory to bucket subdir.

Subdir is signified by a $folder$ object.
zabc_$folder$ 
bucket_uriobject_namere   r   rr   rP   r   r:   rn   r   rr   abcr   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   ^GsutilNamingTests.testCopyingRelPathSubDirToBucketSubdirWithDollarFolderObj.<locals>.<genexpr>)  rZ   r[   r;   Tr<   rP   N)rA   CreateObjectr,   rB   r-   r.   r/   r1   r]   rD   rE   r*   r   s        r   9testCopyingRelPathSubDirToBucketSubdirWithDollarFolderObjKGsutilNamingTests.testCopyingRelPathSubDirToBucketSubdirWithDollarFolderObj  s     &&(N"0!  #   -C,D EGOO	rww||FF+	ne	$	&	  
  K44TD6" ##*7D7#IJK KF ^^,^UFD1 H 	X&r   c           	         U R                  5       nU R                  S/S9nU R                  SS[        R                  R                  SS5      [        US5      S-   /US	9  [        S
 U R                  [        US5      5      R                  SS9 5       5      n[        [        USSS5      /5      nU R                  XC5        g)zgTests recursively copying relative sub-directory to bucket subdir.

Subdir is signified by a / object.
r   r   r:   rn   r   rr   r   /r   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   `GsutilNamingTests.testCopyingRelativePathSubDirToBucketSubdirSignifiedBySlash.<locals>.<genexpr>@  rZ   r[   r;   Tr<   rP   NrA   r,   rB   r-   r.   r/   r1   r]   rD   rE   r*   r   s        r   ;testCopyingRelativePathSubDirToBucketSubdirSignifiedBySlashMGsutilNamingTests.testCopyingRelativePathSubDirToBucketSubdirSignifiedBySlash3  s    
 &&(N  -C,D EGOO		ff	%	ne	$s	*	,     K44TD6" ##*7D7#IJK KF D=>?HX&r   c           	      z   U R                  5       nU R                  S/S9nU R                  SS[        R                  R                  SS5      [        U5      /US9  [        S U R                  [        US	5      5      R                  S
S9 5       5      n[        [        USS5      /5      nU R                  XC5        g)z=Tests recursively copying relative sub-directory to a bucket.r   r   r:   rn   r   rr   r   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   JGsutilNamingTests.testCopyingRelativePathSubDirToBucket.<locals>.<genexpr>O  rZ   r[   r;   Tr<   rP   Nr   r   s        r   %testCopyingRelativePathSubDirToBucket7GsutilNamingTests.testCopyingRelativePathSubDirToBucketG  s    &&(N  -C,D EGOOtRWW\\&&1N#%    K44TD6" ##*7D7#IJK KF D678HX&r   c           
      t   U R                  5       nU R                  S/S9nSS[        R                  -  4 H  nU R	                  SSU[        U5      /US9  [        S U R                  [        US	5      5      R                  S
S9 5       5      n[        [        US5      /5      nU R                  XT5        M     g)z6Tests copying ./ to a bucket produces expected naming.rm   r   ..%sr:   rn   r   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   @GsutilNamingTests.testCopyingDotSlashToBucket.<locals>.<genexpr>_  $      MLa a&&Lr[   r;   Tr<   N)
rA   r,   r-   seprB   r1   r]   rD   rE   r*   )r2   rK   r3   rel_src_dirrL   r`   s         r   testCopyingDotSlashToBucket-GsutilNamingTests.testCopyingDotSlashToBucketV  s     &&(N  UG 4GURVV^,
oo
{D$89w  H M//d1$ %%,WdW%KLM Mf d>5123h
x( -r   c           	         U R                  5       nU R                  S/S9nU R                  SS[        R                  R                  USS5      [        U5      /5        [        S U R                  [        US5      5      R                  S	S
9 5       5      nU R                  S[        U5      5        U R                  [        USS5      US   5        g)zTests copying a directory containing 1 file to a bucket.

We test this case to ensure that correct bucket handling isn't dependent
on the copy being treated as a multi-source copy.
)r   rr   rm   r   r:   rn   r   rr   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   LGsutilNamingTests.testCopyingDirContainingOneFileToBucket.<locals>.<genexpr>t  s!      L $Ka3q66 $Kr[   r;   Tr<   r>   rm   r   N)rA   r,   rB   r-   r.   r/   r1   rC   rD   rE   r*   rF   )r2   rK   r3   rL   s       r   'testCopyingDirContainingOneFileToBucket9GsutilNamingTests.testCopyingDirContainingOneFileToBucketg  s     &&(N  -D,E FGOO		gvv	.	n		 
  L4#?#?^T"$$$+GTG$J$K L MFQF$T.&%8&)Dr   c                 @   U R                  5       nU R                  S/S9n[        U5      S-   n[        U5      S-   nX44 HJ  n U R                  S[        R
                  R                  US5      U/5        U R                  SU-  5        ML     g ! [         a     M\  f = f)Nrm   r   z/.z/..r:   zExpected InvalidUrlError for %s)	rA   r,   r1   rB   r-   r.   r/   failr
   )r2   rK   r3   object_named_dotobject_named_dotdotr   s         r   testCopyDotFilesToBucket*GsutilNamingTests.testCopyDotFilesToBuckety  s    &&(N  eI 6GN+d2~.6(>rww||GU;[IJ		3kAB ?  s   AB
BBc           	         U R                  SS/S9nU R                  5       n[        S/5         U R                  SS[	        U5      U/5        SSS5        [        S U R                  U< [        R                  < S	35      R                  S
S9 5       5      n[        [	        X!R                  S5      [	        X!R                  SS5      /5      nU R                  XC5        g! , (       d  f       N= f)z+Tests copying from a bucket to a directory.rm   dir/foo2test_objectsGSUtilcheck_hashesneverr:   rn   Nc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   ;GsutilNamingTests.testCopyingBucketToDir.<locals>.<genexpr>  !      GF1A Fr[   r;   Tr<   dirfoo2)rA   r,   r   rB   r1   r]   rD   r-   r   rE   bucket_namer*   )r2   rz   dst_dirrL   r`   s        r   testCopyingBucketToDir(GsutilNamingTests.testCopyingBucketToDir  s    &&UJ4G&HN  "G	BC	D
oodT4#7AB 
E G44bff&wwEFG GF W00%8W00%@ H 	X& 
E	Ds   C  
C.z)os.symlink() is not available on Windows.c           
         U R                  5       nU R                  5       nU R                  5       n[        R                  R	                  US5      n[        R
                  " U5        U R                  USS9nU R                  USS9  [        R
                  " [        R                  R	                  US5      5        [        R                  " U[        R                  R	                  US5      5        U R                  SSU[        U5      /SSS	9n[        S
 U R                  [        US5      5      R                  SS9 5       5      n[        U[        R                  R                  U5      S[        R                  R                  U5      5      n[        U/5      n	U R                  X5        S[        R                  R	                  US5      -  n
U R                  XR                   S   SU
< S[#        UR                   5      < 35        g)z5Tests that cp warns when copying a symlink directory.r(      foo)rd   re   
symlinkdirr:   -rr>   T)debugreturn_log_handlerc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   @GsutilNamingTests.testCopyingSymlinkDirectory.<locals>.<genexpr>  !      ,+A 	A+r[   r;   r<   zSkipping symlink directory "%s"info"z)" not found in mock_log_handler["info"]: N)rA   r,   r-   r.   r/   r0   r@   symlinkrB   r1   r]   rD   rE   basenamer*   assertInmessagesrT   )r2   r   rd   tmpdir2r(   fpath1mock_log_handlerrL   expected_object_pathr`   desired_msgs              r   testCopyingSymlinkDirectory-GsutilNamingTests.testCopyingSymlinkDirectory  s    ""$J!F  "G WW\\&(+FHHV   @Fw8HHRWW\\&,/0JJwV\:;tVT*-. ' !  ,--d:t.DEMM%) N +, ,F  
BGG,<,<V,Dh " 0 0 8:()*HX&477<<56KMM..v6	c*334	67r   c           	         U R                  SS/S9nU R                  5       nU R                  SS[        U5      [        U5      /5        [        S U R	                  [        US5      5      R                  SS	9 5       5      n[        [        X!R                  S5      [        X!R                  S
S5      /5      nU R                  XC5        g)z1Tests copying from a bucket-only URI to a bucket.rm   r   r   r:   rn   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   >GsutilNamingTests.testCopyingBucketToBucket.<locals>.<genexpr>  rZ   r[   r;   Tr<   r   r   N)rA   rB   r1   r]   rD   rE   r   r*   r2   rz   rK   rL   r`   s        r   testCopyingBucketToBucket+GsutilNamingTests.testCopyingBucketToBucket  s    &&UJ4G&HN&&(NOOD4n!5tN7KLM K44TD6" ##*7D7#IJK KF ^77?^77G H 	X&r   c           	         U R                  SS/S9nU R                  5       nU R                  SSX/5        [        S U R                  U< [        R
                  < S35      R                  SS	9 5       5      n[        R                  R                  U5      S
   n[        [        X$S5      [        X$SS5      /5      nU R                  XS5        g)z.Tests copying from a directory to a directory.rm   )r   r   r   r:   rn   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   DGsutilNamingTests.testCopyingDirectoryToDirectory.<locals>.<genexpr>  r   r[   r;   Tr<   r>   r   r   N)r,   rB   r]   rD   r-   r   rE   r.   r   r1   r*   )r2   r3   r   rL   src_dir_baser`   s         r   testCopyingDirectoryToDirectory1GsutilNamingTests.testCopyingDirectoryToDirectory  s      UO,D EG  "GOOD423 G44bff&wwEFG GF 77==)!,LWE*WE62 H 	X&r   c                    U R                  / SQS9nU R                  5       nU R                  SU< [        R                  < S3U/5        [	        S U R                  U< [        R                  < S35      R                  SS9 5       5      n[	        [        US	5      [        US
5      /5      nU R                  XC5        g)z:Tests copying containing files and a directory without -R.)rm   rv   )d1f2)d2f3)d3d4f4r   r:   ro   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   GGsutilNamingTests.testCopyingFilesAndDirNonRecursive.<locals>.<genexpr>  r   r[   r;   Tr<   rm   rv   N)	r,   rB   r-   r   r]   rD   rE   r1   r*   )r2   r3   r   rL   r`   s        r   "testCopyingFilesAndDirNonRecursive4GsutilNamingTests.testCopyingFilesAndDirNonRecursive  s       -  G   "GOODgrvv6@A G44bff&wwEFG GF D%($w*>?@HX&r   c                 f   U R                  SS9nU R                  5       nU R                  SX/5        [        U R	                  U< [
        R                  < S35      R                  SS95      nU R                  S[        U5      5        U R                  [        US5      [        US   5      5        g	)
z&Tests copying one file to a directory.rm   r8   r:   ro   Tr<   r>   r   N)r@   r,   rB   rC   rD   r-   r   rE   r*   rF   r1   rT   )r2   rJ   r   rL   s       r   testCopyingFileToDir&GsutilNamingTests.testCopyingFileToDir  s    ""U"3H  "GOOD8-.$$'	))0$)OQF 	QF$T'5)3vay>:r   c                 l   U R                  SS9nU R                  5       nU R                  SU[        U5      S-   /5        [	        U R                  [        US5      5      R                  SS95      nU R                  S[        U5      5        U R                  S	US
   R                  R                  5        g)zATests copying a file to an object containing consecutive slashes.r7   r8   r:   z//objr;   Tr<   r>   z/objr   Nr?   rI   s       r   -testCopyingFileToObjectWithConsecutiveSlashes?GsutilNamingTests.testCopyingFileToObjectWithConsecutiveSlashes  s    ""T"2H&&(NOOD8T.%9G%CDE$$TD&" 	##*7D7#IKF 	QF$VVAY22778r   c           	         U R                  SSS9nU R                  5       nU R                  SSSU[        U5      /5        [	        U R                  [        US5      5      R                  SS	95      nU R                  S
[        U5      5        US   R                  nU R                  SUR                  5        U R                  SUR                  5        U R                  S[        US5      /SS9n[        R                  " [        R                  " [        R                   " U5      5      SS9n U R                  UR#                  5       S5        UR%                  5         g! UR%                  5         f = f)z4Tests copying one file with compression to a bucket.s	   plaintextr   )re   r9   r:   z-ztxtro   Tr<   r>   r   gzipcatreturn_stdoutrb)fileobjmodeN)r@   rA   rB   r1   rC   rD   rE   r*   rF   rG   rH   contentEncodingr  GzipFilesixBytesIOensure_binaryreadclose)r2   rJ   rK   rL   
actual_objstdoutfs          r   !testCopyingCompressedFileToBucket3GsutilNamingTests.testCopyingCompressedFileToBucket  s?   ""LH"MH&&(NOO	uh^ 45 $$TC&! 	"")'4'"HJF 	QF$&&JXz/VZ778__UT.(%C$D+/  1F 	ckk#*;*;F*CD4PA
qvvx.ggiaggis   - E E0c                 |   U R                  S/S9nU R                  5       nU R                  S[        US5      [        U5      /5        [        U R	                  [        US5      5      R                  SS95      nU R                  S[        U5      5        U R                  SUS   R                  R                  5        g	)
z%Tests copying an object to an object.r)   r   r:   ro   Tr<   r>   r   N)
rA   rB   r1   rC   rD   rE   r*   rF   rG   rH   )r2   rz   rK   rL   s       r   testCopyingObjectToObject+GsutilNamingTests.testCopyingObjectToObject  s    &&UG&<N&&(NOOD46^8LMN$$TC&! 	"")'4'"HJF 	QF$UF1I11667r   c           	      X   U R                  S/S9nU R                  S/S9nU R                  S[        US5      SUR                  -  /5        [	        S U R                  [        US5      5      R                  SS	9 5       5      n[	        [        US5      /5      nU R                  XC5        g
)z;Tests copying an object to an object using a dest wildcard.r)   r   dstobjr:   z%s*c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   OGsutilNamingTests.testCopyingObjectToObjectUsingDestWildcard.<locals>.<genexpr>'  s!      JI1A Ir[   ro   Tr<   N)rA   rB   r1   urir]   rD   rE   r*   r   s        r   *testCopyingObjectToObjectUsingDestWildcard<GsutilNamingTests.testCopyingObjectToObjectUsingDestWildcard   s    &&UG&<N&&XJ&?NOOD.%0^///12  J44TC6! "")'4'"HIJ JF D234HX&r   c           
      (   U R                  S/S9nU R                  S/S9nU R                  5       n[        S/5         U R                  SS[	        US5      [
        R                  R                  US5      U/5        S	S	S	5        [        S
 U R                  [
        R                  R                  US5      5      R                  SS9 5       5      n[        [	        US5      [	        US5      /5      nU R                  XT5        g	! , (       d  f       N= f)z/Tests copying objects and files to a directory.rP   r   r   r   r   r:   rn   r;   Nc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   AGsutilNamingTests.testCopyingObjsAndFilesToDir.<locals>.<genexpr>9  s!      DC1A Cr[   Tr<   )rA   r,   r   rB   r1   r-   r.   r/   r]   rD   rE   r*   )r2   rz   r3   r   rL   r`   s         r   testCopyingObjsAndFilesToDir.GsutilNamingTests.testCopyingObjsAndFilesToDir-  s   &&TF&;N  TF 3G  "G	BC	D
ood

~t
$
'',,w
%w 	 
E  D44RWW\\T6 #GTGBCD DF D$'gt)<=>HX& 
E	Ds   ?D
Dc           	         U R                  S/S9nU R                  5       nS GH  n[        S/5         U R                  S[	        US5      SU-  /US9  SSS5        [        5       n[        R                  " U5       Ht  u  pVnU H1  nUR                  [        R                  R                  XX5      5        M3     U H1  n	UR                  [        R                  R                  XY5      5        M3     Mv     [        [        R                  R                  US5      /5      n
U R                  X5        GM     g! , (       d  f       N= f)	zBTests that copying an object to . or ./ downloads to correct name.rP   r   r   r   r   r:   r   r   N)rA   r,   r   rB   r1   r]   r-   walkaddr.   r/   r*   )r2   rz   r   
final_charrL   dirnamedirnames	filenames
subdirnamefilenamer`   s              r   testCopyingObjToDot%GsutilNamingTests.testCopyingObjToDot?  s   &&TF&;N  "G
!D EFtND9$z13# 	 	% G uf*,'''*:
&'Y"J
**RWW\\'6
7 #!H
**RWW\\'4
5 " +;
 bggll7D123h
x(  FFs   !D55
E	c           	         U R                  S/S9nU R                  S/S9nU R                  5       nU R                  SS[        US5      U< [        R
                  < S3[        U5      /5        [        S U R                  [        US5      5      R                  S	S
9 5       5      n[        [        US5      [        US5      /5      nU R                  XT5        g)z,Tests copying objects and files to a bucket.rP   r   r   r   r:   rn   r;   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   DGsutilNamingTests.testCopyingObjsAndFilesToBucket.<locals>.<genexpr>^  rZ   r[   Tr<   N)
rA   r,   rB   r1   r-   r   r]   rD   rE   r*   r2   rz   r3   rK   rL   r`   s         r   testCopyingObjsAndFilesToBucket1GsutilNamingTests.testCopyingObjsAndFilesToBucketS  s    &&TF&;N  TF 3G&&(NOOD^T"RVV$^	   K44TD6" ##*7D7#IJK KF D.^T0JKLHX&r   c           	      l   U R                  5       nU R                  US-   SS9  U R                  5       nU R                  SSUS-   [	        US5      /5        [        S U R                  [	        US	5      5      R                  S
S9 5       5      n[        [	        US5      /5      nU R                  XC5        g)a7  Tests copying a directory with a single file recursively to a bucket.

The file should end up in a new bucket subdirectory with the file's
directory structure starting below the recursive copy point, as in Unix cp.

Example:
  filepath: dir1/dir2/foo
  cp -r dir1 dir3
  Results in dir3/dir2/foo being created.
z
/dir1/dir2rm   rd   r9   r:   rn   z/dir1rx   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   RGsutilNamingTests.testCopyingSubdirRecursiveToNonexistentSubdir.<locals>.<genexpr>v  rZ   r[   r;   Tr<   zdir3/dir2/fooN	r,   r@   rA   rB   r1   r]   rD   rE   r*   r2   r3   rK   rL   r`   s        r   -testCopyingSubdirRecursiveToNonexistentSubdir?GsutilNamingTests.testCopyingSubdirRecursiveToNonexistentSubdire  s       "Gw5G&&(NOOD7W,.&134  K44TD6" ##*7D7#IJK KF D9:;HX&r   c           	      >   U R                  SS9nU R                  5       nU R                  SSU[        US5      /5        [	        S U R                  [        US5      5      R                  SS	9 5       5      n[	        [        US5      /5      nU R                  XC5        g
)zTests copying a file with -R.rm   r8   r:   rn   dir/fooc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   BGsutilNamingTests.testCopyingFileToDirRecursive.<locals>.<genexpr>  rZ   r[   r;   Tr<   Nr\   r2   rJ   rK   rL   r`   s        r   testCopyingFileToDirRecursive/GsutilNamingTests.testCopyingFileToDirRecursive|  s    ""U"3H&&(NOOD44	+JKL K44TD6" ##*7D7#IJK KF D345HX&r   c           	      B   U R                  SS9nU R                  5       nU R                  SU[        US5      S-   /5        [	        S U R                  [        US5      5      R                  SS	9 5       5      n[	        [        US
5      /5      nU R                  XC5        g)zfTests copying a file to a non-existent directory.

Should create the directory and add the file to it
rm   r8   r:   r   r   c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   DGsutilNamingTests.testCopyingFileToNonExistentDir.<locals>.<genexpr>  rZ   r[   r;   Tr<   rI  Nr\   rL  s        r   testCopyingFileToNonExistentDir1GsutilNamingTests.testCopyingFileToNonExistentDir  s    
 ""U"3H&&(NOOD8T.%%@3%FGH K44TD6" ##*7D7#IJK KF D345HX&r   c           
         U R                  5       nU R                  USS9nU R                  USS9nU R                  5       nU R                  SSX#[	        US5      /5        [        S U R                  [	        US5      5      R                  S	S
9 5       5      n[        [	        US5      [	        US5      /5      nU R                  Xe5        g)z%Tests copying multiple files with -R.rm   rA  rv   r:   rn   rI  c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   KGsutilNamingTests.testCopyingMultipleFilesToDirRecursive.<locals>.<genexpr>  rZ   r[   r;   Tr<   zdir/foo/foozdir/foo/barNrD  )r2   r3   r_   	src_file2rK   rL   r`   s          r   &testCopyingMultipleFilesToDirRecursive8GsutilNamingTests.testCopyingMultipleFilesToDirRecursive  s      "G##7e#DI##7e#DI&&(NOOtYNI.01  K44TD6" ##*7D7#IJK KF ^]+^]+ H 	X&r   c                     U R                  SS9nU R                  5       n U R                  SX/5        U R                  S5        g! [         a*  nU R	                  [
        UR                  5         SnAgSnAff = f)z%Tests copying a directory without -R.r>   r   r:   %Did not get expected CommandExceptionN)r,   rB   r   r	   r   r   reason)r2   r3   r   es       r   "testAttemptDirCopyWithoutRecursion4GsutilNamingTests.testAttemptDirCopyWithoutRecursion  sl      A .G  "G7
oodW./
ii78 7
mm+QXX667s   $A 
A: A55A:c                    U R                  SS/S9nU R                  5       n[        S/5         U R                  S[	        US5      U/5        SSS5        [        U R                  U< [        R                  < S35      R                  SS	95      nU R                  S
[        U5      5        U R                  [	        US5      [        US   5      5        g! , (       d  f       N= f)zBTests copying a file and subdirectory of the same name without -R.rP   zf1/f2r   r   r:   Nro   Tr<   r>   r   )rA   r,   r   rB   r1   rC   rD   r-   r   rE   r*   rF   rT   )r2   rz   r   rL   s       r   %testNonRecursiveFileAndSameNameSubdir7GsutilNamingTests.testNonRecursiveFileAndSameNameSubdir  s    &&T7O&DN  "G	BC	D
oodT.$7AB 
E$$'	))0$)OQF 	QF$T'4(#fQi.9 
E	Ds   C
C#c                     U R                  5       n U R                  SS[        U5      /5        U R                  S5        g! [         a&  nU R                  SUR                  5         SnAgSnAff = f)z8Attempts to copy a src specified as a provider-only URI.r:   r'   r[  zprovider-onlyNrA   rB   r1   r   r	   r   r\  r2   rz   r]  s      r   !testAttemptCopyingProviderOnlySrc3GsutilNamingTests.testAttemptCopyingProviderOnlySrc  s_    &&(N/
oodWd>&:;<
ii78 /
mmOQXX../s   .A 
A1A,,A1c                     U R                  5       n U R                  SX/5        U R                  S5        g! [         a&  nU R	                  SUR
                  5         SnAgSnAff = f)z"Attempts to an object atop itself.r:   r[  zare the same file - abortN)r@   rB   r   r	   r   r\  )r2   rJ   r]  s      r   'testAttemptCopyingOverlappingSrcDstFile9GsutilNamingTests.testAttemptCopyingOverlappingSrcDstFile  sY    ""$H;
oodX01
ii78 ;
mm/::;s   $7 
A'A""A'c                    U R                  SS9n U R                  S[        US5      [        US5      /5        U R                  S5        g	! [         a5  nU R                  UR                  R                  S5      S5         S	nAg	S	nAff = f)
z3Attempts to copy where dst wildcard matches >1 obj.r!   r   r:   obj0ro   r[  zmust match exactly 1 URLN)rA   rB   r1   r   r	   assertNotEqualr\  findre  s      r   &testAttemptCopyingToMultiMatchWildcard8GsutilNamingTests.testAttemptCopyingToMultiMatchWildcard  s    &&A&6NI
oodNF3NC023 ii78 I
!((--(BCRHHIs   9A 
B
+BB
c                 
   U R                  SS9nU R                  5       n U R                  SS[        US5      U/5        U R	                  S5        g! [
         a&  nU R                  SUR                  5         SnAgSnAff = f)	z,Attempts to copy multiple objects to a file.r!   r   r:   rn   ro   r[  z!must name a directory, bucket, orN)rA   r@   rB   r1   r   r	   r   r\  )r2   rz   dst_filer]  s       r   !testAttemptCopyingMultiObjsToFile3GsutilNamingTests.testAttemptCopyingMultiObjsToFile  sz    &&A&6N""$HC
oodT4#<hGH
ii78 C
mm7BBCs   0A 
BA==Bc                 J   U R                  5       nU R                  USS9  U R                  USS9  U R                  5       n U R                  SS[	        U5      U/5        U R                  S5        g! [         a&  nU R                  SUR                  5         SnAgSnAff = f)	z>Attempts to copy objects that cause a file/directory conflict.rh   )r   r   zb/ar:   rn   r[  z,exists where a directory needs to be createdN)	rA   r   r,   rB   r1   r   r	   rn  r\  )r2   r   r   r]  s       r   %testAttemptCopyingWithFileDirConflict7GsutilNamingTests.testAttemptCopyingWithFileDirConflict  s     ""$J=?  "G$
oodT4
#3W=>
ii78 $
H(($ $$s   /A2 2
B"<BB"c                 v   U R                  5       n[        R                  " [        R                  R	                  US5      5        U R                  SSS9n U R                  S[        U5      US-   /5        U R                  S5        g! [         a&  nU R                  SUR                  5         SnAgSnAff = f)	zAAttempts to copy an object that causes a directory/file conflict.r   rv   )r   re   r:   r   r[  z"where the file needs to be createdN)r,   r-   r0   r.   r/   r   rB   r1   r   r	   rn  r\  )r2   rd   src_urir]  s       r   %testAttemptCopyingWithDirFileConflict7GsutilNamingTests.testAttemptCopyingWithDirFileConflict  s     !FHHRWW\\&%()EEBGJ
oodT']FSL9:
ii78 J
>IIJs   1B 
B8B33B8c           	      2   U R                  S/S9nU R                  S[        US5      [        US5      /5        [        S U R	                  [        US5      5      R                  SS	9 5       5      n[        [        US5      /5      nU R                  X25        g
)z{Attempts to move using src wildcard that overlaps dest object.

We want to ensure that this doesn't stomp the result data.
oldr   mvzold*newc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   AGsutilNamingTests.testWildcardMoveWithinBucket.<locals>.<genexpr>  rZ   r[   r;   Tr<   NrA   rB   r1   r]   rD   rE   r*   )r2   rK   rL   r`   s       r   testWildcardMoveWithinBucket.GsutilNamingTests.testWildcardMoveWithinBucket  s    
 &&UG&<NOOD.&1.%023  K44TD6" ##*7D7#IJK KF D/01HX&r   c                     U R                  S/S9n U R                  S[        US5      /5        g! [         a&  nU R	                  SUR
                  5         SnAgSnAff = f)zATest ls of non-existent obj that matches prefix of existing objs.obj_with_suffixr   lsr)   zmatched no objectsN)rA   rB   r1   r	   r   r\  re  s      r   %testLsNonExistentObjectWithPrefixName7GsutilNamingTests.testLsNonExistentObjectWithPrefixName  s^     &&5F4G&HN4
oodT.%89: 4
mm(!((334s   0 
A AA c                    U R                  / SQS9nU R                  S[        US5      /SS9n[        [        US5      [        USS	5      [        USS
5      UR                  -   [        USS	5      [        USS5      /5      nUR                  S5        [        UR                  S5       Vs/ s H  oDR                  5       PM     sn5      nU R                  X55        gs  snf )z2Test that ls of a bucket returns expected results.foo1zd0/foo2z
d1/d2/foo3r   r  ro   Tr  r  r   :r   d0r   r   
N	rA   rB   r1   r]   delimr1  r   stripr*   r2   rz   outputr`   linerL   s         r   testLsBucketNonRecursive*GsutilNamingTests.testLsBucketNonRecursive  s    &&6 ' 8N__TD$=#>+/  1F^V$^T3'^T4(>+?+??^T3'^T6* H LL6<<+=>+=4**,+=>?FX& ?s   *Cc                    U R                  / SQS9nU R                  SS[        US5      /SS9n[        [        US5      [        US	S
5      [        US	SS
5      [        US	SS5      [        USS
5      [        USS5      /5      nUR	                  S5        [        UR                  S5       Vs/ s H  oDR                  5       PM     sn5      nU R                  X55        gs  snf )z5Test that ls -R of a bucket returns expected results.r  r   r  rn   ro   Tr  r  r   r  r   foo3r  r   r   r  NrA   rB   r1   r]   r1  r   r  r*   r  s         r   testLsBucketRecursive'GsutilNamingTests.testLsBucketRecursive,  s    &&6 ' 8N__TD$~s*C#D+/  1F^V$^T3'^T4-^T40^T3'^T6* H LL6<<+=>+=4**,+=>?FX& ?s   ,Cc                 H   U R                  S/S9nU R                  SS[        US5      /SS9n[        [        US5      /5      nUR	                  S5        [        UR                  S	5       Vs/ s H  oDR                  5       PM     sn5      nU R                  X55        g
s  snf )zBTest that ls -R of a bucket with an object that has leading slash.r7   r   r  rn   ro   Tr  r   r  Nr  )r2   rK   r  r`   r  rL   s         r   /testLsBucketRecursiveWithLeadingSlashObjectNameAGsutilNamingTests.testLsBucketRecursiveWithLeadingSlashObjectName>  s    &&TF&;N__TD$~s*C#D+/  1FD./0HLL6<<+=>+=4**,+=>?FX& ?s   -Bc                 |   U R                  SS/S9nU R                  S[        US5      /SS9n[        [        USS5      [        USS	5      UR                  -   /5      nUR                  S
5        [        UR                  S5       Vs/ s H  oDR                  5       PM     sn5      nU R                  X55        gs  snf )z9Test that ls of a bucket subdir returns expected results.src_subdir/foosrc_subdir/nested/foo2r   r  
src_subdirTr  rm   r   r   r  Nr  r  s         r   testLsBucketSubdirNonRecursive0GsutilNamingTests.testLsBucketSubdirNonRecursiveH  s    &&&(@A ' CN__TD$F#G+/  1F^\51	nlH	58L8L	L H LL6<<+=>+=4**,+=>?FX& ?s   B9c                    U R                  SS/S9nS H  nU R                  SS[        US5      U-   /SS	9n[        [        USS
5      [        USS5      [        USSS
5      [        USSS5      /5      nUR	                  S5        [        UR                  S5       Vs/ s H  oUR                  5       PM     sn5      nU R                  XF5        M     gs  snf )z<Test that ls -R of a bucket subdir returns expected results.r  r  r   r/  r  rn   r  Tr  r  rm   r   r   r   r  Nr  )r2   rz   r2  r  r`   r  rL   s          r   testLsBucketSubdirRecursive-GsutilNamingTests.testLsBucketSubdirRecursiveV  s    &&&(@A ' CN

tNL9JFG  f 
~|S
1
~|U
3
~|Xs
;
~|Xv
>	 	h ll2V\\$-?@-?TJJL-?@Af
x(   As   C
c                 `    U R                  5       nU R                  SSS[        U5      /5        g)/Test that the 'acl set' command basically runs.aclr]   privateNrA   rB   r1   r2   rz   s     r   testSetAclOnBucketRuns(GsutilNamingTests.testSetAclOnBucketRunsh  s,    
 &&(NOOEE9d>.BCDr   c           	          U R                  S/S9n[        5          U R                  SSS[        U5      SS S-   /5        SSS5        g! , (       d  f       g= f)	zATest that 'acl set' basically runs against wildcard-named bucket.r7   r   r  r]   r  Nro   )rA   r   rB   r1   r  s     r   #testSetAclOnWildcardNamedBucketRuns5GsutilNamingTests.testSetAclOnWildcardNamedBucketRunsp  sU    
 &&TF&;N	#	%
oo
)T.1#26<
=? 
&	%	%s   %A		
Ac           	      b    U R                  S/S9nU R                  SSS[        US5      /5        g)r  r7   r   r  r]   r  ro   Nr  r  s     r   testSetAclOnObjectRuns(GsutilNamingTests.testSetAclOnObjectRuns{  s3    &&TF&;NOOEE9d>3.GHIr   c                 `    U R                  5       nU R                  SSS[        U5      /5        g)z2Test that the 'defacl set' command basically runs.defaclr]   r  Nr  r  s     r   testSetDefAclOnBucketRuns+GsutilNamingTests.testSetDefAclOnBucketRuns  s*    &&(NOOHuin1EFGr   c           	          U R                  5       n U R                  SSS[        US5      /5        U R                  S5        g! [         a&  nU R                  SUR                  5         SnAgSnAff = f)zDTest that the 'defacl set' command fails when run against an object.r  r]   r  ro   r[  zURL must name a bucketNrd  re  s      r   testSetDefAclOnObjectFails,GsutilNamingTests.testSetDefAclOnObjectFails  sd    &&(N8
ooh	43L MN
ii78 8
mm,ahh778s   0A 
A3A..A3c                 d   U R                  SS9nU R                  5       nU R                  SU[        U5      /SS9  [	        U R                  [        US5      5      R                  SS95      nU R                  S	[        U5      5        U R                  SUS
   R                  R                  5        g)zTests using gsutil -D option.r7   r8   r:      )r   ro   Tr<   r>   r   Nr?   rI   s       r   testMinusDOptionWorks'GsutilNamingTests.testMinusDOptionWorks  s    ""T"2H&&(NOOD8T.%9:!OD$$TC&! 	"")'4'"HJF 	QF$T6!900556r   c                    U R                  / SQS9nU R                  / SQS9nU R                  SS/S9n[        S5       HS  u  pEU R                  SS	[	        US
5      [
        R                  R                  US
5      [	        USU-  5      U-   /5        MU     [        S U R                  [	        US
5      5      R                  SS9 5       5      n[        5       n[        S5       HV  nUR                  [	        USU-  S5      5        [        S5       H%  nUR                  [	        USU-  SU-  5      5        M'     MX     U R                  Xv5        g)z?Tests copying flatly listed objects and files to bucket subdir.)r7   zd0/f1zd1/d2/f2r   )r   )r   r   )r   d5f5r   zdst_subdir0/existingzdst_subdir1/existingr/  r:   rn   r;   dst_subdir%dc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   NGsutilNamingTests.testFlatCopyingObjsAndFilesToBucketSubDir.<locals>.<genexpr>  rZ   r[   Tr<   r!   existing   zf%dN)rA   r,   	enumeraterB   r1   r-   r.   r/   r]   rD   rE   ranger1  r*   )	r2   rz   r3   rK   ir2  rL   r`   js	            r   )testFlatCopyingObjsAndFilesToBucketSubDir;GsutilNamingTests.testFlatCopyingObjsAndFilesToBucketSubDir  sX   &&4O&PN  ; ! =G&&,.DE ' GN #9-
ood

~t
$
'',,w
%
~~1
2Z
?	 	 .  K44TD6" ##*7D7#IJK KF uH1Xll4(:JGHQx!T..1*<eaiHI   	X&r   c                    U R                  SS/S9nU R                  SS/S9nU R                  SS/S9n[        S	5       GH  u  pEU R                  S
S[	        U5      U[	        USU-  5      U-   /5        [        S U R                  [	        USU-  S5      5      R                  SS9 5       5      n[        R                  R                  U5      S   nUR                  n[        [	        USU-  S5      [	        USU-  US5      [	        USU-  USS5      [	        USU-  US5      [	        USU-  USS5      /5      n	U R                  X5        GM     g)zDTests recursive copy of objects and files to existing bucket subdir.r7   	nested/f1r   dst_subdir0/existing_objdst_subdir1/existing_objr   r   r   r   r/  r:   rn   r  c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   XGsutilNamingTests.testRecursiveCopyObjsAndFilesToExistingBucketSubDir.<locals>.<genexpr>  !      EDQ#a&& Dr[   r;   Tr<   r>   existing_objr   rP   r   N)rA   r,   r  rB   r1   r]   rD   rE   r-   r.   r   r   r*   )
r2   rz   rK   r3   r  r2  rL   tmp_dirname
bucketnamer`   s
             r   3testRecursiveCopyObjsAndFilesToExistingBucketSubDirEGsutilNamingTests.testRecursiveCopyObjsAndFilesToExistingBucketSubDir  s   &&T;4G&HN&&02LM ' ON  T3C,D EG"9-
ood

~

~~1
2Z
? 	
  E66>>$$WdWCDE Ef GGMM'*1-k!--j
~~1>
B
~~1:t
D
~~1:x
N
~~1;
E
~~1;$
O 	h x(' .r   c                    U R                  S/S9nU R                  S/S9nSS[        R                  -   4 H  nU R	                  SSU[        R                  -   U-   [        US5      /5        [        S	 U R                  [        USS
5      5      R                  SS9 5       5      n[        [        USSS5      [        USS5      /5      nU R                  XT5        M     g)zDTests recursive copy of invalid path file to existing bucket subdir.)r   r7   r   dst_subdir/existing_objr   r   r:   rn   
dst_subdirc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   cGsutilNamingTests.testRecursiveCopyFileToExistingBucketSubDirInvalidSourceParent.<locals>.<genexpr>  s      21Q#a&& 1r[   r;   Tr<   r   r7   r  N)
r,   rA   r-   r   rB   r1   r]   rD   rE   r*   )r2   r3   rK   relative_path_stringrL   r`   s         r   >testRecursiveCopyFileToExistingBucketSubDirInvalidSourceParentPGsutilNamingTests.testRecursiveCopyFileToExistingBucketSubDirInvalidSourceParent  s      -=,> ?G&&5N4O&PN!$cBFFl 3
ood

BFF
1
1
~|
, 	
  266><688?+/ 9@ 9112 2f 
~|Xt
<
~|^
< 	h x( !4r   c                 ^   U R                  S/S9n[        R                  R                  US5      n[        R                  " U5        U R                  USS9  U R                  S/S9nSS[        R                  -   S	S	[        R                  -   4 Hx  nU R                  US
9   [        R                  R                  X$5      nU R                  [        5         U R                  SSUU[        US5      /5        SSS5        SSS5        Mz     g! , (       d  f       N= f! , (       d  f       M  = f)zFTests recursive copy of invalid paths files to existing bucket subdir.rP   r   r   r   rA  r  r   r   z..)r  r:   rn   r  N)r,   r-   r.   r/   r0   r@   rA   r   subTestassertRaisesr
   rB   r1   )r2   src_dir1src_dir2rK   r  invalid_parent_dirs         r   ?testRecursiveCopyFilesToExistingBucketSubDirInvalidSourceParentQGsutilNamingTests.testRecursiveCopyFilesToExistingBucketSubDirInvalidSourceParent  s    !!dV!4Hww||Hh/HHHXx48&&5N4O&PN!$cBFFlD$- H<<-A<BWW\\(I/
//$ ><0	!  0 CB !I 0/ CBs$   !5D!D7D
DD
D,	c                 2   U R                  SS/S9nU R                  SS/S9nU R                  5       nU R                  SS[        R                  R                  US	5      [        U5      [        US
5      /5        [        S U R                  [        US5      5      R                  SS9 5       5      n[        [        US
UR                  S5      [        US
UR                  SS5      [        US
S	S5      [        US
S	SS5      /5      nU R                  XT5        g)CTests recursive copy of objs + files to non-existent bucket subdir.r7   r  r   )parentr   )r  r   r   r   r:   rn   r  r  c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   [GsutilNamingTests.testRecursiveCopyObjsAndFilesToNonExistentBucketSubDir.<locals>.<genexpr>  rZ   r[   r;   Tr<   r   rP   r   r   N)rA   r,   rB   r-   r.   r/   r1   r]   rD   rE   r   r*   r=  s         r   6testRecursiveCopyObjsAndFilesToNonExistentBucketSubDirHGsutilNamingTests.testRecursiveCopyObjsAndFilesToNonExistentBucketSubDir  s3   &&T;4G&HN  "-  G &&(NOOD
Wh'^^\*	   K44TD6" ##*7D7#IJK KF ^\>+E+EtL^\>+E+Ex	^\8T:^\8XtD H 	X&r   c           	      r   U R                  SS/S9nU R                  5       nU R                  SS[        US5      [        US5      /5        [        S U R	                  [        US	5      5      R                  S
S9 5       5      n[        [        USS5      [        USSS5      /5      nU R                  XC5        g)r  z	parent/f0zparent/nested/f1r   r:   rn   r  r  c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   YGsutilNamingTests.testRecursiveCopyNestedObjsToNonExistentBucketSubDir.<locals>.<genexpr>  rZ   r[   r;   Tr<   r7   r   rP   Nr  r   s        r   4testRecursiveCopyNestedObjsToNonExistentBucketSubDirFGsutilNamingTests.testRecursiveCopyNestedObjsToNonExistentBucketSubDir  s    &&!#56 ' 8N&&(NOOD^X&^\* 
  K44TD6" ##*7D7#IJK KF ^\40^\8T: H 	X&r   c           	      ^   U R                  SS/S9nU R                  5       nU R                  SSU[        US5      /5        [	        S U R                  [        US5      5      R                  S	S
9 5       5      n[	        [        USS5      [        USSS5      /5      nU R                  XC5        g)r  r   r  r   r:   rn   r  c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   TGsutilNamingTests.testRecursiveCopyFilesToNonExistentBucketSubDir.<locals>.<genexpr>,  rZ   r[   r;   Tr<   r   r   N)r,   rA   rB   r1   r]   rD   rE   r*   rE  s        r   /testRecursiveCopyFilesToNonExistentBucketSubDirAGsutilNamingTests.testRecursiveCopyFilesToNonExistentBucketSubDir'  s      T3C,D EG&&(NOOD4$~|*LMN K44TD6" ##*7D7#IJK KF ^\40^\8T: H 	X&r   c           
         U R                  S/S9nU R                  5       nS H  u  p4[        S/5         U R                  SS[	        US5      U-   X$-   /5        SSS5        [        S	 U R                  U< [        R                  < S
35      R                  SS9 5       5      n[        [	        USS5      /5      nU R                  Xe5        M     g! , (       d  f       N~= f)z-Tests copying a bucket subdir to a directory.src_subdir/objr   )r   r   r   r   r/  )r   r   r   r:   rn   r  Nc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   AGsutilNamingTests.testCopyingBucketSubDirToDir.<locals>.<genexpr>C  s!      IHQ#a&& Hr[   r;   Tr<   r)   )rA   r,   r   rB   r1   r]   rD   r-   r   rE   r*   )r2   rz   r   final_src_charfinal_dst_charrL   r`   s          r   testCopyingBucketSubDirToDir.GsutilNamingTests.testCopyingBucketSubDirToDir5  s    &&5E4F&GN  "G-9(  !D EF.?$
 	 G  I66 !!($!GHI If d7L%89:h
x(-9 GFs   %C
C	c                    U R                  / SQS9nU R                  5       n[        S5       H  u  nu  pE[        S/5         U R	                  SS[        USU-  5      U-   X%-   /5        SSS5        [        S	 U R                  [        R                  R                  US
U-  S5      5      R                  SS9 5       5      n[        [        US
U-  S5      /5      nU R                  Xv5        M     g! , (       d  f       N= f)z@Tests copying a wildcard-specified bucket subdir to a directory.)zsrc_sub0dir/foozsrc_sub1dir/foozsrc_sub2dir/foozsrc_sub3dir/foor   r  r   r:   rn   z
src_sub%d*Nc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   ZGsutilNamingTests.testCopyingWildcardSpecifiedBucketSubDirToExistingDir.<locals>.<genexpr>[  s!      MLQ#a&& Lr[   zsrc_sub%ddirr;   Tr<   rm   )rA   r,   r  r   rB   r1   r]   rD   r-   r.   r/   rE   r*   )r2   rz   r   r  r  r  rL   r`   s           r   5testCopyingWildcardSpecifiedBucketSubDirToExistingDirGGsutilNamingTests.testCopyingWildcardSpecifiedBucketSubDirToExistingDirJ  s   && 5& N   "G/8406++N  !D EF!12^C$
 	 G  M66ggll7N%"$%%,WdW%KLM Mf d7NQ$6>?@h
x(06 GFs   (C11
C?	c                    U R                  S/S9nU R                  5       n U R                  S[        US5      U/5        U R	                  S5        g! [
         a*  nU R                  [        UR                  5         SnAgSnAff = f)z@Tests for failure when attempting bucket subdir copy without -R.r  r   r:   r  r[  N)	rA   r,   rB   r1   r   r	   r   r   r\  )r2   rz   r   r]  s       r   .testCopyingBucketSubDirToDirFailsWithoutMinusR@GsutilNamingTests.testCopyingBucketSubDirToDirFailsWithoutMinusRb  sy    &&5E4F&GN  "G7
oodT.,?IJ
ii78 7
mm+QXX667s   /A 
B BBc                 T   U R                  [        S5       Vs/ s H  nSU-  PM
     snS9nU R                  [        S5       Vs/ s H  nSU-  PM
     snS9n[        S5       H  u  nu  pEU R                  SS[	        USU-  5      U-   [	        US	U-  5      U-   /5        [        S
 U R                  [	        US	U-  S5      5      R                  SS9 5       5      n[        [	        US	U-  SU-  S5      [	        US	U-  S5      /5      nU R                  Xv5        M     gs  snf s  snf )z7Tests copying a bucket subdir to another bucket subdir.   src_subdir_%d/objr   dst_subdir_%d/obj2r  r:   rn   src_subdir_%ddst_subdir_%dc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   JGsutilNamingTests.testCopyingBucketSubDirToBucketSubDir.<locals>.<genexpr>z  r  r[   r;   Tr<   r)   obj2N	rA   r  r  rB   r1   r]   rD   rE   r*   r2   r  rz   rK   r  r  rL   r`   s           r   %testCopyingBucketSubDirToBucketSubDir7GsutilNamingTests.testCopyingBucketSubDirToBucketSubDirl  sc   &&7<Qx@x!)A-x@ ' BN&&8=aA1*Q.A ' CN 09406++N
ood

~2
3n
D
~2
3n
D 	
  E66>?$$WdWCDE Ef 
~2Oa4G
O
~2F
; 	h x(06	 AAs   D D%c                    U R                  [        S5       Vs/ s H  nSU-  PM
     sn[        S5       Vs/ s H  nSU-  PM
     sn-   S9nU R                  [        S5       Vs/ s H  nSU-  PM
     snS9n[        S5       H  u  nu  pEU R                  SS[	        US	U-  5      U-   [	        US
U-  5      U-   /5        [        S U R                  [	        US
U-  S5      5      R                  SS9 5       5      n[        [	        US
U-  S	U-  S5      [	        US
U-  S	U-  SS5      [	        US
U-  S5      /5      nU R                  Xv5        M     gs  snf s  snf s  snf )zDTests copying a bucket subdir to another bucket subdir with nesting.r  r  zsrc_subdir_%d/nested/objr   r  r  r:   rn   r  r  c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   TGsutilNamingTests.testCopyingBucketSubDirToBucketSubDirWithNested.<locals>.<genexpr>  r  r[   r;   Tr<   r)   r   r  Nr  r  s           r   /testCopyingBucketSubDirToBucketSubDirWithNestedAGsutilNamingTests.testCopyingBucketSubDirToBucketSubDirWithNested  s   &&7<Qx@x!)A-x@16q:A	#a	':; ' <N &&8=aA1*Q.A ' CN 09406++N
ood

~2
3n
D
~2
3n
D 	
  E66>?$$WdWCDE Ef 
~2Oa4G
O
~2Oa4G 
~2F
;	 	h x(#06 A:As   EE
%Ec           
         S/n[        S5       H  nUR                  SU-  SU-  /5        M     U R                  US9nU R                  [        S5       Vs/ s H  nSU-  PM
     snS9n[        S5       H<  u  nu  pVU R	                  S[        US	U-  5      U-   [        US
U-  5      U-   /5        M>     [        S U R                  [        US5      5      R                  SS9 5       5      n[        5       n[        S5       Hi  nUR                  [        US
U-  S5      5        UR                  [        US
U-  S	U-  S5      5        UR                  [        US
U-  S	U-  SS5      5        Mk     U R                  X5        gs  snf )z9Tests moving a bucket subdir to a existing bucket subdir.rm   r  zsrc_subdir%d/foo2zsrc_subdir%d/nested/foo3r   zdst_subdir%d/existingr  r  src_subdir%dr  c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   QGsutilNamingTests.testMovingBucketSubDirToExistingBucketSubDir.<locals>.<genexpr>  rZ   r[   r;   Tr<   r  r   r   r  N)r  extendrA   r  rB   r1   r]   rD   rE   r1  r*   )	r2   src_objsr  rz   rK   r  r  rL   r`   s	            r   ,testMovingBucketSubDirToExistingBucketSubDir>GsutilNamingTests.testMovingBucketSubDirToExistingBucketSubDir  s   wH1Xoo*Q.0JQ0NOP &&H&=N&&;@8D8a-18D ' FN 09406++N
ood
~~1
2^
C
~~1
2^
C 	06  K44TD6" ##*7D7#IJK KF uH1Xll4(:JGHll
~~1>A3Ev
NPll
~~1>A3Ex	  	X&) Es   Fc                    U R                  S/S9nU R                  SS/S9n[        S5       H  u  p4U R                  S[        US5      [        USU-  5      U-   /5        [	        S U R                  [        USU-  S	5      5      R                  S
S9 5       5      n[	        [        USU-  S5      [        USU-  S5      /5      nU R                  Xe5        M     g)z+Tests copying an object to a bucket subdir.rl  r   zdir0/existingzdir1/existingr  r:   dir%dc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   DGsutilNamingTests.testCopyingObjectToBucketSubDir.<locals>.<genexpr>  r  r[   r;   Tr<   r  NrA   r  rB   r1   r]   rD   rE   r*   r2   rz   rK   r  r  rL   r`   s          r   testCopyingObjectToBucketSubDir1GsutilNamingTests.testCopyingObjectToBucketSubDir  s	   &&VH&=N&&%7 ' 9N 'y1
ood
~v
&
~w{
+n
< 	  E66>7$$WdWCDE Ef 
~w{F
3
~w{J
7 	h x( 2r   c                    U R                  SS/S9nU R                  / SQS9n[        S5       H  u  p4U R                  S[        R
                  R                  US5      [        US	U-  5      U-   /5        [        S
 U R                  [        US	U-  S5      5      R                  SS9 5       5      n[        [        US	U-  S5      [        US	U-  S5      [        US	U-  S5      [        US	U-  S5      /5      nU R                  Xe5        M     g)z2Tests copying wildcarded files to a bucket subdir.zsubdir0/existingzsubdir1/existingr   )r7   rP   r   r   r  r:   zf?zsubdir%dc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   MGsutilNamingTests.testCopyingWildcardedFilesToBucketSubDir.<locals>.<genexpr>  r  r[   r;   Tr<   r  r7   rP   r   N)rA   r,   r  rB   r-   r.   r/   r1   r]   rD   rE   r*   r2   rK   r3   r  r  rL   r`   s          r   (testCopyingWildcardedFilesToBucketSubDir:GsutilNamingTests.testCopyingWildcardedFilesToBucketSubDir  s/   &&(*<= ' ?N  ,> ?G&y1
ood
'',,w
%
~zA~
.
? 	  E66>:$$WdWCDE Ef 
~zA~z
:
~zA~t
4
~zA~t
4
~zA~t
4	 	h x( 2r   c                    U R                  SS/S9nU R                  S/S9n[        S5       Hl  u  p4U R                  SS[	        US	5      [	        US
U-  5      U-   /5        [        S U R                  [	        US5      5      R                  SS9 5       5      nMn     [        [	        USS5      [	        USS5      [	        USS	SSS5      [	        USS	SSS5      /5      nU R                  UW5        g)z1Tests copying one nested file to a bucket subdir.zd0/placeholderzd1/placeholderr   )r   r   r   rP   r   r  r:   r   r   zd%dc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   KGsutilNamingTests.testCopyingOneNestedFileToBucketSubDir.<locals>.<genexpr>  r   r[   r;   Tr<   r  placeholderr   r   r   rP   N)	rA   r,   r  rB   r1   r]   rD   rE   r*   r7  s          r   &testCopyingOneNestedFileToBucketSubDir8GsutilNamingTests.testCopyingOneNestedFileToBucketSubDir  s    &&&(89 ' ;N  -I,J KG&y1
ood

w

~uqy
)N
: 	
  M//d1$ %%,WdW%KLM Mf 2 ^T=1^T=1^T4x>^T4x>	 H 	Xv&r   c                    U R                  / SQS9nU R                  SS/S9n[        S5       Hg  u  p4U R                  S[        USU-  5      [        USU-  5      U-   /5        U R                  S	[        US
U-  5      [        USU-  5      U-   /5        Mi     [	        S U R                  [        US5      5      R                  SS9 5       5      n[	        [        USS5      [        USS5      [        USS5      [        USS5      [        USS5      [        USS5      [        USS5      [        USS5      [        USS5      [        USS5      /
5      nU R                  Xe5        g)z3Tests moving files to a non-existent bucket subdir.)f0f0f0f1f1f0f1f1r   r  r  r  r:   zf%df*r  r  zf%d*znonexisting%dc              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   WGsutilNamingTests.testMovingWildcardedFilesToNonExistentBucketSubDir.<locals>.<genexpr>  rZ   r[   r;   Tr<   dst_subdir0r  rA  rB  nonexisting0dst_subdir1rC  rD  nonexisting1Nr0  r1  s          r   2testMovingWildcardedFilesToNonExistentBucketSubDirDGsutilNamingTests.testMovingWildcardedFilesToNonExistentBucketSubDir  s    &&5 ' 7N&&02LM ' ON 'y1
ood
~w{
+
~~1
2^
C 	
 ood
~vz
*
~2
3n
D 	 2  K44TD6" ##*7D7#IJK KF ^]N;^]F3^]F3^^V4^^V4^]N;^]F3^]F3^^V4^^V4 H 	X&r   c           
      ~   U R                  SS/S9nU R                  SS/S9n[        S5       H6  u  p4U R                  S[        USU-  5      [        US	U-  5      U-   /5        M8     [	        S
 U R                  [        US5      5      R                  SS9 5       5      n[	        [        USS5      [        USS5      [        USS5      [        USS5      /5      nU R                  Xe5        [	        S U R                  [        US5      5      R                  SS9 5       5      nU R                  U[	        5       5        g)z*Tests moving an object to a bucket subdir.rl  obj1r   r  r  r  r  zobj%dr  c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   CGsutilNamingTests.testMovingObjectToBucketSubDir.<locals>.<genexpr>7  rZ   r[   r;   Tr<   rG  r  rI  c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   rP  B  rZ   r[   Nr0  r1  s          r   testMovingObjectToBucketSubDir0GsutilNamingTests.testMovingObjectToBucketSubDir+  so   &&VV4D&EN&&02LM ' ON 'y1
ood
~w{
+
~~1
2^
C 	 2  K44TD6" ##*7D7#IJK KF ^]N;^]F3^]N;^]F3	 H 	X& K44TD6" ##*7D7#IJK KF 	VSU#r   c                    U R                  / SQS9nU R                  5       n[        S5       H6  u  p4U R                  S[        USU-  5      U-   [        USU-  5      /5        M8     [	        S U R                  [        US5      5      R                  S	S
9 5       5      n[	        [        USS5      [        USS5      [        USSS5      [        USSS5      /5      nU R                  Xe5        g)z=Tests moving a bucket subdir to a non-existent bucket subdir.)rm   zsrc_subdir0/foo2zsrc_subdir0/nested/foo3zsrc_subdir1/foo2zsrc_subdir1/nested/foo3r   r  r  r%  r  c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   TGsutilNamingTests.testMovingBucketSubDirToNonExistentBucketSubDir.<locals>.<genexpr>U  r   r[   r;   Tr<   rG  r   rI  r   r  Nr0  )r2   
src_bucket
dst_bucketr  r  rL   r`   s          r   /testMovingBucketSubDirToNonExistentBucketSubDirAGsutilNamingTests.testMovingBucketSubDirToNonExistentBucketSubDirG  s   "" 1" J ""$J&y1
ood
z>A-
.
?
z>A-
. 	 2  ,--d:t.DEMM%) N +, ,F Z/Z/Z&9Z&9	 H 	X&r   c           
      T   U R                  / SQS9n[        S5       H)  u  p#U R                  SS[        USU-  5      U-   /5        M+     [	        S U R                  [        US5      5      R                  S	S
9 5       5      n[	        [        US5      /5      nU R                  XT5        g)zTests removing a bucket subdir.)r7   zdir0/f1zdir0/nested/f2zdir1/f1zdir1/nested/f2r   r  rmrn   r-  c              3   8   #    U  H  n[        U5      v   M     g 7frR   rS   rU   s     r   rX   =GsutilNamingTests.testRemovingBucketSubDir.<locals>.<genexpr>n  rZ   r[   r;   Tr<   r7   Nr0  )r2   rK   r  r  rL   r`   s         r   testRemovingBucketSubDir*GsutilNamingTests.testRemovingBucketSubDird  s    && 5& N 'y1
oo
tNGaK8>IJL 2  K44TD6" ##*7D7#IJK KF D./0HX&r   c           	      |   U R                  / SQS9U R                  / SQS9/n[        S5       HW  u  p#U R                  SS[        X   5      U-   /5         U R                  S[        X   5      /5        U R	                  S5        MY     g	! [
         a'  nU R                  UR                  S5         S	nAM  S	nAff = f)
z;Tests removing all objects in bucket via rm -R gs://bucket.)r7   zdir/f1zdir/nested/f2r   r  r\  rn   r  Fi  N)rA   r  rB   r1   
assertTruer   r*   status)r2   bucket_urisr  r  r]  s        r   testRecursiveRemoveObjsInBucket1GsutilNamingTests.testRecursiveRemoveObjsInBuckett  s     	'HI'HIK
 'y1
oodT4#7.#HIJ(tKN345 2  (3''(s   /B


B;B66B;c                     SnU R                  5       nU R                  UUSS9  U R                  S[        X!5      /SS9nU R	                  [
        R                  " U5      [
        R                  " U5      5        g)z:Tests that you can list an object with unicode characters.u   フォr   r   r  Tr  N)rA   r   rB   r1   r   r  ensure_text)r2   r   r   r  s       r   testUnicodeArgs!GsutilNamingTests.testUnicodeArgs  st    K""$J"-%  ' __TD$A#B+/  1FMM#//+.0GHr   c                     U R                  5       nU R                  USSS9nU R                  SS[        U5      /SS9nU R	                  UR                  5       [        U5      S-   [        U5      S-   /5        g )	Nr   r   r   r  rn   Tr  z/:)rA   r   rB   r1   r*   
splitlines)r2   r   obj_urir  s       r   testRecursiveListTrailingSlash0GsutilNamingTests.testRecursiveListTrailingSlash  s    ""$J:,/)/   1G __TD$z*:#;4_PF 	V&&(DMD,@,0MC,?+B Cr   c                 >    UR                   R                  S5      S   $ )z(For gs://bucket/abc/def/ghi returns ghi.r   rm  )r&  
rpartition)r2   r&  s     r   FinalObjNameComponent'GsutilNamingTests.FinalObjNameComponent  s    77c"2&&r   c                     Sn[        U5      nU R                  SUR                  5        U R                  SU-  UR                  5        g )Nzabc:deffilez	file://%s)r   r*   scheme
url_string)r2   url_strurls      r   testFileContainingColon)GsutilNamingTests.testFileContainingColon  s>    G
w
'CVSZZ([7*CNN;r    N)V__name__
__module____qualname____firstlineno____doc__r4   rM   ra   rj   r   r   r   r   r   r   r   r   r   r   r   skipIfr   
IS_WINDOWSr   r   r   r  r  r  r  r   r'  r,  r8  r>  rF  rM  rR  rX  r^  ra  rf  ri  rp  rt  rw  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r*  r2  r8  r>  rK  rR  rY  r_  re  ri  rn  rr  rz  __static_attributes__r|  r   r   r$   r$   K   s   +'8T	7' '.J'Z'&	''8'(')"E$
'" ??;))>@7@7B'' '	;	92	8''$)('$'.	'''$7:/;	IC$
J'4'"'$'')$E	?J
H
8	7'6)8)*&'4'&')*)07)0)6':),)0'0''R$8':' ("	I	C'<r   r$   c                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)GsUtilCommandTestsi  z3Basic sanity check tests to make sure commands run.c                 `    U R                  5       nU R                  SSS[        U5      /5        g)z7Test that the 'logging set off' command basically runs.loggingr]   offNr  r  s     r   testDisableLoggingCommandRuns0GsUtilCommandTests.testDisableLoggingCommandRuns  s*    &&(NOOIud>.BCDr   c           
      d    U R                  5       nU R                  SSSSS[        U5      /5        g)z6Test that the 'logging set on' command basically runs.r  r]   onz-bzgs://log_bucketNr  r  s     r   testEnableLoggingCommandRuns/GsUtilCommandTests.testEnableLoggingCommandRuns  s5    &&(NOOE4'8(*+r   c                 r    S[         R                  ;   a  [         R                  S	 U R                  S/ 5        g)zBTest that the help command doesn't raise (sanity checks all help).PAGERhelpN)r-   environrB   )r2   s    r   testHelpCommandDoesntRaise-GsUtilCommandTests.testHelpCommandDoesntRaise  s*     "**
**W
OOFBr   c                 |    U R                  SS9nU R                  S[        U5      /SS9nU R                  US5        g)z)Test that the cat command basically runs.rm   )re   r  Tr  N)r   rB   r1   r*   )r2   rz  r  s      r   testCatCommandRuns%GsUtilCommandTests.testCatCommandRuns  s?    /G__UT']O4_HFVU#r   c                 ^    U R                  5       nU R                  SS[        U5      /5        g)z3Test that the 'logging get' command basically runs.r  getNr  r  s     r   testGetLoggingCommandRuns,GsUtilCommandTests.testGetLoggingCommandRuns  s(    &&(NOOItN';<=r   c                 .   U R                  5       n [        5          U R                  S[        U5      /5        SSS5        U R	                  S5        g! , (       d  f       N = f! [
         a&  nU R                  UR                  S5         SnAgSnAff = f)zTest mb on existing bucket.mbNz'Did not get expected StorageCreateErrori  )rA   r   rB   r1   r   r   r*   rc  r2   rK   r]  s      r   testMakeBucketsCommand)GsUtilCommandTests.testMakeBucketsCommand  st    &&(N&%'tN345 (
ii9: ('  &
qxx%%&s-   
A$ AA$ 
A!A$ $
B.BBc                     U R                  5       n U R                  S[        US5      /5        U R                  S5        g! [         a-  nU R                  [        U-  UR                  5         SnAgSnAff = f)z'Test rm command on non-existent object.r\  non_existentr[  N)rA   rB   r1   r   r	   r   r   r\  r  s      r   testRemoveObjsCommand(GsUtilCommandTests.testRemoveObjsCommand  sh    &&(NG
oodT..ABC
ii78 G
mm*^;QXXFFGs   .A 
A8#A33A8r|  N)r}  r~  r  r  r  r  r  r  r  r  r  r  r  r|  r   r   r  r    s*    ;E
+ $>
&Gr   r  )&r  
__future__r   r   r   r   r  r-   r  gslib.cloud_apir   r   gslib.exceptionr	   r
   r   r   gslib.storage_urlr   gslib.tests.testcaseteststestcasegslib.tests.utilr   r1   r   r   r   gslib.utils.constantsr   gslib.utilsr   r   r   r"   GsUtilUnitTestCaser$   r  r|  r   r   <module>r     s   , '  % '  	 
 - , , + 3 2 2 ' ' 0 1 7 % & # #X<33 X<x*3G44 3Gr   