
    s                     j   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl	m
Z
 ddl	mZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmc mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  d Z!d Z" G d dejF                        Z$ G d dejF                        Z%y)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    | j                  d       | j                  d       | j                          y)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    | j                  dd       | j                  d       | j                          y)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                      e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Z ej&                  ej*                  d      d        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d  Z%d! Z&d" Z'd# Z(d$ Z)d% Z*d& Z+d' Z,d( Z-d) Z.d* Z/d+ Z0d, Z1d- Z2d. Z3d/ Z4d0 Z5d1 Z6d2 Z7d3 Z8d4 Z9d5 Z:d6 Z;d7 Z<d8 Z=d9 Z>d: Z?d; Z@d< ZAd= ZBd> ZCd? ZDd@ ZEdA ZFdB ZGdC ZHdD ZIdE ZJdF ZKdG ZLdH ZMdI ZNdJ ZOdK ZPdL ZQdM ZRdN ZSyO)PGsutilNamingTestsz#Unit tests for gsutil naming logic.c                    | j                  dt        j                  t        d      t        d                   | j                  dt        j                  t        d      t        d                   | j                  dt        j                  t        d      t        d                   | j                  dt        j                  t        d      t        d                   | j                  dt        j                  t        d	      t        d
                   | j                  dt        j                  t        d      t        d                   | j	                         }t
        j                  j                  |d      }t        j                  |       | j                  t        |      t        j                  t        t        |            t        t        |d                         y)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   testGetPathBeforeFinalDirz+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                 r   | j                  d      }| j                         }| j                  d|t        |      g       t	        | j                  t        |d            j                  d            }| j                  dt        |             | j                  d|d   j                  j                         y	)
z-Tests copying one top-level file to a bucket.f0	file_namecp**Texpand_top_level_buckets   r   NCreateTempFileCreateBucket
RunCommandr0   list_test_wildcard_iteratorIterAllr)   lenroot_objectnamer1   src_filedst_bucket_uriactuals       r   testCopyingTopLevelFileToBucketz1GsutilNamingTests.testCopyingTopLevelFileToBucketx   s    ""T"2H&&(NOOD8T.%9:;$$TD&" 	##*7D7#IKF 	QF$T6!900556r   c           	         | j                  d      }| j                  d      }| j                         }| j                  d||t        |      g       t	        d | j                  t        |d            j                  d      D              }t	        t        |d      t        |d      g      }| j                  ||       y	)
z)Tests copying multiple files to a bucket.r5   r6   f1r8   c              3   2   K   | ]  }t        |        y wNstr.0us     r   	<genexpr>zEGsutilNamingTests.testCopyingMultipleFilesToBucket.<locals>.<genexpr>          KJ1A J   r9   Tr:   Nr>   r?   r@   r0   setrB   rC   r)   )r1   	src_file0	src_file1rI   rJ   expecteds         r    testCopyingMultipleFilesToBucketz2GsutilNamingTests.testCopyingMultipleFilesToBucket   s    ##d#3I##d#3I&&(NOOD9in1EFG K44TD6" ##*7D7#IJK KF ^T"^T" H 	Xv&r   c           	      *   | j                         }t        j                  j                  |d      }t        j                  |       | j                  |dd      }| j                         }| j                  d|t        |d      g       | j                  d|t        |d      g       t        d | j                  t        |d            j                         D              }t        t        |dd	      t        |dd      g      }| j                  ||       y
)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   )tmpdirr7   contentsr8   zsubdir/ac              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zHGsutilNamingTests.testCopyingNestedFileToBucketSubdir.<locals>.<genexpr>   s       PO1A OrW   r9   aN)r+   r,   r-   r.   r/   r>   r?   r@   r0   rY   rB   IterObjectsr)   )r1   r_   r'   rH   rI   rJ   r\   s          r   #testCopyingNestedFileToBucketSubdirz5GsutilNamingTests.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 	Xv&r   c                    | j                         }| j                         }| j                  dd      }| j                  d|t        |d      g       | j                  d|t        |d      g       | j                  d|t        |d      g       | j                  ddt        |d	d
      t        |      g       t	        d | j                  t        |d            j                  d      D              }t	        t        |d
d      g      }| j                  ||       | j                         }| j                         }| j                  d|t        |d      g       | j                  d|t        |d      g       | j                  d|t        |d      g       | j                  ddt        |d	dd      t        |      g       t	        d | j                  t        |d            j                  d      D              }t	        t        |dd      t        |dd      g      }| j                  ||       | j                         }| j                  ddt        |dd	d      t        |      g       t	        d | j                  t        |d            j                  d      D              }t	        t        |dd      t        |dd      g      }| j                  ||       | j                         }	| j                         }
| j                  d|t        |	d      g       | j                  d|t        |	d      g       | j                  d|t        |	d      g       | j                  ddt        |	dd	dd      t        |
      g       t	        d | j                  t        |
d            j                  d      D              }t	        t        |
dd      t        |
dd      g      }| j                  ||       y)zCEnsure wildcarded recursive cp in bucket subdirs behaves like Unix.foos   bar)r7   r`   r8   zTest/sub-test/foozTest2/sub-test/foozTest3/sub-test/foo-R*zsub-testc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zEGsutilNamingTests.testCopyingBucketSubdirsToBucket.<locals>.<genexpr>   rV   rW   r9   Tr:   zTest/dir1/dir2/foozTest2/dir1/dir2/foozTest3/dir1/dir2/bardir1dir2c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zEGsutilNamingTests.testCopyingBucketSubdirsToBucket.<locals>.<genexpr>          LK1A KrW   barzTest*c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zEGsutilNamingTests.testCopyingBucketSubdirsToBucket.<locals>.<genexpr>   rm   rW   zdir1/test1/dir2/dir3/foozdir1/test2/dir2/dir3/foozdir1/test3/dir2/dir3/bardir3c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zEGsutilNamingTests.testCopyingBucketSubdirsToBucket.<locals>.<genexpr>   rm   rW   N)r?   r>   r@   r0   rY   rB   rC   r)   )r1   src_bucket_urirI   fpathrJ   r\   src_bucket_uri2dst_bucket_uri2dst_bucket_uri3src_bucket_uri3dst_bucket_uri4s              r    testCopyingBucketSubdirsToBucketz2GsutilNamingTests.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Xv&'')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 	Xv&'')OOOD_gsF3_ 
  L44TT6# $$+GTG$JKL LF _fe,_fe, H 	Xv&'')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 	Xv&r   c                    | j                         }| j                  g d      }| j                  dd|t        |      g       t	        d | j                  t        |d            j                  d      D              }t        j                  j                  |      d	   }t	        t        ||d
      t        ||d      t        ||d      t        ||ddd      g      }| j                  ||       y)z>Tests recursively copying absolute path directory to a bucket.)r5   rM   f2.txt)dir0rj   nested
test_filesr8   rg   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zGGsutilNamingTests.testCopyingAbsolutePathDirToBucket.<locals>.<genexpr>   rV   rW   r9   Tr:   r<   r5   rM   r{   r|   rj   r}   N)r?   r+   r@   r0   rY   rB   rC   r,   r-   splitr)   )r1   rI   src_dir_rootrJ   
src_tmpdirr\   s         r   "testCopyingAbsolutePathDirToBucketz4GsutilNamingTests.testCopyingAbsolutePathDirToBucket   s    &&(N%%E & GLOOD4tN/CDE K44TD6" ##*7D7#IJK KF |,Q/J^Z.^Z.^Z2^ZB	 H 	Xv&r   c           	      R   | j                         }| j                  dg      }| j                  dddt        |      g|       t	        d | j                  t        |d            j                  d	
      D              }t	        t        |dd      g      }| j                  ||       y)z9Tests recursively copying relative directory to a bucket.)r|   rM   r~   r8   rg   r|   cwdc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zGGsutilNamingTests.testCopyingRelativePathDirToBucket.<locals>.<genexpr>  rV   rW   r9   Tr:   rM   N)r?   r+   r@   r0   rY   rB   rC   r)   r1   rI   r2   rJ   r\   s        r   "testCopyingRelativePathDirToBucketz4GsutilNamingTests.testCopyingRelativePathDirToBucket  s    &&(N  ^,< =GOOD4n)=>GOL K44TD6" ##*7D7#IJK KF D678HXv&r   c           	         | j                         }| j                  |dd       | j                  dg      }| j                  ddt        j
                  j                  dd	      t        |d
      g|       t        d | j                  t        |d            j                  d      D              }t        t        |d      t        |d
d	d      g      }| j                  ||       y)zvTests recursively copying relative sub-directory to bucket subdir.

    Subdir is signified by a $folder$ object.
    zabc_$folder$ 
bucket_uriobject_namer`   r|   rj   rM   r~   r8   rg   r|   rj   abcr   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   z^GsutilNamingTests.testCopyingRelPathSubDirToBucketSubdirWithDollarFolderObj.<locals>.<genexpr>)  rV   rW   r9   Tr:   rM   N)r?   CreateObjectr+   r@   r,   r-   r.   r0   rY   rB   rC   r)   r   s        r   9testCopyingRelPathSubDirToBucketSubdirWithDollarFolderObjzKGsutilNamingTests.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 	Xv&r   c           	         | j                         }| j                  dg      }| j                  ddt        j                  j                  dd      t        |d      dz   g|	       t        d
 | j                  t        |d            j                  d      D              }t        t        |ddd      g      }| j                  ||       y)zoTests recursively copying relative sub-directory to bucket subdir.

    Subdir is signified by a / object.
    r   r~   r8   rg   r|   rj   r   /r   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   z`GsutilNamingTests.testCopyingRelativePathSubDirToBucketSubdirSignifiedBySlash.<locals>.<genexpr>@  rV   rW   r9   Tr:   rM   Nr?   r+   r@   r,   r-   r.   r0   rY   rB   rC   r)   r   s        r   ;testCopyingRelativePathSubDirToBucketSubdirSignifiedBySlashzMGsutilNamingTests.testCopyingRelativePathSubDirToBucketSubdirSignifiedBySlash3  s    
 &&(N  -C,D EGOO		ff	%	ne	$s	*	,     K44TD6" ##*7D7#IJK KF D=>?HXv&r   c           	         | j                         }| j                  dg      }| j                  ddt        j                  j                  dd      t        |      g|       t        d | j                  t        |d	            j                  d
      D              }t        t        |dd      g      }| j                  ||       y)z=Tests recursively copying relative sub-directory to a bucket.r   r~   r8   rg   r|   rj   r   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zJGsutilNamingTests.testCopyingRelativePathSubDirToBucket.<locals>.<genexpr>O  rV   rW   r9   Tr:   rM   Nr   r   s        r   %testCopyingRelativePathSubDirToBucketz7GsutilNamingTests.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Xv&r   c           
         | j                         }| j                  dg      }ddt        j                  z  fD ]  }| j	                  dd|t        |      g|       t        d | j                  t        |d	            j                  d
      D              }t        t        |d      g      }| j                  ||        y)z6Tests copying ./ to a bucket produces expected naming.rf   r~   ..%sr8   rg   r   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   z@GsutilNamingTests.testCopyingDotSlashToBucket.<locals>.<genexpr>_  #      MLa a&LrW   r9   Tr:   N)
r?   r+   r,   sepr@   r0   rY   rB   rC   r)   )r1   rI   r2   rel_src_dirrJ   r\   s         r   testCopyingDotSlashToBucketz-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           	         | j                         }| j                  dg      }| j                  ddt        j                  j                  |dd      t        |      g       t        d | j                  t        |d            j                  d	
      D              }| j                  dt        |             | j                  t        |dd      |d          y)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|   rj   rf   r~   r8   rg   r|   rj   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zLGsutilNamingTests.testCopyingDirContainingOneFileToBucket.<locals>.<genexpr>t  s       L $Ka3q6 $KrW   r9   Tr:   r<   rf   r   N)r?   r+   r@   r,   r-   r.   r0   rA   rB   rC   r)   rD   )r1   rI   r2   rJ   s       r   'testCopyingDirContainingOneFileToBucketz9GsutilNamingTests.testCopyingDirContainingOneFileToBucketg  s     &&(N  -D,E FGOO		gvv	.	n		 
  L4#?#?^T"$$$+GTG$J$K L MFQF$T.&%8&)Dr   c                 @   | j                         }| j                  dg      }t        |      dz   }t        |      dz   }||fD ]I  }	 | j                  dt        j
                  j                  |d      |g       | j                  d|z         K y # t        $ r Y Xw xY w)Nrf   r~   z/.z/..r8   zExpected InvalidUrlError for %s)	r?   r+   r0   r@   r,   r-   r.   failr
   )r1   rI   r2   object_named_dotobject_named_dotdotr   s         r   testCopyDotFilesToBucketz*GsutilNamingTests.testCopyDotFilesToBuckety  s    &&(N  eI 6GN+d2~.6(*=>rww||GU;[IJ		3kAB ?  s   AB	BBc           	         | j                  ddg      }| j                         }t        dg      5  | j                  ddt	        |      |g       ddd       t        d | j                  |t        j                  d	      j                  d
      D              }t        t	        ||j                  d      t	        ||j                  dd      g      }| j                  ||       y# 1 sw Y   xY w)z+Tests copying from a bucket to a directory.rf   dir/foo2test_objectsGSUtilcheck_hashesneverr8   rg   Nc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   z;GsutilNamingTests.testCopyingBucketToDir.<locals>.<genexpr>         GF1A FrW   r9   Tr:   dirfoo2)r?   r+   r   r@   r0   rY   rB   r,   r   rC   bucket_namer)   )r1   rr   dst_dirrJ   r\   s        r   testCopyingBucketToDirz(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 Wn00%8Wn00%@ H 	Xv& 
E	Ds   C''C0z)os.symlink() is not available on Windows.c           
      $   | j                         }| j                         }| j                         }t        j                  j	                  |d      }t        j
                  |       | j                  |d      }| j                  |d       t        j
                  t        j                  j	                  |d             t        j                  |t        j                  j	                  |d             | j                  dd|t        |      gdd	      }t        d
 | j                  t        |d            j                  d      D              }t        |t        j                  j                  |      dt        j                  j                  |            }t        |g      }	| j                  |	|       dt        j                  j	                  |d      z  }
| j                  |
|j                   d   d|
dt#        |j                                y)z5Tests that cp warns when copying a symlink directory.r'      foo)r_   r`   
symlinkdirr8   -rr<   T)debugreturn_log_handlerc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   z@GsutilNamingTests.testCopyingSymlinkDirectory.<locals>.<genexpr>         ,+A 	A+rW   r9   r:   zSkipping symlink directory "%s"info"z)" not found in mock_log_handler["info"]: N)r?   r+   r,   r-   r.   r/   r>   symlinkr@   r0   rY   rB   rC   basenamer)   assertInmessagesrQ   )r1   r   r_   tmpdir2r'   fpath1mock_log_handlerrJ   expected_object_pathr\   desired_msgs              r   testCopyingSymlinkDirectoryz-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Xv&477<<56KMM%..v6	c*334	67r   c           	         | j                  ddg      }| j                         }| j                  ddt        |      t        |      g       t        d | j	                  t        |d            j                  d	      D              }t        t        ||j                  d      t        ||j                  d
d      g      }| j                  ||       y)z1Tests copying from a bucket-only URI to a bucket.rf   r   r   r8   rg   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   z>GsutilNamingTests.testCopyingBucketToBucket.<locals>.<genexpr>  rV   rW   r9   Tr:   r   r   N)r?   r@   r0   rY   rB   rC   r   r)   r1   rr   rI   rJ   r\   s        r   testCopyingBucketToBucketz+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 	Xv&r   c           	         | j                  ddg      }| j                         }| j                  dd||g       t        d | j                  |t        j
                  d      j                  d	      D              }t        j                  j                  |      d
   }t        t        ||d      t        ||dd      g      }| j                  ||       y)z.Tests copying from a directory to a directory.rf   )r   r   r~   r8   rg   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zDGsutilNamingTests.testCopyingDirectoryToDirectory.<locals>.<genexpr>  r   rW   r9   Tr:   r<   r   r   N)r+   r@   rY   rB   r,   r   rC   r-   r   r0   r)   )r1   r2   r   rJ   src_dir_baser\   s         r   testCopyingDirectoryToDirectoryz1GsutilNamingTests.testCopyingDirectoryToDirectory  s      UO,D EG  "GOOD4'23 G44bff&wwEFG GF 77==)!,LWlE*WlE62 H 	Xv&r   c                    | j                  g d      }| j                         }| j                  d|t        j                  d|g       t	        d | j                  |t        j                  d      j                  d      D              }t	        t        |d	      t        |d
      g      }| j                  ||       y)z:Tests copying containing files and a directory without -R.)rf   rn   )d1f2)d2f3)d3d4f4r~   r8   rh   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zGGsutilNamingTests.testCopyingFilesAndDirNonRecursive.<locals>.<genexpr>  r   rW   r9   Tr:   rf   rn   N)	r+   r@   r,   r   rY   rB   rC   r0   r)   )r1   r2   r   rJ   r\   s        r   "testCopyingFilesAndDirNonRecursivez4GsutilNamingTests.testCopyingFilesAndDirNonRecursive  s       -  G   "GOODgrvv6@A G44bff&wwEFG GF D%($w*>?@HXv&r   c                 p   | j                  d      }| j                         }| j                  d||g       t        | j	                  |t
        j                  d      j                  d            }| j                  dt        |             | j                  t        |d      t        |d                y	)
z&Tests copying one file to a directory.rf   r6   r8   rh   Tr:   r<   r   N)r>   r+   r@   rA   rB   r,   r   rC   r)   rD   r0   rQ   )r1   rH   r   rJ   s       r   testCopyingFileToDirz&GsutilNamingTests.testCopyingFileToDir  s    ""U"3H  "GOOD8W-.$$'	))0$)OQF 	QF$T'5)3vay>:r   c                 x   | j                  d      }| j                         }| j                  d|t        |      dz   g       t	        | j                  t        |d            j                  d            }| j                  dt        |             | j                  d	|d
   j                  j                         y)zATests copying a file to an object containing consecutive slashes.r5   r6   r8   z//objr9   Tr:   r<   z/objr   Nr=   rG   s       r   -testCopyingFileToObjectWithConsecutiveSlashesz?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           	         | j                  dd      }| j                         }| j                  ddd|t        |      g       t	        | j                  t        |d            j                  d	            }| j                  d
t        |             |d   j                  }| j                  d|j                         | j                  d|j                         | j                  dt        |d      gd      }t        j                  t        j                  t        j                   |            d      }	 | j                  |j#                         d       |j%                          y# |j%                          w xY w)z4Tests copying one file with compression to a bucket.s	   plaintextr{   )r`   r7   r8   z-ztxtrh   Tr:   r<   r   gzipcatreturn_stdoutrb)fileobjmodeN)r>   r?   r@   r0   rA   rB   rC   r)   rD   rE   rF   contentEncodingr   GzipFilesixBytesIOensure_binaryreadclose)r1   rH   rI   rJ   
actual_objstdoutfs          r   !testCopyingCompressedFileToBucketz3GsutilNamingTests.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   6 E' 'E9c                    | j                  dg      }| j                         }| j                  dt        |d      t        |      g       t        | j	                  t        |d            j                  d            }| j                  dt        |             | j                  d|d   j                  j                         y	)
z%Tests copying an object to an object.r(   r   r8   rh   Tr:   r<   r   N)
r?   r@   r0   rA   rB   rC   r)   rD   rE   rF   )r1   rr   rI   rJ   s       r   testCopyingObjectToObjectz+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           	      l   | j                  dg      }| j                  dg      }| j                  dt        |d      d|j                  z  g       t	        d | j                  t        |d            j                  d	      D              }t	        t        |d      g      }| j                  ||       y
)z;Tests copying an object to an object using a dest wildcard.r(   r   dstobjr8   z%s*c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zOGsutilNamingTests.testCopyingObjectToObjectUsingDestWildcard.<locals>.<genexpr>'  s       JI1A IrW   rh   Tr:   N)r?   r@   r0   urirY   rB   rC   r)   r   s        r   *testCopyingObjectToObjectUsingDestWildcardz<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Xv&r   c           
      2   | j                  dg      }| j                  dg      }| j                         }t        dg      5  | j                  ddt	        |d      t
        j                  j                  |d      |g       d	d	d	       t        d
 | j                  t
        j                  j                  |d            j                  d      D              }t        t	        |d      t	        |d      g      }| j                  ||       y	# 1 sw Y   xY w)z/Tests copying objects and files to a directory.rM   r   r   r~   r   r8   rg   r9   Nc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zAGsutilNamingTests.testCopyingObjsAndFilesToDir.<locals>.<genexpr>9  s       DC1A CrW   Tr:   )r?   r+   r   r@   r0   r,   r-   r.   rY   rB   rC   r)   )r1   rr   r2   r   rJ   r\   s         r   testCopyingObjsAndFilesToDirz.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Xv& 
E	Ds   ?DDc           	         | j                  dg      }| j                         }dD ]  }t        dg      5  | j                  dt	        |d      d|z  g|       ddd       t               }t        j                  |      D ]r  \  }}}|D ]1  }|j                  t        j                  j                  ||             3 |D ]1  }	|j                  t        j                  j                  ||	             3 t t        t        j                  j                  |d      g      }
| j                  |
|        y# 1 sw Y   xY w)	zBTests that copying an object to . or ./ downloads to correct name.rM   r   r   r   r   r8   r   r   N)r?   r+   r   r@   r0   rY   r,   walkaddr-   r.   r)   )r1   rr   r   
final_charrJ   dirnamedirnames	filenames
subdirnamefilenamer\   s              r   testCopyingObjToDotz%GsutilNamingTests.testCopyingObjToDot?  s   &&TF&;N  "G
!D EFtND9$z13# 	 	% G uf*,'''*:
&'8Y"J
**RWW\\':6
7 #!H
**RWW\\'84
5 " +;
 bggll7D123h
x(  FFs   $D66D?	c           	         | j                  dg      }| j                  dg      }| j                         }| j                  ddt        |d      |t        j
                  dt        |      g       t        d | j                  t        |d            j                  d	
      D              }t        t        |d      t        |d      g      }| j                  ||       y)z,Tests copying objects and files to a bucket.rM   r   r   r~   r8   rg   r9   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zDGsutilNamingTests.testCopyingObjsAndFilesToBucket.<locals>.<genexpr>^  rV   rW   Tr:   N)
r?   r+   r@   r0   r,   r   rY   rB   rC   r)   r1   rr   r2   rI   rJ   r\   s         r   testCopyingObjsAndFilesToBucketz1GsutilNamingTests.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Xv&r   c           	      z   | j                         }| j                  |dz   d       | j                         }| j                  dd|dz   t	        |d      g       t        d | j                  t	        |d	            j                  d
      D              }t        t	        |d      g      }| j                  ||       y)aS  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/dir2rf   r_   r7   r8   rg   z/dir1rp   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zRGsutilNamingTests.testCopyingSubdirRecursiveToNonexistentSubdir.<locals>.<genexpr>v  rV   rW   r9   Tr:   zdir3/dir2/fooN	r+   r>   r?   r@   r0   rY   rB   rC   r)   r1   r2   rI   rJ   r\   s        r   -testCopyingSubdirRecursiveToNonexistentSubdirz?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Xv&r   c           	      L   | j                  d      }| j                         }| j                  dd|t        |d      g       t	        d | j                  t        |d            j                  d	      D              }t	        t        |d      g      }| j                  ||       y
)zTests copying a file with -R.rf   r6   r8   rg   dir/fooc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zBGsutilNamingTests.testCopyingFileToDirRecursive.<locals>.<genexpr>  rV   rW   r9   Tr:   NrX   r1   rH   rI   rJ   r\   s        r   testCopyingFileToDirRecursivez/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Xv&r   c           	      P   | j                  d      }| j                         }| j                  d|t        |d      dz   g       t	        d | j                  t        |d            j                  d	      D              }t	        t        |d
      g      }| j                  ||       y)znTests copying a file to a non-existent directory.

    Should create the directory and add the file to it
    rf   r6   r8   r   r   c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zDGsutilNamingTests.testCopyingFileToNonExistentDir.<locals>.<genexpr>  rV   rW   r9   Tr:   r  NrX   r  s        r   testCopyingFileToNonExistentDirz1GsutilNamingTests.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Xv&r   c           
         | j                         }| j                  |d      }| j                  |d      }| j                         }| j                  dd||t	        |d      g       t        d | j                  t	        |d            j                  d	
      D              }t        t	        |d      t	        |d      g      }| j                  ||       y)z%Tests copying multiple files with -R.rf   r  rn   r8   rg   r  c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zKGsutilNamingTests.testCopyingMultipleFilesToDirRecursive.<locals>.<genexpr>  rV   rW   r9   Tr:   zdir/foo/foozdir/foo/barNr  )r1   r2   r[   	src_file2rI   rJ   r\   s          r   &testCopyingMultipleFilesToDirRecursivez8GsutilNamingTests.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 	Xv&r   c                     | j                  d      }| j                         }	 | j                  d||g       | j                  d       y# t        $ r*}| j	                  t
        |j                         Y d}~yd}~ww xY w)z%Tests copying a directory without -R.r<   r~   r8   %Did not get expected CommandExceptionN)r+   r@   r   r	   r   r   reason)r1   r2   r   es       r   "testAttemptDirCopyWithoutRecursionz4GsutilNamingTests.testAttemptDirCopyWithoutRecursion  sn      A .G  "G7
oodWg./
ii78 7
mm+QXX667s   %A
 
	A= A88A=c                    | j                  ddg      }| j                         }t        dg      5  | j                  dt	        |d      |g       ddd       t        | j                  |t        j                  d      j                  d	            }| j                  d
t        |             | j                  t	        |d      t        |d                y# 1 sw Y   xY w)zBTests copying a file and subdirectory of the same name without -R.rM   zf1/f2r   r   r8   Nrh   Tr:   r<   r   )r?   r+   r   r@   r0   rA   rB   r,   r   rC   r)   rD   rQ   )r1   rr   r   rJ   s       r   %testNonRecursiveFileAndSameNameSubdirz7GsutilNamingTests.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                     | j                         }	 | j                  ddt        |      g       | j                  d       y# t        $ r&}| j                  d|j                         Y d}~yd}~ww xY w)z8Attempts to copy a src specified as a provider-only URI.r8   r&   r&  zprovider-onlyNr?   r@   r0   r   r	   r   r'  r1   rr   r(  s      r   !testAttemptCopyingProviderOnlySrcz3GsutilNamingTests.testAttemptCopyingProviderOnlySrc  s_    &&(N/
oodWd>&:;<
ii78 /
mmOQXX../s   .A 	A0
A++A0c                     | j                         }	 | j                  d||g       | j                  d       y# t        $ r&}| j	                  d|j
                         Y d}~yd}~ww xY w)z"Attempts to an object atop itself.r8   r&  zare the same file - abortN)r>   r@   r   r	   r   r'  )r1   rH   r(  s      r   'testAttemptCopyingOverlappingSrcDstFilez9GsutilNamingTests.testAttemptCopyingOverlappingSrcDstFile  s[    ""$H;
oodXx01
ii78 ;
mm/::;s   %8 	A'A""A'c                    | j                  d      }	 | j                  dt        |d      t        |d      g       | j                  d       y	# t        $ r5}| j                  |j                  j                  d      d       Y d	}~y	d	}~ww xY w)
z3Attempts to copy where dst wildcard matches >1 obj.r!   r   r8   obj0rh   r&  zmust match exactly 1 URLN)r?   r@   r0   r   r	   assertNotEqualr'  findr.  s      r   &testAttemptCopyingToMultiMatchWildcardz8GsutilNamingTests.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                    | j                  d      }| j                         }	 | j                  ddt        |d      |g       | j	                  d       y# t
        $ r&}| j                  d|j                         Y d}~yd}~ww xY w)	z,Attempts to copy multiple objects to a file.r!   r   r8   rg   rh   r&  z!must name a directory, bucket, orN)r?   r>   r@   r0   r   r	   r   r'  )r1   rr   dst_filer(  s       r   !testAttemptCopyingMultiObjsToFilez3GsutilNamingTests.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                 T   | j                         }| j                  |d       | j                  |d       | j                         }	 | j                  ddt	        |      |g       | j                  d       y# t        $ r&}| j                  d|j                         Y d}~yd}~ww xY w)	z>Attempts to copy objects that cause a file/directory conflict.rb   )r   r   zb/ar8   rg   r&  z,exists where a directory needs to be createdN)	r?   r   r+   r@   r0   r   r	   r5  r'  )r1   r   r   r(  s       r   %testAttemptCopyingWithFileDirConflictz7GsutilNamingTests.testAttemptCopyingWithFileDirConflict  s     ""$J=?  "G$
oodT4
#3W=>
ii78 $
H(($ $$s   /A8 8	B'B""B'c                 x   | j                         }t        j                  t        j                  j	                  |d             | j                  dd      }	 | j                  dt        |      |dz   g       | j                  d       y# t        $ r&}| j                  d|j                         Y d}~yd}~ww xY w)	zAAttempts to copy an object that causes a directory/file conflict.r   rn   )r   r`   r8   r   r&  z"where the file needs to be createdN)r+   r,   r/   r-   r.   r   r@   r0   r   r	   r5  r'  )r1   r_   src_urir(  s       r   %testAttemptCopyingWithDirFileConflictz7GsutilNamingTests.testAttemptCopyingWithDirFileConflict  s     !FHHRWW\\&%()EEBGJ
oodT']FSL9:
ii78 J
>IIJs   1B
 
	B9B44B9c           	      @   | j                  dg      }| j                  dt        |d      t        |d      g       t        d | j	                  t        |d            j                  d	      D              }t        t        |d      g      }| j                  ||       y
)zAttempts 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   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zAGsutilNamingTests.testWildcardMoveWithinBucket.<locals>.<genexpr>  rV   rW   r9   Tr:   Nr?   r@   r0   rY   rB   rC   r)   )r1   rI   rJ   r\   s       r   testWildcardMoveWithinBucketz.GsutilNamingTests.testWildcardMoveWithinBucket  s    
 &&UG&<NOOD.&1.%023  K44TD6" ##*7D7#IJK KF D/01HXv&r   c                     | j                  dg      }	 | j                  dt        |d      g       y# t        $ r&}| j	                  d|j
                         Y d}~yd}~ww xY w)zATest ls of non-existent obj that matches prefix of existing objs.obj_with_suffixr   lsr(   zmatched no objectsN)r?   r@   r0   r	   r   r'  r.  s      r   %testLsNonExistentObjectWithPrefixNamez7GsutilNamingTests.testLsNonExistentObjectWithPrefixName  s^     &&5F4G&HN4
oodT.%89: 4
mm(!((334s   3 	A"AA"c                    | j                  g d      }| j                  dt        |d      gd      }t        t        |d      t        |dd	      t        |dd
      |j                  z   t        |dd	      t        |dd      g      }|j                  d       t        |j                  d      D cg c]  }|j                          c}      }| j                  ||       yc c}w )z2Test that ls of a bucket returns expected results.foo1zd0/foo2z
d1/d2/foo3r   rI  rh   Tr   rM  r   :r   d0r   r   
N	r?   r@   r0   rY   delimr  r   stripr)   r1   rr   outputr\   linerJ   s         r   testLsBucketNonRecursivez*GsutilNamingTests.testLsBucketNonRecursive  s    &&6 ' 8N__TD$=#>+/  1F^V$^T3'^T4(>+?+??^T3'^T6* H LL6<<+=>+=4$**,+=>?FXv& ?s   0C!c                    | j                  g d      }| j                  ddt        |d      gd      }t        t        |d      t        |d	d
      t        |d	dd
      t        |d	dd      t        |dd
      t        |dd      g      }|j	                  d       t        |j                  d      D cg c]  }|j                          c}      }| j                  ||       yc c}w )z5Test that ls -R of a bucket returns expected results.rL  r   rI  rg   rh   Tr   rM  r   rN  r   foo3rO  r   r   rP  Nr?   r@   r0   rY   r  r   rS  r)   rT  s         r   testLsBucketRecursivez'GsutilNamingTests.testLsBucketRecursive,  s    &&6 ' 8N__TD$~s*C#D+/  1F^V$^T3'^T4-^T40^T3'^T6* H LL6<<+=>+=4$**,+=>?FXv& ?s   2C#c                 R   | j                  dg      }| j                  ddt        |d      gd      }t        t        |d      g      }|j	                  d       t        |j                  d	      D cg c]  }|j                          c}      }| j                  ||       y
c c}w )zBTest that ls -R of a bucket with an object that has leading slash.r5   r   rI  rg   rh   Tr   r   rP  NrZ  )r1   rI   rU  r\   rV  rJ   s         r   /testLsBucketRecursiveWithLeadingSlashObjectNamezAGsutilNamingTests.testLsBucketRecursiveWithLeadingSlashObjectName>  s    &&TF&;N__TD$~s*C#D+/  1FD./0HLL6<<+=>+=4$**,+=>?FXv& ?s   3B$c                    | j                  ddg      }| j                  dt        |d      gd      }t        t        |dd      t        |dd	      |j                  z   g      }|j                  d
       t        |j                  d      D cg c]  }|j                          c}      }| j                  ||       yc c}w )z9Test that ls of a bucket subdir returns expected results.src_subdir/foosrc_subdir/nested/foo2r   rI  
src_subdirTr   rf   r}   r   rP  NrQ  rT  s         r   testLsBucketSubdirNonRecursivez0GsutilNamingTests.testLsBucketSubdirNonRecursiveH  s    &&&(@A ' CN__TD$F#G+/  1F^\51	nlH	58L8L	L H LL6<<+=>+=4$**,+=>?FXv& ?s   B>c                    | j                  ddg      }dD ]  }| j                  ddt        |d      |z   gd	      }t        t        |dd
      t        |dd      t        |ddd
      t        |ddd      g      }|j	                  d       t        |j                  d      D cg c]  }|j                          c}      }| j                  ||        yc c}w )z<Test that ls -R of a bucket subdir returns expected results.r_  r`  r   r  rI  rg   ra  Tr   rN  rf   r}   r   r   rP  NrZ  )r1   rr   r  rU  r\   rV  rJ   s          r   testLsBucketSubdirRecursivez-GsutilNamingTests.testLsBucketSubdirRecursiveV  s    &&&(@A ' CN

tNL9JFG  f 
~|S
1
~|U
3
~|Xs
;
~|Xv
>	 	h ll2V\\$-?@-?TDJJL-?@Af
x(   As   #C
c                 `    | j                         }| j                  dddt        |      g       y)/Test that the 'acl set' command basically runs.aclrY   privateNr?   r@   r0   r1   rr   s     r   testSetAclOnBucketRunsz(GsutilNamingTests.testSetAclOnBucketRunsh  s,    
 &&(NOOEE9d>.BCDr   c           	          | j                  dg      }t               5  | j                  dddt        |      dd dz   g       ddd       y# 1 sw Y   yxY w)	zATest that 'acl set' basically runs against wildcard-named bucket.r5   r   rg  rY   rh  Nrh   )r?   r   r@   r0   rj  s     r   #testSetAclOnWildcardNamedBucketRunsz5GsutilNamingTests.testSetAclOnWildcardNamedBucketRunsp  sU    
 &&TF&;N	#	%
oo
)T.1#26<
=? 
&	%	%s   %AAc           	      h    | j                  dg      }| j                  dddt        |d      g       y)rf  r5   r   rg  rY   rh  rh   Nri  rj  s     r   testSetAclOnObjectRunsz(GsutilNamingTests.testSetAclOnObjectRuns{  s3    &&TF&;NOOEE9d>3.GHIr   c                 `    | j                         }| j                  dddt        |      g       y)z2Test that the 'defacl set' command basically runs.defaclrY   rh  Nri  rj  s     r   testSetDefAclOnBucketRunsz+GsutilNamingTests.testSetDefAclOnBucketRuns  s*    &&(NOOHuin1EFGr   c           	          | j                         }	 | j                  dddt        |d      g       | j                  d       y# t        $ r&}| j                  d|j                         Y d}~yd}~ww xY w)zDTest that the 'defacl set' command fails when run against an object.rr  rY   rh  rh   r&  zURL must name a bucketNr-  r.  s      r   testSetDefAclOnObjectFailsz,GsutilNamingTests.testSetDefAclOnObjectFails  sd    &&(N8
ooh	43L MN
ii78 8
mm,ahh778s   0A 	A2A--A2c                 v   | j                  d      }| j                         }| j                  d|t        |      gd       t	        | j                  t        |d            j                  d            }| j                  d	t        |             | j                  d|d
   j                  j                         y)zTests using gsutil -D option.r5   r6   r8      )r   rh   Tr:   r<   r   Nr=   rG   s       r   testMinusDOptionWorksz'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                    | j                  g d      }| j                  g d      }| j                  ddg      }t        d      D ]S  \  }}| j                  dd	t	        |d
      t
        j                  j                  |d
      t	        |d|z        |z   g       U t        d | j                  t	        |d
            j                  d      D              }t               }t        d      D ]S  }|j                  t	        |d|z  d             t        d      D ]$  }|j                  t	        |d|z  d|z               & U | j                  ||       y)z?Tests copying flatly listed objects and files to bucket subdir.)r5   zd0/f1zd1/d2/f2r   )r   )r   r   )r   d5f5r~   zdst_subdir0/existingzdst_subdir1/existingr  r8   rg   r9   dst_subdir%dc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zNGsutilNamingTests.testFlatCopyingObjsAndFilesToBucketSubDir.<locals>.<genexpr>  rV   rW   Tr:   r!   existing   zf%dN)r?   r+   	enumerater@   r0   r,   r-   r.   rY   rB   rC   ranger  r)   )	r1   rr   r2   rI   ir  rJ   r\   js	            r   )testFlatCopyingObjsAndFilesToBucketSubDirz;GsutilNamingTests.testFlatCopyingObjsAndFilesToBucketSubDir  s\   &&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   	Xv&r   c                    | j                  ddg      }| j                  ddg      }| j                  ddg      }t        d	      D ]  \  }}| j                  d
dt	        |      |t	        |d|z        |z   g       t        d | j                  t	        |d|z  d            j                  d      D              }t        j                  j                  |      d   }|j                  }t        t	        |d|z  d      t	        |d|z  |d      t	        |d|z  |dd      t	        |d|z  |d      t	        |d|z  |dd      g      }	| j                  |	|        y)zDTests recursive copy of objects and files to existing bucket subdir.r5   	nested/f1r   dst_subdir0/existing_objdst_subdir1/existing_objr   r}   r   r~   r  r8   rg   r|  c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zXGsutilNamingTests.testRecursiveCopyObjsAndFilesToExistingBucketSubDir.<locals>.<genexpr>         EDQ#a& DrW   r9   Tr:   r<   existing_objr}   rM   r   N)r?   r+   r  r@   r0   rY   rB   rC   r,   r-   r   r   r)   )
r1   rr   rI   r2   r  r  rJ   tmp_dirname
bucketnamer\   s
             r   3testRecursiveCopyObjsAndFilesToExistingBucketSubDirzEGsutilNamingTests.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                    | j                  dg      }| j                  dg      }ddt        j                  z   fD ]  }| j	                  dd|t        j                  z   |z   t        |d      g       t        d	 | j                  t        |dd
            j                  d      D              }t        t        |ddd      t        |dd      g      }| j                  ||        y)zDTests recursive copy of invalid path file to existing bucket subdir.)r}   r5   r~   dst_subdir/existing_objr   r   r8   rg   
dst_subdirc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zcGsutilNamingTests.testRecursiveCopyFileToExistingBucketSubDirInvalidSourceParent.<locals>.<genexpr>  s      21Q#a& 1rW   r9   Tr:   r}   r5   r  N)
r+   r?   r,   r   r@   r0   rY   rB   rC   r)   )r1   r2   rI   relative_path_stringrJ   r\   s         r   >testRecursiveCopyFileToExistingBucketSubDirInvalidSourceParentzPGsutilNamingTests.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                 \   | j                  dg      }t        j                  j                  |d      }t        j                  |       | j                  |d       | j                  dg      }ddt        j                  z   d	d	t        j                  z   fD ]{  }| j                  |
      5  t        j                  j                  ||      }| j                  t              5  | j                  dd||t        |d      g       ddd       ddd       } y# 1 sw Y   xY w# 1 sw Y   xY w)zFTests recursive copy of invalid paths files to existing bucket subdir.rM   r~   r}   r   r  r  r   r   z..)r  r8   rg   r  N)r+   r,   r-   r.   r/   r>   r?   r   subTestassertRaisesr
   r@   r0   )r1   src_dir1src_dir2rI   r  invalid_parent_dirs         r   ?testRecursiveCopyFilesToExistingBucketSubDirInvalidSourceParentzQGsutilNamingTests.testRecursiveCopyFilesToExistingBucketSubDirInvalidSourceParent  s    !!dV!4Hww||Hh/HHHXx48&&5N4O&PN!$cBFFlD$- H<<-A<BWW\\(4HI/
//$ ><0	!  0 CB !I 0/ CBs$   ,6D""!DD"DD""D+	c                 F   | j                  ddg      }| j                  ddg      }| j                         }| j                  ddt        j                  j                  |d	      t        |      t        |d
      g       t        d | j                  t        |d            j                  d      D              }t        t        |d
|j                  d      t        |d
|j                  dd      t        |d
d	d      t        |d
d	dd      g      }| j                  ||       y)CTests recursive copy of objs + files to non-existent bucket subdir.r5   r  r   )parentr   )r  r}   r   r~   r8   rg   r  r  c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   z[GsutilNamingTests.testRecursiveCopyObjsAndFilesToNonExistentBucketSubDir.<locals>.<genexpr>  rV   rW   r9   Tr:   r}   rM   r   r   N)r?   r+   r@   r,   r-   r.   r0   rY   rB   rC   r   r)   r  s         r   6testRecursiveCopyObjsAndFilesToNonExistentBucketSubDirzHGsutilNamingTests.testRecursiveCopyObjsAndFilesToNonExistentBucketSubDir  s5   &&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 	Xv&r   c           	         | j                  ddg      }| j                         }| j                  ddt        |d      t        |d      g       t        d | j	                  t        |d	            j                  d
      D              }t        t        |dd      t        |ddd      g      }| j                  ||       y)r  z	parent/f0zparent/nested/f1r   r8   rg   r  r  c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zYGsutilNamingTests.testRecursiveCopyNestedObjsToNonExistentBucketSubDir.<locals>.<genexpr>  rV   rW   r9   Tr:   r5   r}   rM   NrE  r   s        r   4testRecursiveCopyNestedObjsToNonExistentBucketSubDirzFGsutilNamingTests.testRecursiveCopyNestedObjsToNonExistentBucketSubDir  s    &&!#56 ' 8N&&(NOOD^X&^\* 
  K44TD6" ##*7D7#IJK KF ^\40^\8T: H 	Xv&r   c           	      l   | j                  ddg      }| j                         }| j                  dd|t        |d      g       t	        d | j                  t        |d            j                  d	
      D              }t	        t        |dd      t        |ddd      g      }| j                  ||       y)r  r   r  r~   r8   rg   r  c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zTGsutilNamingTests.testRecursiveCopyFilesToNonExistentBucketSubDir.<locals>.<genexpr>,  rV   rW   r9   Tr:   r}   r   N)r+   r?   r@   r0   rY   rB   rC   r)   r  s        r   /testRecursiveCopyFilesToNonExistentBucketSubDirzAGsutilNamingTests.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 	Xv&r   c           
         | j                  dg      }| j                         }dD ]  \  }}t        dg      5  | j                  ddt	        |d      |z   ||z   g       ddd       t        d	 | j                  |t        j                  d
      j                  d      D              }t        t	        |dd      g      }| j                  ||        y# 1 sw Y   yxY w)z-Tests copying a bucket subdir to a directory.src_subdir/objr   )r   r   r   r   r  )r   r   r   r8   rg   ra  Nc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zAGsutilNamingTests.testCopyingBucketSubDirToDir.<locals>.<genexpr>C  s       IHQ#a& HrW   r9   Tr:   r(   )r?   r+   r   r@   r0   rY   rB   r,   r   rC   r)   )r1   rr   r   final_src_charfinal_dst_charrJ   r\   s          r   testCopyingBucketSubDirToDirz.GsutilNamingTests.testCopyingBucketSubDirToDir5  s    &&5E4F&GN  "G-9(  !D EF.?n$
 	 G  I66 !!($!GHI If d7L%89:h
x(-9 GFs   &CC	c                    | j                  g d      }| j                         }t        d      D ]  \  }\  }}t        dg      5  | j	                  ddt        |d|z        |z   ||z   g       ddd       t        d	 | j                  t        j                  j                  |d
|z  d            j                  d      D              }t        t        |d
|z  d      g      }| j                  ||        y# 1 sw Y   xY w)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   r8   rg   z
src_sub%d*Nc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zZGsutilNamingTests.testCopyingWildcardSpecifiedBucketSubDirToExistingDir.<locals>.<genexpr>[  s       MLQ#a& LrW   zsrc_sub%ddirr9   Tr:   rf   )r?   r+   r  r   r@   r0   rY   rB   r,   r-   r.   rC   r)   )r1   rr   r   r  r  r  rJ   r\   s           r   5testCopyingWildcardSpecifiedBucketSubDirToExistingDirzGGsutilNamingTests.testCopyingWildcardSpecifiedBucketSubDirToExistingDirJ  s   && 5& N   "G/8406++NN  !D EF!12^Cn$
 	 G  M66ggll7N%"$%%,WdW%KLM Mf d7NQ$6>?@h
x(06 GFs   )C88D	c                    | j                  dg      }| j                         }	 | j                  dt        |d      |g       | j	                  d       y# t
        $ r*}| j                  t        |j                         Y d}~yd}~ww xY w)z@Tests for failure when attempting bucket subdir copy without -R.r  r   r8   ra  r&  N)	r?   r+   r@   r0   r   r	   r   r   r'  )r1   rr   r   r(  s       r   .testCopyingBucketSubDirToDirFailsWithoutMinusRz@GsutilNamingTests.testCopyingBucketSubDirToDirFailsWithoutMinusRb  sy    &&5E4F&GN  "G7
oodT.,?IJ
ii78 7
mm+QXX667s   /A 	B BBc                 Z   | j                  t        d      D cg c]  }d|z  	 c}      }| j                  t        d      D cg c]  }d|z  	 c}      }t        d      D ]  \  }\  }}| j                  ddt	        |d|z        |z   t	        |d	|z        |z   g       t        d
 | j                  t	        |d	|z  d            j                  d      D              }t        t	        |d	|z  d|z  d      t	        |d	|z  d      g      }| j                  ||        yc c}w c c}w )z7Tests copying a bucket subdir to another bucket subdir.   src_subdir_%d/objr   dst_subdir_%d/obj2r  r8   rg   src_subdir_%ddst_subdir_%dc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zJGsutilNamingTests.testCopyingBucketSubDirToBucketSubDir.<locals>.<genexpr>z  r  rW   r9   Tr:   r(   obj2N	r?   r  r  r@   r0   rY   rB   rC   r)   r1   r  rr   rI   r  r  rJ   r\   s           r   %testCopyingBucketSubDirToBucketSubDirz7GsutilNamingTests.testCopyingBucketSubDirToBucketSubDirl  sg   &&7<Qx@x!)A-x@ ' BN&&8=aA1*Q.A ' CN 09406++NN
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                    | j                  t        d      D cg c]  }d|z  	 c}t        d      D cg c]  }d|z  	 c}z         }| j                  t        d      D cg c]  }d|z  	 c}      }t        d      D ]  \  }\  }}| j                  ddt	        |d	|z        |z   t	        |d
|z        |z   g       t        d | j                  t	        |d
|z  d            j                  d      D              }t        t	        |d
|z  d	|z  d      t	        |d
|z  d	|z  dd      t	        |d
|z  d      g      }| j                  ||        yc c}w c c}w c c}w )zDTests copying a bucket subdir to another bucket subdir with nesting.r  r  zsrc_subdir_%d/nested/objr   r  r  r8   rg   r  r  c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zTGsutilNamingTests.testCopyingBucketSubDirToBucketSubDirWithNested.<locals>.<genexpr>  r  rW   r9   Tr:   r(   r}   r  Nr  r  s           r   /testCopyingBucketSubDirToBucketSubDirWithNestedzAGsutilNamingTests.testCopyingBucketSubDirToBucketSubDirWithNested  s   &&7<Qx@x!)A-x@16q:A	#a	':; ' <N &&8=aA1*Q.A ' CN 09406++NN
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           
         dg}t        d      D ]  }|j                  d|z  d|z  g        | j                  |      }| j                  t        d      D cg c]  }d|z  	 c}      }t        d      D ]<  \  }\  }}| j	                  dt        |d	|z        |z   t        |d
|z        |z   g       > t        d | j                  t        |d            j                  d      D              }t               }t        d      D ]h  }|j                  t        |d
|z  d             |j                  t        |d
|z  d	|z  d             |j                  t        |d
|z  d	|z  dd             j | j                  ||       yc c}w )z9Tests moving a bucket subdir to a existing bucket subdir.rf   r  zsrc_subdir%d/foo2zsrc_subdir%d/nested/foo3r   zdst_subdir%d/existingr  rB  src_subdir%dr|  c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zQGsutilNamingTests.testMovingBucketSubDirToExistingBucketSubDir.<locals>.<genexpr>  rV   rW   r9   Tr:   r~  r   r}   rY  N)r  extendr?   r  r@   r0   rY   rB   rC   r  r)   )	r1   src_objsr  rr   rI   r  r  rJ   r\   s	            r   ,testMovingBucketSubDirToExistingBucketSubDirz>GsutilNamingTests.testMovingBucketSubDirToExistingBucketSubDir  s   wH1Xoo*Q.0JQ0NOP &&H&=N&&;@8D8a-18D ' FN 09406++NN
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	  	Xv&) Es   Fc                    | j                  dg      }| j                  ddg      }t        d      D ]  \  }}| j                  dt        |d      t        |d|z        |z   g       t	        d | j                  t        |d|z  d	            j                  d
      D              }t	        t        |d|z  d      t        |d|z  d      g      }| j                  ||        y)z+Tests copying an object to a bucket subdir.r3  r   zdir0/existingzdir1/existingr  r8   dir%dc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zDGsutilNamingTests.testCopyingObjectToBucketSubDir.<locals>.<genexpr>  r  rW   r9   Tr:   r~  Nr?   r  r@   r0   rY   rB   rC   r)   r1   rr   rI   r  r  rJ   r\   s          r   testCopyingObjectToBucketSubDirz1GsutilNamingTests.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                 .   | j                  ddg      }| j                  g d      }t        d      D ]  \  }}| j                  dt        j
                  j                  |d      t        |d	|z        |z   g       t        d
 | j                  t        |d	|z  d            j                  d      D              }t        t        |d	|z  d      t        |d	|z  d      t        |d	|z  d      t        |d	|z  d      g      }| j                  ||        y)z2Tests copying wildcarded files to a bucket subdir.zsubdir0/existingzsubdir1/existingr   )r5   rM   r   r~   r  r8   zf?zsubdir%dc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zMGsutilNamingTests.testCopyingWildcardedFilesToBucketSubDir.<locals>.<genexpr>  r  rW   r9   Tr:   r~  r5   rM   r   N)r?   r+   r  r@   r,   r-   r.   r0   rY   rB   rC   r)   r1   rI   r2   r  r  rJ   r\   s          r   (testCopyingWildcardedFilesToBucketSubDirz:GsutilNamingTests.testCopyingWildcardedFilesToBucketSubDir  s3   &&(*<= ' ?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                    | j                  ddg      }| j                  dg      }t        d      D ]o  \  }}| j                  ddt	        |d	      t	        |d
|z        |z   g       t        d | j                  t	        |d            j                  d      D              }q t        t	        |dd      t	        |dd      t	        |dd	ddd      t	        |dd	ddd      g      }| j                  |       y)z1Tests copying one nested file to a bucket subdir.zd0/placeholderzd1/placeholderr   )r   r   r}   rM   r~   r  r8   r   r   zd%dc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zKGsutilNamingTests.testCopyingOneNestedFileToBucketSubDir.<locals>.<genexpr>  r   rW   r9   Tr:   rO  placeholderr   r   r}   rM   N)	r?   r+   r  r@   r0   rY   rB   rC   r)   r  s          r   &testCopyingOneNestedFileToBucketSubDirz8GsutilNamingTests.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                    | j                  g d      }| j                  ddg      }t        d      D ]g  \  }}| j                  dt        |d|z        t        |d|z        |z   g       | j                  d	t        |d
|z        t        |d|z        |z   g       i t	        d | j                  t        |d            j                  d      D              }t	        t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      t        |dd      g
      }| j                  ||       y)z3Tests moving files to a non-existent bucket subdir.)f0f0f0f1f1f0f1f1r   r  r  r  r8   zf%df*r|  rB  zf%d*znonexisting%dc              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zWGsutilNamingTests.testMovingWildcardedFilesToNonExistentBucketSubDir.<locals>.<genexpr>  rV   rW   r9   Tr:   dst_subdir0r  r  r  nonexisting0dst_subdir1r  r  nonexisting1Nr  r  s          r   2testMovingWildcardedFilesToNonExistentBucketSubDirzDGsutilNamingTests.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 	Xv&r   c           
         | j                  ddg      }| j                  ddg      }t        d      D ]6  \  }}| j                  dt        |d|z        t        |d	|z        |z   g       8 t	        d
 | j                  t        |d            j                  d      D              }t	        t        |dd      t        |dd      t        |dd      t        |dd      g      }| j                  ||       t	        d | j                  t        |d            j                  d      D              }| j                  |t	                      y)z*Tests moving an object to a bucket subdir.r3  obj1r   r  r  r  rB  zobj%dr|  c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zCGsutilNamingTests.testMovingObjectToBucketSubDir.<locals>.<genexpr>7  rV   rW   r9   Tr:   r  r  r  c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zCGsutilNamingTests.testMovingObjectToBucketSubDir.<locals>.<genexpr>B  rV   rW   Nr  r  s          r   testMovingObjectToBucketSubDirz0GsutilNamingTests.testMovingObjectToBucketSubDir+  ss   &&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 	Xv& K44TD6" ##*7D7#IJK KF 	VSU#r   c                    | j                  g d      }| j                         }t        d      D ]6  \  }}| j                  dt        |d|z        |z   t        |d|z        g       8 t	        d | j                  t        |d            j                  d	
      D              }t	        t        |dd      t        |dd      t        |ddd      t        |ddd      g      }| j                  ||       y)z=Tests moving a bucket subdir to a non-existent bucket subdir.)rf   zsrc_subdir0/foo2zsrc_subdir0/nested/foo3zsrc_subdir1/foo2zsrc_subdir1/nested/foo3r   r  rB  r  r|  c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   zTGsutilNamingTests.testMovingBucketSubDirToNonExistentBucketSubDir.<locals>.<genexpr>U  r   rW   r9   Tr:   r  r   r  r}   rY  Nr  )r1   
src_bucket
dst_bucketr  r  rJ   r\   s          r   /testMovingBucketSubDirToNonExistentBucketSubDirzAGsutilNamingTests.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 	Xv&r   c           
      `   | j                  g d      }t        d      D ])  \  }}| j                  ddt        |d|z        |z   g       + t	        d | j                  t        |d            j                  d	
      D              }t	        t        |d      g      }| j                  ||       y)zTests removing a bucket subdir.)r5   zdir0/f1zdir0/nested/f2zdir1/f1zdir1/nested/f2r   r  rmrg   r  c              3   2   K   | ]  }t        |        y wrO   rP   rR   s     r   rU   z=GsutilNamingTests.testRemovingBucketSubDir.<locals>.<genexpr>n  rV   rW   r9   Tr:   r5   Nr  )r1   rI   r  r  rJ   r\   s         r   testRemovingBucketSubDirz*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Xv&r   c           	         | j                  g d      | j                  g d      g}t        d      D ]Y  \  }}| j                  ddt        ||         |z   g       	 | j                  dt        ||         g       | j	                  d       [ y	# t
        $ r&}| j                  |j                  d       Y d	}~d	}~ww xY w)
z;Tests removing all objects in bucket via rm -R gs://bucket.)r5   zdir/f1zdir/nested/f2r   r  r  rg   rI  Fi  N)r?   r  r@   r0   
assertTruer   r)   status)r1   bucket_urisr  r  r(  s        r   testRecursiveRemoveObjsInBucketz1GsutilNamingTests.testRecursiveRemoveObjsInBuckett  s     	'HI'HIK
 'y1>
oodT4A#7.#HIJ(tKN345 2  (3''(s   0B	C B;;C c                     d}| j                         }| j                  ||d       | j                  dt        ||      gd      }| j	                  t        j                  |      t        j                  |             y)z:Tests that you can list an object with unicode characters.u   フォr   r   rI  Tr   N)r?   r   r@   r0   r   r   ensure_text)r1   r   r   r   s       r   testUnicodeArgsz!GsutilNamingTests.testUnicodeArgs  sv    K""$J"-%  ' __TD[$A#B+/  1FMM#//+.0GHr   c                     | j                         }| j                  |dd      }| j                  ddt        |      gd      }| j	                  |j                         t        |      dz   t        |      dz   g       y )	Nr   r   r   rI  rg   Tr   z/:)r?   r   r@   r0   r)   
splitlines)r1   r   obj_urir   s       r   testRecursiveListTrailingSlashz0GsutilNamingTests.testRecursiveListTrailingSlash  s    ""$J:,/)/   1G __TD$z*:#;4_PF 	V&&(DMD,@,0MC,?+B Cr   c                 >    |j                   j                  d      d   S )z(For gs://bucket/abc/def/ghi returns ghi.r   r4  )r   
rpartition)r1   r   s     r   FinalObjNameComponentz'GsutilNamingTests.FinalObjNameComponent  s    77c"2&&r   c                     d}t        |      }| j                  d|j                         | j                  d|z  |j                         y )Nzabc:deffilez	file://%s)r   r)   scheme
url_string)r1   url_strurls      r   testFileContainingColonz)GsutilNamingTests.testFileContainingColon  s>    G
w
'CVSZZ([7*CNN;r   N)T__name__
__module____qualname____doc__r3   rK   r]   rd   ry   r   r   r   r   r   r   r   r   r   r   skipIfr   
IS_WINDOWSr   r   r   r   r   r   r   r   r   r  r  r  r  r  r   r$  r)  r+  r/  r1  r7  r:  r<  r?  rF  rJ  rW  r[  r]  rb  rd  rk  rn  rp  rs  ru  rx  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   r$   r$   K   s   +'8T	7' '.J'Z'&	''8'(')"E$
'" 8??;))>@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                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
GsUtilCommandTestsz3Basic sanity check tests to make sure commands run.c                 `    | j                         }| j                  dddt        |      g       y)z7Test that the 'logging set off' command basically runs.loggingrY   offNri  rj  s     r   testDisableLoggingCommandRunsz0GsUtilCommandTests.testDisableLoggingCommandRuns  s*    &&(NOOIud>.BCDr   c           
      d    | j                         }| j                  dddddt        |      g       y)z6Test that the 'logging set on' command basically runs.r  rY   onz-bzgs://log_bucketNri  rj  s     r   testEnableLoggingCommandRunsz/GsUtilCommandTests.testEnableLoggingCommandRuns  s5    &&(NOOE4'8(*+r   c                 n    dt         j                  v rt         j                  d= | j                  dg        y)zBTest that the help command doesn't raise (sanity checks all help).PAGERhelpN)r,   environr@   )r1   s    r   testHelpCommandDoesntRaisez-GsUtilCommandTests.testHelpCommandDoesntRaise  s*     "**
**W
OOFBr   c                     | j                  d      }| j                  dt        |      gd      }| j                  |d       y)z)Test that the cat command basically runs.rf   )r`   r   Tr   N)r   r@   r0   r)   )r1   r>  r   s      r   testCatCommandRunsz%GsUtilCommandTests.testCatCommandRuns  s?    /G__UT']O4_HFVU#r   c                 ^    | j                         }| j                  ddt        |      g       y)z3Test that the 'logging get' command basically runs.r  getNri  rj  s     r   testGetLoggingCommandRunsz,GsUtilCommandTests.testGetLoggingCommandRuns  s(    &&(NOOItN';<=r   c                 "   | j                         }	 t               5  | j                  dt        |      g       ddd       | j	                  d       y# 1 sw Y   xY w# t
        $ r&}| j                  |j                  d       Y d}~yd}~ww xY w)zTest mb on existing bucket.mbNz'Did not get expected StorageCreateErrori  )r?   r   r@   r0   r   r   r)   r  r1   rI   r(  s      r   testMakeBucketsCommandz)GsUtilCommandTests.testMakeBucketsCommand  st    &&(N&%'tN345 (
ii9: ('  &
qxx%%&s-   
A AA AA 	B(B		Bc                     | j                         }	 | j                  dt        |d      g       | j                  d       y# t        $ r-}| j                  t        |z  |j                         Y d}~yd}~ww xY w)z'Test rm command on non-existent object.r  non_existentr&  N)r?   r@   r0   r   r	   r   r   r'  r"  s      r   testRemoveObjsCommandz(GsUtilCommandTests.testRemoveObjsCommand  sh    &&(NG
oodT..ABC
ii78 G
mm*^;QXXFFGs   .A 	A7
#A22A7N)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   r0   r   r   r   gslib.utils.constantsr   gslib.utilsr   r   r   r"   GsUtilUnitTestCaser$   r  r  r   r   <module>r2     s   , '  % '  	 
 - , , + 3 2 2 ' ' 0 1 7 % & # #X<33 X<x*3G44 3Gr   