
    ;9                        S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSK	J
r
  SSKJr  SS	KJr  SS
KJr  SSKJs  Jr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  \R2                  " \S5      \R2                  " \R4                  S:  S5       " S S\R6                  5      5       5       r  SS jr\R2                  " \S5       " S S\R<                  R>                  5      5       r g)%Integration tests for tab completion.    )absolute_import)print_function)division)unicode_literalsN)CreateOrGetGsutilLogger)CloudObjectCompleter)TAB_COMPLETE_CACHE_TTL)TabCompletionCache)ARGCOMPLETE_AVAILABLE)SetBotoConfigForTest)unittest)WorkingDirectory)GetTabCompletionCacheFilenamez#Tab completion requires argcomplete)      	   z3Tab completion is only supported on Python < 3.11.9c                   h   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
 rS rS rS rSrU =r$ )TestTabComplete&   r   c                 J   > [         [        U ]  5         [        S5      U l        g )Ntab_complete)superr   setUpr   logger)self	__class__s    /platform/gsutil/gslib/tests/test_tabcomplete.pyr   TestTabComplete.setUp-   s    	/4&().9DK    c                     U R                  SSS9nU R                  U5        U R                  < SUSS < 3nSU-  nU R                  SU/U/S	9  g)
z.Tests tab completion matching a single bucket.bucketaaa-prefix://N//%s/lsexpected_resultsMakeTempNameCreateBucketdefault_providerRunGsUtilTabCompletionr   bucket_namerequestexpected_results       r   test_single_bucket"TestTabComplete.test_single_bucket1   sh     ##HV#<Kk"00+cr2BCG+Ow2A1B   Dr    c                     U R                  SSS9nU R                  U5        U R                  < SUSS < 3nSU-  nU R                  SU/U/S	9  g)
z:Tests bucket-only tab completion matching a single bucket.r"   r#   r$   r&   Nr'   //%s rbr*   r,   r1   s       r   test_bucket_only_single_bucket.TestTabComplete.test_bucket_only_single_bucket>   sh     ##HV#<Kk"00+cr2BCG+Ow2A1B   Dr    c                     U R                  S5      nU R                  USS9nU R                  < SUR                  < SUSS < 3nU R	                  SU// S	9  g)
z<Tests that bucket-only tab completion doesn't match objects.obj   dataobject_namecontentsr&   /Nr'   r9   r*   r-   CreateObjectr/   r2   r0   )r   r@   
object_urir3   s       r   test_bucket_only_no_objects+TestTabComplete.test_bucket_only_no_objectsK   sd     ##E*K""{W"MJ"33Z5K5K)#2.0G 	w"Er    c                     U R                  S5      nUS-   nU R                  USS9nU R                  < SUR                  < S3nSUR                  < SU< S3nU R	                  SU/U/S	9  g
)z4Tests tab completion matching a single subdirectory.r=   z/subobjr>   r?   r&   rB   //r)   r*   NrC   )r   object_base_namer@   rE   r3   r4   s         r   test_single_subdirectory(TestTabComplete.test_single_subdirectoryV   s{     ((/"Y.K""{W"MJ 11:3I3IJG$.$:$:<LMOw2A1B   Dr    c                 2   U R                  S5      nSnU R                  UUSS9  U R                  UUSS9  U R                  < SSR                  X!/5      < 3nSSR                  X!S/5      -  nSSR                  X!S/5      -  nU R	                  S	U/XE/S
9  g)z/Tests tab completion matching multiple buckets.r"   r#   1)bucket_name_prefixbucket_name_suffix2r&    r(   r)   r*   N)r-   r.   r/   joinr0   )r   	base_namer%   r3   expected_result1expected_result2s         r   test_multiple_buckets%TestTabComplete.test_multiple_bucketsc   s     !!(+IFi)/),  . 	i)/),  .  00"''6:M2NOG&S)A!BB&S)A!BB	w+;*N   Pr    c                     U R                  S5      nU R                  USS9nU R                  < SUR                  < SUSS < 3nSUR                  < SU< S	3nU R	                  S
U/U/S9  g)z.Tests tab completion matching a single object.r=   r>   r?   r&   rB   Nr'   rI    r)   r*   rC   )r   r@   rE   r3   r4   s        r   test_single_object"TestTabComplete.test_single_objectw   s{     ##E*K""{W"MJ"33Z5K5K)#2.0G$.$:$:KHOw2A1B   Dr    c                 V   U R                  5       nU R                  S5      nUS-   nU R                  UUSS9  US-   nU R                  UUSS9  U R                  < SUR                  < SU< 3nSUR                  < SU< 3nSUR                  < SU< 3nU R                  S	U/Xg/S
9  g)z/Tests tab completion matching multiple objects.r=   z-suffix1r>   )
bucket_urir@   rA   z-suffix2r&   rB   rI   r)   r*   N)r.   r-   rD   r/   r2   r0   )r   r^   rJ   object1_nameobject2_namer3   rU   rV   s           r   test_multiple_objects%TestTabComplete.test_multiple_objects   s     ""$J((/#j0L".&  ( $j0L".&  ( #33Z5K5K.0G$.$:$:LI$.$:$:LI	w+;*N   Pr    c                    U R                  SSS9nU R                  U5        U R                  < SUSS < 3nSU-  nSnU R                  U/S	9nU< [        R
                  < 3nS
[        R                  R                  XT5      -  nU R                  SSU/U/S9  U R                  SSU/U/S9  U R                  SSSU/U/S9  g)z3Tests tab completion for commands with subcommands.r"   r#   r$   r&   Nr'   r8   a_local_file
test_files%s corsgetr*   set	some_file)	r-   r.   r/   CreateTempDirosseppathrS   r0   )r   r2   bucket_requestexpected_bucket_result
local_file	local_dirlocal_file_requestexpected_local_file_results           r   test_subcommands TestTabComplete.test_subcommands   s     ##HV#<Kk""&"7"7Sb9IJN${2J""zl";I#,bff5!&i)L!L 	 ?2H1I   K 	0B C2L1M   O 	^ L2H1I   Kr    c                     U R                  SSS9nUS-   nU R                  U5        U R                  < SU< S3nSU-  nU R                  SU/U/S	9  g
)zTests tab completion with a partial URL that by itself is not valid.

The bucket name in a Cloud URL cannot end in a dash, but a partial URL
during tab completion may end in a dash and completion should still work.
r"   r#   r$   z-sr&   -r(   r)   r*   Nr,   )r   bucket_base_namer2   r3   r4   s        r    test_invalid_partial_bucket_name0TestTabComplete.test_invalid_partial_bucket_name   sm     ((&(A"T)Kk" 113CDG+Ow2A1B   Dr    c                 |   SnU R                  U/S9nU< [        R                  < 3nS[        R                  R	                  X!5      -  nU R                  SSU/U/S9  U R                  / SQS/S9  S	nU R                  U/S9n[        U5         U R                  / SQUS
/S9  SSS5        g! , (       d  f       g= f)z'Tests tab completion for ACL arguments.rd   re   rg   aclrj   r*   )r~   rj   privzprivate 	priv_fileprivateN)rl   rm   rn   ro   rS   r0   r   )r   rr   rs   rt   ru   s        r   test_acl_argument!TestTabComplete.test_acl_argument   s      J""zl";I#,bff5!&i)L!L 	/A B2L1M   O 	 62<   ? J""zl";I	)	$ !!"84>	3J " L 
%	$	$s   B--
B;)r   )__name__
__module____qualname____firstlineno____doc__r   r5   r:   rF   rK   rW   r[   ra   rv   r{   r   __static_attributes____classcell__)r   s   @r   r   r   &   sO    
 .:DD	FDP(DP.K6D"L Lr    r   c                 ~    Uc  [         R                   " 5       n[        XX#5      nUR                  [        5       5        g )N)timer   WriteToFiler   )r%   results	timestamppartial_resultscaches        r   _WriteTabCompletionCacher      s3     		I
Vi
I%134r    c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)TestTabCompleteUnitTests   zUnit tests for tab completion.c                     [        SSU R                  5       4/5         SnSS/n[        X5        [        U R	                  5       5      nU" U5      nU R                  X$5        SSS5        g! , (       d  f       g= f)z1Tests tab completion results returned from cache.GSUtil	state_dirgs://prefixzgs://prefix1zgs://prefix2Nr   rl   r   r	   MakeGsUtilApiassertEqual)r   r3   cached_results	completerr   s        r   test_cached_results,TestTabCompleteUnitTests.test_cached_results   sn     
+t7I7I7KLM	Ng&7nw7&t'9'9';<i'"g
~/ 
O	N	Ns   AA++
A9c                    [        SSU R                  5       4/5         U R                  S5      nUS-   nU R                  U5        U R                  < SU< 3nU R                  < SU< S3nSU-  SU-  /n[        X5[        R                  " 5       [        -
  5        [        U R                  5       5      nU" U5      nU R                  U/U5        S	S	S	5        g	! , (       d  f       g	= f)
zBTests tab completion results not returned from cache when too old.r   r   r"   z-suffixr&   rB   z//%s1z//%s2N)r   rl   r-   r.   r/   r   r   r
   r	   r   r   )r   rz   r2   r3   r4   r   r   r   s           r   test_expired_cached_results4TestTabCompleteUnitTests.test_expired_cached_results   s     
+t7I7I7KLM	N**84$y0k
$!224DEg&*&;&;[Io+-w/DEnw#yy{-CCE 't'9'9';<i'"g
('2! 
O	N	Ns   B3C
C(c                     [        SSU R                  5       4/5         SnSS/n[        X5        Sn[        U R	                  5       5      nU" U5      nU R                  S/U5        SSS5        g! , (       d  f       g= f)zTests tab completion results returned from cache with prefix match.

If the tab completion prefix is an extension of the cached prefix, tab
completion should return results from the cache that start with the prefix.
r   r   r   zgs://prefix-firstzgs://prefix-secondzgs://prefix-fNr   )r   cached_prefixr   r3   r   r   s         r   test_prefix_caching,TestTabCompleteUnitTests.test_prefix_caching  sz     
+t7I7I7KLM	N#m+-ABn}=g&t'9'9';<i'"g
+,g6 
O	N	Ns   AA//
A=c                    [        SSU R                  5       4/5         U R                  SSS9nU R                  < SUR                  < S3nU R                  < SUR                  < S3/n[        X#5        U R                  < SUR                  < S	3nU R                  < SUR                  < S
3n[        U R                  5       5      nU" U5      nU R                  U/U5        SSS5        g! , (       d  f       g= f)zTests tab completion prefix caching not spanning directory boundaries.

If the tab completion prefix is an extension of the cached prefix, but is
not within the same bucket/sub-directory then the cached results should not
be used.
r   r   zsubdir/subobj	   test datar?   r&   rB   z/subdirz/subdir/z/subdir/subobjN	r   rl   rD   r/   r2   r   r	   r   r   )r   rE   r   r   r3   r4   r   r   s           r   test_prefix_caching_boundary5TestTabCompleteUnitTests.test_prefix_caching_boundary%  s     
+t7I7I7KLM	N$$.: % <j %)$9$9$.$:$:<m #33Z5K5K
Ln }=%)%:%:%/%;%;=g373H3H3=3I3IKo 't'9'9';<i'"g
('2' 
O	N	Ns   C	C00
C>c                    [        SSU R                  5       4/5         U R                  SSS9nU R                  < SUR                  < S3n/ n[        X#5        U R                  < SUR                  < S3n[        U R                  5       5      nU" U5      nU R                  / U5        S	S	S	5        g	! , (       d  f       g	= f)
a  Tests tab completion returning empty result set using cached prefix.

If the tab completion prefix is an extension of the cached prefix, but does
not match any of the cached results then no remote request should be made
and an empty result set should be returned.
r   r   r=   r   r?   r&   rB   /oNr   r   rE   r   r   r3   r   r   s          r   test_prefix_caching_no_results7TestTabCompleteUnitTests.test_prefix_caching_no_resultsB  s     
+t7I7I7KLM	N$$$Nj$($9$9$.$:$:<mn}=#44j6L6LMg&t'9'9';<i'"g
r7# 
O	N	Ns   BB44
Cc                    [        SSU R                  5       4/5         U R                  SSS9nU R                  < SUR                  < S3n/ n[        UUSS	9  U R                  < SUR                  < S
3n[        U R                  5       5      nU" U5      nU R                  [        U5      /U5        SSS5        g! , (       d  f       g= f)a  Tests tab completion prefix matching ignoring partial cached results.

If the tab completion prefix is an extension of the cached prefix, but the
cached result set is partial, the cached results should not be used because
the matching results for the prefix may be incomplete.
r   r   r=   r   r?   r&   rB   T)r   r   N)
r   rl   rD   r/   r2   r   r	   r   r   strr   s          r   #test_prefix_caching_partial_results<TestTabCompleteUnitTests.test_prefix_caching_partial_resultsY  s     
+t7I7I7KLM	N$$$Nj$($9$9$.$:$:<mn}-/35  $44j6L6LMg&t'9'9';<i'"g
J('2 
O	N	Ns   BB>>
C N)r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r      s%     '03*7$3:$.3r    r   )NF)!r   
__future__r   r   r   r   rm   r   sysgslib.commandr   gslib.tab_completer	   r
   r   gslib.tests.testcaseteststestcasegslib.tests.utilr   r   r   r   gslib.utils.boto_utilr   
skipUnlessversion_infoGsUtilIntegrationTestCaser   r   unit_testcaseGsUtilUnitTestCaser   r   r    r   <module>r      s    , & %  ' 	  
 1 3 5 1 ' ' 2 1 % - ? 
*:<	S%%
2JLtLh88 tLL<tLr (,-25 
*:<C3x55HH C3<C3r    