
    daf                         d dl Z d dl mZ  G d d      Z G d de j                        Zedk(  r e j                          yy)    N)mockc                       e Zd Zd Zd Zy)SampleObjectc                      y N selfs    C/root/Python-3.12.4/Lib/test/test_unittest/testmock/testsealable.pymethod_sample1zSampleObject.method_sample1       d    c                      y r   r   r	   s    r   method_sample2zSampleObject.method_sample2	   r   r   N)__name__
__module____qualname__r   r   r   r   r   r   r      s    ""r   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d Zd Zd Zd Zy)TestSealablec                 T   t        j                         }| j                  |j                  t         j                         | j                  |j                         t         j                         | j                  |j                         j	                         t         j                         y r   )r   MockassertIsInstancetesttest2r
   ms     r   ,test_attributes_return_more_mocks_by_defaultz9TestSealable.test_attributes_return_more_mocks_by_default   s`    IIKaffdii0affh		2affhnn.		:r   c                 $   t        j                         }t        j                  |       | j                  t              5  |j
                   d d d        | j                  t              5   |        d d d        y # 1 sw Y   /xY w# 1 sw Y   y xY wr   r   r   sealassertRaisesAttributeErrorr   r   s     r   .test_new_attributes_cannot_be_accessed_on_sealz;TestSealable.test_new_attributes_cannot_be_accessed_on_seal   so    IIK		!~. 	FF	~. 	C	 		 		 	s   A:)B:BBc                     t        j                         }t        j                  |       | j                  t              5  d|_        d d d        y # 1 sw Y   y xY wN   r   r   s     r   )test_new_attributes_cannot_be_set_on_sealz6TestSealable.test_new_attributes_cannot_be_set_on_seal   sB    IIK		!~. 	AF	 	 	   AAc                     t        j                         }d|j                  _        t        j                  |       d|j                  _        | j                  |j                  j                  d       y )Nr&      )r   r   r   r   r    assertEqualr   s     r   +test_existing_attributes_can_be_set_on_sealz8TestSealable.test_existing_attributes_can_be_set_on_seal%   sF    IIK		!q)r   c                     t        j                         }d|j                  _        t        j                  |       | j                  t              5  d|j                  _        d d d        y # 1 sw Y   y xY wr%   )r   r   r   r   r    r!   r"   test3r   s     r   2test_new_attributes_cannot_be_set_on_child_of_sealz?TestSealable.test_new_attributes_cannot_be_set_on_child_of_seal-   sQ    IIK		!~. 	AFFL	 	 	s   A++A4c                     t        j                         }d|j                  _        t        j                  |       | j                  |j                         d       y )N   )r   r   r   return_valuer    r+   r   s     r   +test_existing_attributes_allowed_after_sealz8TestSealable.test_existing_attributes_allowed_after_seal5   s:    IIK		!1%r   c                     t        j                  d      }t        j                  |       | j                  |j                  d       y )Nr&   )
test_value)r   r   r    r+   r5   r   s     r   .test_initialized_attributes_allowed_after_sealz;TestSealable.test_initialized_attributes_allowed_after_seal=   s/    II#		!q)r   c                     t        j                         }t        j                  |       | j                  t              5   |        d d d        y # 1 sw Y   y xY wr   )r   r   r    r!   r"   r   s     r   test_call_on_sealed_mock_failsz+TestSealable.test_call_on_sealed_mock_failsC   s@    IIK		!~. 	C	 	 	r(   c                     t        j                  d      }t        j                  |       | j                   |       d       y )N   )r2   )r   r   r    r+   r   s     r   )test_call_on_defined_sealed_mock_succeedsz6TestSealable.test_call_on_defined_sealed_mock_succeedsJ   s-    II1%		!a r   c                    t        j                         }d|j                  j                         _        t        j
                  |       | j                  |j                  j                         j                  d       | j                  t              5  |j                  j                         j                   d d d        | j                  t              5  |j                  j                   d d d        y # 1 sw Y   >xY w# 1 sw Y   y xY w)N   )
r   r   test1r   r.   r    r+   r!   r"   test4r   s     r   &test_seals_recurse_on_added_attributesz3TestSealable.test_seals_recurse_on_added_attributesP   s    IIK !		!..2~. 	"GGMMO!!	"~. 	GGMM	 		" 	"	 	s   %C4D 4C= D	c                    t        j                         }d|j                  j                  d   _        d|j                  j                  dd _        t        j
                  |       | j                  |j                  j                  d   j                  d       | j                  |j                  j                  dd j                  d       | j                  t              5  |j                  j                  d   j                   d d d        | j                  t              5  |j                  j                  dd j                   d d d        y # 1 sw Y   KxY w# 1 sw Y   y xY w)Nr=   ar*   r:   )
r   	MagicMockr>   r   r.   r    r+   r!   r"   r?   r   s     r   #test_seals_recurse_on_magic_methodsz0TestSealable.test_seals_recurse_on_magic_methods\   s   NN#$c #$a 		!s+1115q+1115~. 	%GGMM#$$	%~. 	%GGMM!A$$	% 	%	% 	%	% 	%s   !$E"$EEE$c                    t        j                  d      }t        j                  d      |j                  _        d|j                  j                  _        t        j
                  |       | j                  |j                  j                  j                  d       |j                  j                  j                   d|j                  j                  _        y )N	root_mockname
not_sealedr=   r&   )r   r   r>   r   r.   r    r+   r?   r   s     r   ,test_seals_dont_recurse_on_manual_attributesz9TestSealable.test_seals_dont_recurse_on_manual_attributesj   s~    II;'		|4		!,,a0	r   c                 X   t        j                  t              }d|_        d|_        t        j
                  |       | j                  |j                  d       | j                  |j                  d       | j                  t              5  |j                   ddd       y# 1 sw Y   yxY w)z0You are not restricted when using mock with specr&   r1   N)
r   r   r   attr_sample1attr_sample3r    r+   r!   r"   attr_sample2r   s     r   )test_integration_with_spec_att_definitionz6TestSealable.test_integration_with_spec_att_definitionu   s{    IIl#		!++~. 	NN	 	 	s   
B  B)c                 6   t        j                  t              }d|j                  _        t        j
                  |       | j                  |j                         d       | j                  t              5  |j                          ddd       y# 1 sw Y   yxY w)z<You need to define the methods, even if they are in the specr&   N)
r   r   r   r   r2   r    r+   r!   r"   r   r   s     r   ,test_integration_with_spec_method_definitionz9TestSealable.test_integration_with_spec_method_definition   sq    IIl#()%		!))+Q/~. 		 	 	s   5BBc                     t        j                  t              }| j                  t              5  d|j
                  _        ddd       y# 1 sw Y   yxY w)z)You cannot define methods out of the specr1   N)r   r   r   r!   r"   method_sample3r2   r   s     r   :test_integration_with_spec_method_definition_respects_speczGTestSealable.test_integration_with_spec_method_definition_respects_spec   sA    IIl#~. 	.,-A)	. 	. 	.s   A

Ac                    t        j                         }t        j                  |       | j                  t              5 }|j
                   d d d        | j                  dt        j                               y # 1 sw Y   /xY w)NSECRETE_name)	r   r   r    r!   r"   rV   assertInstr	exceptionr
   r   cms      r   (test_sealed_exception_has_attribute_namez5TestSealable.test_sealed_exception_has_attribute_name   s[    IIK		!~. 	"NN	nc",,&78	 	s   A::Bc                    t        j                  d      }|j                  j                  j                  j
                   t        j                  |       | j                  t              5 }|j                  j                  j                  j
                  j                   d d d        | j                  dt        j                               y # 1 sw Y   /xY w)N	mock_namerG   z&mock_name.test1.test2.test3.test4.boom)r   r   r>   r   r.   r?   r    r!   r"   boomrW   rX   rY   rZ   s      r   "test_attribute_chain_is_maintainedz/TestSealable.test_attribute_chain_is_maintained   s    II;'	!!		!~. 	+"GGMM%%**	+>BLL@QR	+ 	+s   +5CCc                    t        j                         }|j                         j                  j	                         j
                   t        j                  |       | j                  t              5 }|j                         j                  j	                         j                          d d d        | j                  dt        j                               y # 1 sw Y   /xY w)Nz mock.test1().test2.test3().test4)r   r   r>   r   r.   r?   r    r!   r"   rW   rX   rY   rZ   s      r   test_call_chain_is_maintainedz*TestSealable.test_call_chain_is_maintained   s    IIK		%%		!~. 	,"GGIOO!!#))+	,8#bll:KL	, 	,s   17CCc                 :
    G d d      }dD ]  }| j                  |      5  t        j                  ||      }d|j                  _        d|j
                  j                  _        t        j                  |       | j                  |j                  t        j                         | j                  |j                  t        j                         | j                  |j                  t        j                         | j                  |j
                  t        j                         | j                  |j
                  j                  t        j                         | j                  |j
                  j                  t        j                         | j                  |j                         t        j                         | j                  |j                         d       d|j                  _        | j                  |j                         d       | j                  |j
                  j                         d       d|j
                  j                  _        | j                  |j
                  j                         d       | j                  t               5  |j                          d d d        | j                  t"              5  d	|_        d d d        | j                  t"              5  |j                         j&                   d d d        d
|j                  _        | j                  |j                         d
       | j                  t"              5  |j(                   d d d        | j                  t"              5  d	|_        d d d        | j                  t"              5  |j+                          d d d        | j                  t               5  |j
                  j                          d d d        | j                  t"              5  |j
                  j(                   d d d        | j                  t"              5  d	|j
                  _        d d d        | j                  t"              5  |j
                  j+                          d d d        d d d         y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   cxY w# 1 sw Y   KxY w# 1 sw Y   *xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)Nc                   0    e Zd ZdZd Zd Z G d d      Zy)1TestSealable.test_seal_with_autospec.<locals>.Foor   c                      y r   r   r	   s    r   bar1z6TestSealable.test_seal_with_autospec.<locals>.Foo.bar1       Dr   c                      y r   r   r	   s    r   bar2z6TestSealable.test_seal_with_autospec.<locals>.Foo.bar2   rh   r   c                       e Zd ZdZd Zy)5TestSealable.test_seal_with_autospec.<locals>.Foo.Bazr1   c                      y r   r   r	   s    r   banz9TestSealable.test_seal_with_autospec.<locals>.Foo.Baz.ban   s    tr   N)r   r   r   bazrn   r   r   r   Bazrl      s
    #r   rp   N)r   r   r   foorg   rj   rp   r   r   r   Foore      s    C  $ $r   rr   )TF)spec_setrB   bnew_anew_br&   rj   )subTestr   create_autospecrg   r2   rp   rn   r    r   rq   NonCallableMagicMockrC   rj   ro   r+   r!   	TypeErrorr"   barxmissing_attrmissing_method)r
   rr   rs   rq   s       r   test_seal_with_autospecz$TestSealable.test_seal_with_autospec   s   	$ 	$ & 0	-Hx0 /-**3B(+%+.(		#%%cggt/H/HI%%chh?%%chh?%%cggt~~>%%cggkk43L3LM%%cggkk4>>B %%chhj$..A  S1(/%  W5  4+2(  8&&y1 GGI&&~6  CG &&~6 !HHJLL! )/%  V4&&~6 %$$%&&~6 )'(C$)&&~6 )&&()&&y1 "GGKKM"&&~6 )GG(()&&~6 -+,CGG(-&&~6 -GG**,-]/- /-0	-2    ! !% %) )) )" ") )- -- -]/- /-s   I,TR T=RT"R,=ATR9T5S=TS+TS #T S,T4S8T#T>TRTR)$T,R61T9S>TSTST S)%T,S51T8T=TT	TT	N)r   r   r   r   r#   r'   r,   r/   r3   r6   r8   r;   r@   rD   rJ   rO   rQ   rT   r\   r`   rb   r   r   r   r   r   r      sc    ;*&*!
%	 	.9SM;-r   r   __main__)unittestr   r   TestCaser   r   mainr   r   r   <module>r      sD     # #]-8$$ ]-@ zHMMO r   