
    (                         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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\	R$                  5      rg)aH  Tests for parallel uploads ported from gsutil naming tests.

Currently, the mock storage service is not thread-safe and therefore not
suitable for multiprocess/multithreaded testing. Since parallel composite
uploads necessarily create at least one worker thread outside of main,
these tests are present in this file as temporary (slower) integration tests
to provide validation for parallel composite uploads until a thread-safe
mock storage service rewrite.

Tests for relative paths are not included as integration_testcase does not
support modifying the current working directory.
    )absolute_import)print_function)division)unicode_literalsN)	SkipForS3)ObjectToURI)SequentialAndParallelTransfer)Retryc                       \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\" S5      \S	 5       5       r\S
 5       r\S 5       r\S 5       r\S 5       rSrg)TestParallelCp1   z#Unit tests for gsutil naming logic.c                     U R                  SS9nU R                  5       nU R                  SU[        U5      /5        U R	                  US5      nU R                  [        US5      US   5        g)z-Tests copying one top-level file to a bucket.f0	file_namecp   r   NCreateTempFileCreateBucket	RunGsUtilsuriAssertNObjectsInBucketassertEqualselfsrc_filedst_bucket_uriliness       /platform/gsutil/gslib/tests/test_parallel_cp.pytestCopyingTopLevelFileToBucket.TestParallelCp.testCopyingTopLevelFileToBucket4   sj     ""T"2H&&(NNND(D$89:'':ET.$/q:    c                 :   U R                  SS9nU R                  SS9nU R                  5       nU R                  SX[        U5      /5        U R	                  US5      nU R                  [        US5      US   5        U R                  [        US5      US   5        g)	z)Tests copying multiple files to a bucket.r   r   f1r      r   r   Nr   )r   	src_file0	src_file1r   r   s        r     testCopyingMultipleFilesToBucket/TestParallelCp.testCopyingMultipleFilesToBucket>   s     ##d#3I##d#3I&&(NNND)^0DEF'':ET.$/q:T.$/q: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        U R                  US5      nU R                  [        US5      US   5        U R                  [        US	5      US
   5        g)zTests copying a nested file to a bucket subdir.

Tests that we correctly translate local FS-specific delimiters ('' on
Windows) to bucket delimiter (/).
subdirobjr#   )tmpdirr   contentsr   zsubdir/ar&   r   z
subdir/objr   N)CreateTempDirospathjoinmkdirr   r   r   r   r   r   )r   r.   r,   r   r   r   s         r    #testCopyingNestedFileToBucketSubdir2TestParallelCp.testCopyingNestedFileToBucketSubdirJ   s     !FWW\\&(+FHHV""&EC"PH&&(NNND(D$DEFNND(D$BCD'':ET.*5uQx@T.,7qBr#   c           	         U R                  5       nU R                  / SQS9nU R                  SSU[        U5      /5        [        R
                  R                  U5      S   nU R                  US5      nU R                  [        XSSS	5      US
   5        U R                  [        XS5      US   5        U R                  [        XS5      US   5        U R                  [        XS5      US   5        g)z>Tests recursively copying absolute path directory to a bucket.)r   r%   f2.txt)dir0dir1nested
test_filesr   -Rr      r9   r:   r;   r   r   r%   r&   r8      N)	r   r0   r   r   r1   r2   splitr   r   )r   r   src_dir_root
src_tmpdirr   s        r    "testCopyingAbsolutePathDirToBucket1TestParallelCp.testCopyingAbsolutePathDirToBucket^   s     &&(N%%E & GLNND$d>.BCD|,Q/J'':ET.ffhO1XT.d;U1XFT.d;U1XFT.h?qJr#   c           	      "   U R                  5       nU R                  S/S9nU R                  SS[        R                  R                  USS5      [        U5      /5        U R                  US5      n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.
)r9   r:   foor<   r   r>   r9   r:   r   rG   r   N)	r   r0   r   r1   r2   r3   r   r   r   )r   r   src_dirr   s       r    'testCopyingDirContainingOneFileToBucket6TestParallelCp.testCopyingDirContainingOneFileToBucketn   s     &&(N  -D,E FGNNd
Wff-^  '':ET.&%8%(Cr#   z]The boto lib used for S3 does not handle objects starting with slashes if we use V4 signaturec                     U R                  SS9nU R                  5       nU R                  SU[        U5      S-   /5        U R	                  US5      nU R                  [        U5      S-   US   5        g)zATests copying a file to an object containing consecutive slashes.r   r   r   z//objr   r   Nr   r   s       r    -testCopyingFileToObjectWithConsecutiveSlashes<TestParallelCp.testCopyingFileToObjectWithConsecutiveSlashes   sr    
 ""T"2H&&(NNND(D$87$BCD'':ET.)G3U1X>r#   c           	         U R                  5       nU R                  USSS9  U R                  S/S9nU R                  5       nU R                  SS[	        US5      U< [
        R                  < S3[	        U5      /5        U R                  US	5      nU R                  [	        US5      US
   5        U R                  [	        US5      US   5        g)z,Tests copying objects and files to a bucket.r%      fooobject_namer/   f2r<   r   r>   **r&   r   r   N)	r   CreateObjectr0   r   r   r1   sepr   r   )r   src_bucket_urirH   r   r   s        r    testCopyingObjsAndFilesToBucket.TestParallelCp.testCopyingObjsAndFilesToBucket   s     &&(Nn$H  TF 3G&&(NNNd^T"RVV$^	  '':ET.$/q:T.$/q:r#   c           	         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        U R                  US5      nU R                  [	        US	5      US
   5        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/dir2rG   )r.   r   r   r>   z/dir1dir3r   zdir3/dir2/foor   N)r0   r   r   r   r   r   r   )r   rH   r   r   s       r    -testCopyingSubdirRecursiveToNonexistentSubdir<TestParallelCp.testCopyingSubdirRecursiveToNonexistentSubdir   s       "Gw5G&&(NNN	tWw&	nf	%	'( '':ET./:E!HEr#   c                   ^ ^^ S H  nT R                  5       mT R                  TSSS9  T R                  TSSS9  T R                  / SQS9n[        S5       Hf  mT R	                  S	[
        R                  R                  US
5      [        TST-  5      U-   /5        [        [        SSS9UUU 4S j5       nU" 5         Mh     M     g)z2Tests copying wildcarded files to a bucket subdir. /zsubdir0/existingrO   rP   zsubdir1/existing)r   r%   rR   r<   r&   r   zf?subdir%dr@   r   )triestimeout_secsc                    > TR                  S[        TST-  S5      /SS9n U R                  S5      nTR                  S[	        U5      5        TR                  [        TST-  S5      US	   5        TR                  [        TST-  S
5      US   5        TR                  [        TST-  S5      US   5        TR                  [        TST-  S5      US   5        g)z7Validate files were copied to the correct destinations.lsra   rS   T)return_stdout
   existingr   r   r   r%   r&   rR   r@   N)r   r   rA   r   len)stdoutr   r   ir   s     r    _Check1HTestParallelCp.testCopyingWildcardedFilesToBucketSubDir.<locals>._Check1   s     >>T.*q.$?@  " "& ,,t$%


1c%j
)


4
Q
K 8%


4
QEuQx
P


4
QEuQx
P


4
QEuQx
Pr#   N)r   rT   r0   ranger   r1   r2   r3   r   r
   AssertionError)r   final_dst_charrH   rm   r   rl   s   `   @@r    (testCopyingWildcardedFilesToBucketSubDir7TestParallelCp.testCopyingWildcardedFilesToBucketSubDir   s     $((*n
$6!'  ) $6!'  ) "".@"AgQx!GGLL$'a0>A
 	 
~QQ	7	Q 
8	Q 		+  $r#   c                 P   S GH  nU R                  5       nU R                  USSS9  U R                  USSS9  [        S5       HB  nU R                  S/S9nU R	                  S	S
[        US5      [        USU-  5      U-   /5        MD     U R                  US5      nU R                  [        USSSSS5      US   5        U R                  [        USS5      US   5        U R                  [        USSSSS5      US   5        U R                  [        USS5      US   5        GM"     g)z1Tests copying one nested file to a bucket subdir.r^   zd0/placeholderrO   rP   zd1/placeholderr&   )d3d4r;   r%   r<   r   z-rru   zd%dr?   d0rv   r;   r%   r   placeholderr   d1r@   N)r   rT   ro   r0   r   r   r   r   )r   rq   r   rl   rH   r   s         r    &testCopyingOneNestedFileToBucketSubDir5TestParallelCp.testCopyingOneNestedFileToBucketSubDir   sH    $((*n
$4!'  ) $4!'  ) Qx!$$1M0N$O$$+n<
 	  )).!<e
tND$hMQx!
tND-@%(K
tND$hMQx!
tND-@%(K1 $r#    N)__name__
__module____qualname____firstlineno____doc__r	   r!   r)   r5   rD   rI   r   rL   rW   r[   rr   rz   __static_attributes__r|   r#   r    r   r   1   s    + ; !; !	; !	; !C !C& !K !K !D !D"  < = ? !=? !; !;" !F !F* !" !"H !L !Lr#   r   )r   
__future__r   r   r   r   r1   gslib.tests.testcaseteststestcase)gslib.tests.testcase.integration_testcaser   gslib.tests.utilr   r   r	   gslib.utils.retry_utilr
   GsUtilIntegrationTestCaser   r|   r#   r    <module>r      sC   , ' %  ' 	 ' ' ? 0 : (DLX77 DLr#   