
    =e                         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                     dS dS )    N)mockc                       e Zd Zd Zd ZdS )SampleObjectc                     d S N selfs    :/usr/lib/python3.11/unittest/test/testmock/testsealable.pymethod_sample1zSampleObject.method_sample1             c                     d S 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dS )TestSealablec                 b   t          j                    }|                     |j        t           j                   |                     |                                t           j                   |                     |                                                                t           j                   d S r   )r   MockassertIsInstancetesttest2r
   ms     r   ,test_attributes_return_more_mocks_by_defaultz9TestSealable.test_attributes_return_more_mocks_by_default   sw    IKKafdi000affhh	222affhhnn..	:::::r   c                 @   t          j                    }t          j        |           |                     t                    5  |j         d d d            n# 1 swxY w Y   |                     t                    5   |             d d d            d S # 1 swxY w Y   d S 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   s   IKK	!~.. 	 	FF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	~.. 	 	ACCC	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s$   AAA;BBBc                     t          j                    }t          j        |           |                     t                    5  d|_        d d d            d S # 1 swxY w Y   d S N   r   r   s     r   )test_new_attributes_cannot_be_set_on_sealz6TestSealable.test_new_attributes_cannot_be_set_on_seal   s    IKK	!~.. 	 	AF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                     t          j                    }d|j        _        t          j        |           d|j        _        |                     |j        j        d           d S )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%   sL    IKK	!q)))))r   c                     t          j                    }d|j        _        t          j        |           |                     t                    5  d|j        _        d d d            d S # 1 swxY w Y   d S 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-   s    IKK	!~.. 	 	AFL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A((A,/A,c                     t          j                    }d|j        _        t          j        |           |                     |                                d           d S N   )r   r   r   return_valuer    r*   r   s     r   +test_existing_attributes_allowed_after_sealz8TestSealable.test_existing_attributes_allowed_after_seal5   sH    IKK	!1%%%%%r   c                     t          j        d          }t          j        |           |                     |j        d           d S )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?    I###	!q)))))r   c                     t          j                    }t          j        |           |                     t                    5   |             d d d            d S # 1 swxY w Y   d S r   )r   r   r    r!   r"   r   s     r   test_call_on_sealed_mock_failsz+TestSealable.test_call_on_sealed_mock_failsC   s    IKK	!~.. 	 	ACCC	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA!Ac                     t          j        d          }t          j        |           |                      |            d           d S )N   )r2   )r   r   r    r*   r   s     r   )test_call_on_defined_sealed_mock_succeedsz6TestSealable.test_call_on_defined_sealed_mock_succeedsJ   sC    I1%%%	!a     r   c                    t          j                    }d|j                                        _        t          j        |           |                     |j                                        j        d           |                     t                    5  |j                                        j	         d d d            n# 1 swxY w Y   |                     t                    5  |j        j         d d d            d S # 1 swxY w Y   d S N   )
r   r   test1r   r-   r    r*   r!   r"   test4r   s     r   &test_seals_recurse_on_added_attributesz3TestSealable.test_seals_recurse_on_added_attributesP   sL   IKK !	!.222~.. 	" 	"GMMOO!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"~.. 	 	GMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s$   B==CC"C<<D D c                    t          j                    }d|j        j        d         _        d|j        j        dd         _        t          j        |           |                     |j        j        d         j        d           |                     |j        j        dd         j        d           |                     t                    5  |j        j        d         j	         d d d            n# 1 swxY w Y   |                     t                    5  |j        j        dd         j	         d d d            d S # 1 swxY w Y   d S )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   N#$c #$ac 	!s+11555qs+11555~.. 	% 	%GM#$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%~.. 	% 	%GM!A#$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s$   
C..C25C2D::D>D>c                 F   t          j        d          }t          j        d          |j        _        d|j        j        _        t          j        |           |                     |j        j        j        d           |j        j        j         d|j        j        _        d S )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    I;'''	|444	!,a000	r   c                 ^   	 t          j        t                    }d|_        d|_        t          j        |           |                     |j        d           |                     |j        d           |                     t                    5  |j	         d d d            d S # 1 swxY w Y   d S )Nr&   r1   )
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    >Il##	!++++++~.. 	 	NN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   B""B&)B&c                 X   	 t          j        t                    }d|j        _        t          j        |           |                     |                                d           |                     t                    5  |	                                 d d d            d S # 1 swxY w Y   d S r%   )
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   s    JIl##()%	!))++Q///~.. 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   =BB#&B#c                     	 t          j        t                    }|                     t                    5  d|j        _        d d d            d S # 1 swxY w Y   d S r0   )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   s    7Il##~.. 	. 	.,-A)	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   AAAc                    t          j                    }t          j        |           |                     t                    5 }|j         d d d            n# 1 swxY w Y   |                     dt          |j                             d S )NSECRETE_name)	r   r   r    r!   r"   rW   assertInstr	exceptionr
   r   cms      r   (test_sealed_exception_has_attribute_namez5TestSealable.test_sealed_exception_has_attribute_name   s    IKK	!~.. 	"NN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	nc",&7&788888s   AAAc                 n   t          j        d          }|j        j        j        j         t          j        |           |                     t                    5 }|j        j        j        j        j	         d d d            n# 1 swxY w Y   | 
                    dt          |j                             d S )N	mock_namerH   z&mock_name.test1.test2.test3.test4.boom)r   r   r?   r   r-   r@   r    r!   r"   boomrX   rY   rZ   r[   s      r   "test_attribute_chain_is_maintainedz/TestSealable.test_attribute_chain_is_maintained   s    I;'''	!!	!~.. 	+"GM%**	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+>BL@Q@QRRRRRs   BB	Bc                    t          j                    }|                                j                                        j         t          j        |           |                     t                    5 }|                                j                                                                         d d d            n# 1 swxY w Y   | 	                    dt          |j                             d S )Nz mock.test1().test2.test3().test4)r   r   r?   r   r-   r@   r    r!   r"   rX   rY   rZ   r[   s      r   test_call_chain_is_maintainedz*TestSealable.test_call_chain_is_maintained   s    IKK			%%	!~.. 	,"GGIIO!!##))+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,8#bl:K:KLLLLLs   2>B<<C C c                 	    G d d          }dD ]}|                      |          5  t          j        ||          }d|j        _        d|j        j        _        t          j        |           |                     |j	        t          j
                   |                     |j        t          j                   |                     |j        t          j                   |                     |j        t          j                   |                     |j        j        t          j
                   |                     |j        j        t          j                   |                     |                                d           d|j        _        |                     |                                d           |                     |j                                        d           d|j        j        _        |                     |j                                        d           |                     t                     5  |	                                 d d d            n# 1 swxY w Y   |                     t"                    5  d	|_        d d d            n# 1 swxY w Y   |                     t"                    5  |                                 d d d            n# 1 swxY w Y   d
|j        _        |                     |                                d
           |                     t"                    5  |j         d d d            n# 1 swxY w Y   |                     t"                    5  d	|_        d d d            n# 1 swxY w Y   |                     t"                    5  |                                 d d d            n# 1 swxY w Y   |                     t                     5  |j                                         d d d            n# 1 swxY w Y   |                     t"                    5  |j        j         d d d            n# 1 swxY w Y   |                     t"                    5  d	|j        _        d d d            n# 1 swxY w Y   |                     t"                    5  |j                                         d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )Nc                   8    e Zd ZdZd Zd Z G d d          ZdS )1TestSealable.test_seal_with_autospec.<locals>.Foor   c                     dS r%   r   r	   s    r   bar1z6TestSealable.test_seal_with_autospec.<locals>.Foo.bar1       qr   c                     dS )Nr)   r   r	   s    r   bar2z6TestSealable.test_seal_with_autospec.<locals>.Foo.bar2   ri   r   c                       e Zd ZdZd ZdS )5TestSealable.test_seal_with_autospec.<locals>.Foo.Bazr1   c                     dS r=   r   r	   s    r   banz9TestSealable.test_seal_with_autospec.<locals>.Foo.Baz.ban   s    1r   N)r   r   r   bazro   r   r   r   Bazrm      s(            r   rq   N)r   r   r   foorh   rk   rq   r   r   r   Foorf      s_        C             r   rs   )TF)spec_setrC   bnew_anew_br&   rk   )subTestr   create_autospecrh   r2   rq   ro   r    r   rr   NonCallableMagicMockrD   rk   rp   r*   r!   	TypeErrorr"   barmissing_attrmissing_method)r
   rs   rt   rr   s       r   test_seal_with_autospecz$TestSealable.test_seal_with_autospec   s   
	 
	 
	 
	 
	 
	 
	 
	 & -	- -	-Hx00 ,- ,-*3BBB(+%+.(	#%%cgt/HIII%%ch???%%ch???%%cgt~>>>%%cgk43LMMM%%cgk4>BBB  S111(/%  W555  444+2(  888&&y11  GGIII              &&~66    CG                             &&~66  HHJJJ               )/%  V444&&~66 % %$$% % % % % % % % % % % % % % %&&~66 ) )'(C$) ) ) ) ) ) ) ) ) ) ) ) ) ) )&&~66 ) )&&((() ) ) ) ) ) ) ) ) ) ) ) ) ) )&&y11 " "GKKMMM" " " " " " " " " " " " " " "&&~66 ) )G(() ) ) ) ) ) ) ) ) ) ) ) ) ) )&&~66 - -+,CG(- - - - - - - - - - - - - - -&&~66 - -G**,,,- - - - - - - - - - - - - - -W,- ,- ,- ,- ,- ,- ,- ,- ,- ,- ,- ,- ,- ,- ,--	- -	-s{  HS/:IS/IS/"I#S/ JS/JS/JS/9KS/KS/!K"AS/3M;S/MS/MS/,N 4S/ NS/NS/%O:S/O

S/O
S/+PS/PS/PS/6QS/QS/QS/4RS/RS/RS/2SS/SS/S S//S3	6S3	N)r   r   r   r   r#   r'   r+   r.   r3   r6   r8   r;   rA   rE   rK   rP   rR   rU   r]   ra   rc   r   r   r   r   r   r      s7       ; ; ;    * * *  & & &* * *  ! ! !
 
 
% % %	  	  	   	 	 	. . .9 9 9S S SM M M;- ;- ;- ;- ;-r   r   __main__)unittestr   r   TestCaser   r   mainr   r   r   <module>r      s          # # # # # # # #]- ]- ]- ]- ]-8$ ]- ]- ]-@ zHMOOOOO r   