
    !'                         S SK r S SKJrJr  SSKJr   " S S\ R                  5      r\S:X  a  \ R                  " 5         gg)    N)Mockcall   )Watchc                   P    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rSrg)
WatchTests   c                     SU l         g )Nr   	callcount)selfs    .lib/third_party/kubernetes/watch/watch_test.pysetUpWatchTests.setUp   s	    DN    c                 B   [        5       n[        5       Ul        [        5       Ul        [        / SQS9Ul        [        5       n[        US9Ul        SUR                  l        [        5       nSnUR                  UR                  5       H  nU R                  SUS   5        U R                  SU-  US   R                  R                  5        U R                  S	U-  US   R                  R                  5        U R                  S	U-  UR                  5        US-  nUS
:X  d  M  UR                  5         M     UR                  R                  SSS9  UR                  R                  SS9  UR                  R                  5         UR                  R                  5         g )N)n{"type": "ADDED", "object": {"metadata": {"name": "test1","resourceVersion": "1"}, "spec": {}, "status": {}}}
c{"type": "ADDED", "object": {"metadata": {"name": "test2","resourceVersion": "2"}, "spec": {}, "staytus": {}}}
{"type": "ADDED", "object": {"metadata": {"name": "test3","resourceVersion": "3"}, "spec": {}, "status": {}}}
zshould_not_happened
return_value:return: V1NamespaceListr   ADDEDtypeztest%dobjectz%d   FT_preload_contentwatchdecode_content)r   closerelease_connread_chunkedget_namespaces__doc__r   streamassertEqualmetadatanameresource_versionstopassert_called_once_withassert_called_oncer   	fake_respfake_apiwcountes         r   test_watch_with_decode!WatchTests.test_watch_with_decode   sb   IfIO!VI! 0 I vH"	:H&@H#AEXXh--.
w&	*
x%'8)=)=)B)BC
te|Qx[%9%9%J%JK
te|Q%7%78qje 
!	 / 33d 4 ,22%2HOO&&(--/r   c                 N   [        5       n[        5       Ul        [        5       Ul        [        SS/S9Ul        [        5       n[        US9Ul        SUR                  l        [        5       nSnUR                  UR                  5       H2  nU R                  SU5        US-  nUS:X  d  M"  UR                  5         M4     UR                  R                  SS	S
9  UR                  R                  SS9  UR                  R                  5         UR                  R                  5         g )Nzlog_line_1
zlog_line_2
r   z :param bool follow:
:return: strr   
log_line_1   FT)r   followr    )r   r"   r#   r$   read_namespaced_pod_logr&   r   r'   r(   r,   r-   r.   r/   s         r   test_watch_for_follow WatchTests.test_watch_for_followE   s    IfIO!VI!/OPIvH'+'CH$16H$$, 	AEXXh667
|Q'qje 
!	 8 $$<<t = -22%2HOO&&(--/r   c           	        ^ ^
 [        5       n[        5       Ul        [        5       Ul        / SQm
U U
4S jn[        US9Ul        [        5       n[        US9Ul        SUR                  l        [        5       n/ nSnUR                  [        SSS	S
95        UR                  [        SSS	S
95        [        U5       H  nUR                  [        SSSS
95        M     [        UR                  UR                  S	S95       H)  u  pU[        T
5      U-  :X  d  M  UR                  5         M+     UR                  R                  U5        T R                  UR                  R                   U5        g )N)r   r   r   c                  V   > T=R                   S-  sl         TR                   S:X  a  / $ T$ )Nr   r   )argskwargsr   valuess     r   
get_values>WatchTests.test_watch_resource_version_set.<locals>.get_valuest   s'    
nnn	1		r   side_effectr   r   r9   FT5)r   r   r+   3)r+   )r   r"   r#   r$   r%   r&   r   appendr   range	enumerater'   lenr,   assert_has_callsr(   
mock_calls)r   r0   rC   r1   r2   calls
iterationsicr4   rB   s   `         @r   test_watch_resource_version_set*WatchTests.test_watch_resource_version_set`   s<    IfIO!VIF "j9IvH"	:H&@H#A
 EJ 
LLuD3OP	LLuD3OP: ll
TC
HJ	  	((3?A	
c&kJ&	&	A ,,U3X,,77?r   c                 r   [        [        5      nS GH!  n[        5       n[        5       Ul        [        5       Ul        [        S/S-  S9Ul        [        5       n[        US9Ul        SUR                  l        SnUR                  UR                  5       H   nUS-  nUS:X  d  M  UR                  5         M"     U R                  US5        UR                  R                  SS	S
9  UR
                  R                  SS9  UR                  R                  5         UR                  R                  5         GM$     g )N)firstsecond{"type": "ADDED", "object": 1}
r   r   r   r      FTr   r    )r   floatr   r"   r#   r$   r%   r&   r'   r,   r(   r-   r.   )r   r2   stepr0   r1   r3   r4   s          r   test_watch_stream_twice"WatchTests.test_watch_stream_twice   s   eA#&iio#vi#:;a? Ai h $) <h(Bh%exx//0!
A:
&&( 1
 ua 55  6 .44E4Joo((*//1- $r   c                 (   [        [        5      n[        5       n[        5       Ul        [        5       Ul        [        S/S9Ul        [        5       n[        US9Ul        SUR                  l        SnUR                  UR                  SS9 H  nUS-   nM
     U R                  US5        UR                  UR                  5       H   nUS-   nUS:X  d  M  UR                  5         M"     U R                  US5        U R                  UR                  R                  S5        U R                  UR
                  R                  S5        U R                  UR                  R                  S5        U R                  UR                  R                  S5        g )NrX   r   r   r   r   )timeout_secondsr9   )r   rZ   r   r"   r#   r$   r%   r&   r'   r(   r,   
call_count)r   r2   r0   r1   r3   r4   s         r   test_watch_stream_loop!WatchTests.test_watch_stream_loop   sN   eAIfIO!VI!89;I vH"	:H&@H#E XXh--qXAaie BUA XXh--.aie	!	 /
 	UAX,,77;Y++66:Y__//3Y++66:r   c                     [        5       nUR                  SS5      nU R                  SUS   5        U R                  SUS   5        U R                  [	        US   [
        5      5        U R                  SUS   5        g )	Nz{"type": "ADDED", "object": 1}rZ   r   r   g      ?r   r   
raw_object)r   unmarshal_eventr(   
assertTrue
isinstancerZ   r   r2   events      r    test_unmarshal_with_float_object+WatchTests.test_unmarshal_with_float_object   sp    A>HEWeFm,S%/*OOJuX67Ql+,r   c                     [        5       nUR                  SS 5      nU R                  SUS   5        U R                  S/US   5        U R                  S/US   5        g )Nz&{"type": "ADDED", "object": ["test1"]}r   r   test1r   rd   )r   re   r(   rh   s      r   "test_unmarshal_with_no_return_type-WatchTests.test_unmarshal_with_no_return_type   s]    AFMEWeFm,gYh0gYl 34r   c                    [        5       nUR                  SS5      nU R                  SUS   5        U R                  [	        US   [
        5      5        U R                  SUS   S   S   5        U R                  SUR                  5        g )Nz~{"type": "ADDED", "object": {"apiVersion":"test.com/v1beta1","kind":"foo","metadata":{"name": "bar", "resourceVersion": "1"}}}r   r   r   1r)   resourceVersion)r   re   r(   rf   rg   dictr+   rh   s      r   !test_unmarshal_with_custom_object,WatchTests.test_unmarshal_with_custom_object   s    A	45=?E 	WeFm, 	OOJuX56S%/*56GHIS!,,-r   c                    [        5       n[        5       Ul        [        5       Ul        [        [        S5      S9Ul        [        5       n[        US9Ul        [        5       n UR                  UR
                  5       H  nU R                  U S5        M     UR
                  R                  SSS9  UR                  R                  SS9  UR                  R                  5         UR                  R                  5         g ! [         a     Ntf = f)	NexpectedrE   r   zShould fail on exception.FTr   r    )r   r"   r#   KeyErrorr$   	get_thingr   r'   failr-   r.   )r   r0   r1   r2   _s        r   test_watch_with_exception$WatchTests.test_watch_with_exception   s    IfIO!VI!hz.BCIvH95HAxx**+!		$34 , ..d / ,22%2HOO&&(--/  
s   #4C? ?
DDr   N)__name__
__module____qualname____firstlineno__r   r5   r<   rS   r\   ra   rj   rn   rt   r|   __static_attributes__ r   r   r   r      s8    %0N06?@B24;@-5.0r   r   __main__)
unittestmockr   r   r   r   TestCaser   r~   mainr   r   r   <module>r      s=   "   t0"" t0n z
--/ r   