Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/unittest/test/testmock/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/unittest/test/testmock/__pycache__/testmock.cpython-38.pyc
U

@��gx�@s�ddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZGdd�de�ZGdd�de�Zd	d
�ZGdd�dej�Zed
kr�e��dS)�N)�is_instance��mock)�call�DEFAULT�patch�sentinel�	MagicMock�Mock�NonCallableMock�NonCallableMagicMock�	AsyncMock�_Call�	_CallList�create_autospecc@s(eZdZdd�Zdd�Zdd�ZeZdS)�ItercCstddddg�|_dS)N�this�is�an�iter)r�thing��self�r�>/opt/cppython/lib/python3.8/unittest/test/testmock/testmock.py�__init__sz
Iter.__init__cCs|S�Nrrrrr�__iter__sz
Iter.__iter__cCs
t|j�Sr)�nextrrrrrrsz	Iter.nextN)�__name__�
__module__�__qualname__rrr�__next__rrrrrsrc@s2eZdZddd�Zed	dd��Zed
dd��ZdS)�	SomethingNcCsdSrr�r�a�b�c�drrr�meth�zSomething.methcCsdSrr)�clsr%r&r'r(rrr�cmeth!szSomething.cmethcCsdSrr�r%r&r'r(rrr�smeth$szSomething.smeth)N)N)N)rr r!r)�classmethodr,�staticmethodr.rrrrr#s

r#cCsdSrr�r%rrr�	something(r*r2c@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[d\�Z0d]d^�Z1d_d`�Z2dadb�Z3dcdd�Z4dedf�Z5dgdh�Z6didj�Z7dkdl�Z8dmdn�Z9dodp�Z:dqdr�Z;dsdt�Z<dudv�Z=dwdx�Z>dydz�Z?d{d|�Z@d}d~�ZAdd��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Zad�d��Zbd�d„Zcd�dĄZdd�dƄZed�dȄZfd�dʄZgd�d̄Zhd�d΄Zid�dЄZjd�d҄Zkd�dԄZld�dքZmd�d؄Znd�dڄZod�d܄Zpd�dބZqd�d�Zrd�d�Zsd�d�Ztd�d�Zud�d�Zvd�d�Zwd�d�Zxd�d�Zyd�d�Zzd�d�Z{d�d�Z|d�d��Z}d�d��Z~d�d��Zd�d��Z�d�d��Z�d��d�Z��dS(�MockTestcCstd�dS)Nzfrom unittest.mock import *)�execrrrr�test_all-szMockTest.test_allcCs�t�}|�|jd�|�|jdd�|�t|jt�d�|�|jdd�|�|j	gd�|�|j
gd�|�d|jd	�|�
|jd
�|�
|jd�|�|jid�dS)
Nz called not initialised correctlyrz$call_count not initialised correctlyz&return_value not initialised correctlyz#call_args not initialised correctly�(call_args_list not initialised correctlyz&method_calls not initialised correctlyZ_itemsz/default mock should not have '_items' attributez parent not initialised correctlyz!methods not initialised correctlyz$children not initialised incorrectly)r
�assertFalse�called�assertEqual�
call_count�
assertTruer�return_value�	call_args�call_args_list�method_calls�assertNotIn�__dict__�assertIsNone�_mock_parent�
_mock_methods�_mock_children�rrrrr�test_constructor4s:
��
�
�
�
���
�zMockTest.test_constructorcCstdd�}|�|jd�dS)N�r<z(return value in constructor not honoured)r
rBr<rFrrr� test_return_value_in_constructorPs
�z)MockTest.test_return_value_in_constructorcCs*dd�}t|�}d|j_|�|�d�dS)NcSsdSrrrrrr�fWr*z9MockTest.test_change_return_value_via_delegate.<locals>.f�)rrr<r9�rrJrrrr�%test_change_return_value_via_delegateVsz.MockTest.test_change_return_value_via_delegatec	Cs:dd�}t|�}t�|j_|�t��|�W5QRXdS)NcSsdSrrrrrrrJ^r*z8MockTest.test_change_side_effect_via_delegate.<locals>.f)r�	TypeErrorr�side_effect�assertRaisesrLrrr�$test_change_side_effect_via_delegate]s

z-MockTest.test_change_side_effect_via_delegatecCs�tdd�}|�dt|��|�dt|�t|��t�dftdd�dfg}|D]�\}}|�d|t|j��|�d|t|����|�d|t|��j��|�d	|t|���|�d
|t|����|�d|t|��jj��j��qNdS)N�foo��namez'%s'r�barz%s.barz%s.foo()z
%s.foo().bingz%s()z%s()()z%s()().foo.bar.baz().bing)r
�assertIn�repr�idrUrRZbing�baz)rr�mocksrTrrr�	test_repres

�zMockTest.test_reprcCs�Gdd�dt�}t|d�}|�dt|��t|�d�}|�dt|��t|d�}|�dt|��t|�d�}|�dt|��t|dd�}|�dt|��|�d	t|��tdd
�}|�dt|��t�}|�dt|��tdgd�}|�dt|��dS)Nc@seZdZdS)z'MockTest.test_repr_with_spec.<locals>.XN�rr r!rrrr�Xvsr]��specz
 spec='X' ��spec_setz spec_set='X' rR)r_rTz name='foo' rSr_)�objectr
rVrWr@�rr]rrrr�test_repr_with_specus$


zMockTest.test_repr_with_speccs�t�}dd�}||_|jt|dddd�|jdddd�dddg��fdd�}||_|�|�|�|�gdddgd�ttjd	�}|�|jtjd
�dd�}t|tjd
�}|�|�tj�dS)Nc_std��dS)NZkablooie)�SystemError)�args�kwargsrrr�effect�sz)MockTest.test_side_effect.<locals>.effectrK����fishcs���Sr��popr��resultsrrrh�szside effect not used correctly�rOz#side effect in constructor not usedcSstSr�rrrrrrO�sz.MockTest.test_side_effect.<locals>.side_effect)rOr<)	r
rOrPre�assert_called_withr9r�
SideEffect�RETURN)rrrhrOrror�test_side_effect�s$
��zMockTest.test_side_effectcs�dddg��fdd�}dd�}t|�}dddg|_|�|�|�|�gdddgd�dddg�t|�}||_|�|�|�|�gdddgd	�dS)
NrKrirjcs���Srrmrrorrrh�sz2MockTest.test_autospec_side_effect.<locals>.effectcSsdSrrrrrrrJ�r*z-MockTest.test_autospec_side_effect.<locals>.fz1side effect not used correctly in create_autospecz'callable side effect not used correctly)rrOr9)rrhrJrrror�test_autospec_side_effect�s
�
�z"MockTest.test_autospec_side_effectcCs,dd�}t|�}td�|_|�td|�dS)NcSsdSrrrrrrrJ�r*z7MockTest.test_autospec_side_effect_exception.<locals>.fzBazinga!)r�
ValueErrorrO�assertRaisesRegexrLrrr�#test_autospec_side_effect_exception�s
z,MockTest.test_autospec_side_effect_exceptioncCsRt�}dg}td||d�}|tjtjd�|j}|��tj|_|j}|�|��|�	|j
dd�|�	|j|d�|�	|j|d�|�
|jd�|�	|jd	d
�|�	|jdd�|�	|jgd�|�	|jgd
|jgf�|�	|jg�|�	|jtjd�|�	|j|d�|�
|jd�|�	|jd|id�|�	|j|d�|�
|jjd�dS)Nr2�child)rT�parentr_�r2zname incorrectly resetzparent incorrectly resetzmethods incorrectly resetzcalled not resetrzcall_count not resetzcall_args not resetzcall_args_list not resetz0method_calls not initialised correctly: %r != %rzside_effect incorrectly resetzreturn_value incorrectly resetzreturn value mock not resetzchildren reset incorrectlyzchildren incorrectly clearedzchild not reset)r
rr#Z
SomethingElser2rtrOr<�
reset_mockr9�
_mock_namerCrDr7r8r:r=r>r?�
mock_callsrE)rr|r_rr2r<rrr�test_reset_mock�sV
�
�
�
���
��
�zMockTest.test_reset_mockcCst�}||_|��dSr)r
r<r~rFrrr�test_reset_mock_recursion�sz"MockTest.test_reset_mock_recursioncCst��}|��dSr)r�	mock_openr~�rr%rrr�(test_reset_mock_on_mock_open_issue_18622�sz1MockTest.test_reset_mock_on_mock_open_issue_18622cCs>t�}|�t|jt�d�|�}|�|�|d�|��|tj�}|�|jd�|�|j	dd�|�|j
tjfifd�|�|j
jtjfd�|�|j
jid�|�|j
tjfifgd�tj|_|tjtjd�}|�|tjd	�|�|j	d
d�|�|j
tjfdtjifd�|�|j
tjfiftjfdtjifgd
�dS)Nz%Default return_value should be a Mockz'different result from consecutive callszcalled not setrKzcall_count incoreectzcall_args not setr6)�keyzincorrect return valuerizcall_count incorrectr�zcall_args_list not set)r
r;rr<r9r~r�Argr8r:r=rfrgr>ZReturnValueZKeyArg)rr�resultZret_valrrr�	test_call�sP�
�
����
��
��zMockTest.test_callc	Cs�t�}|�|tj�|tjd�|tjtjd�|�|jdtjffdtjiftjfdtjifg�|�|jtjfdtjif�|�|jjtjf�|�|jjdtji�|�	|jdk�dS)N)�kwrr�za long sequence)
r
rr�ZKwargr9r>r=rfrgr7rFrrr�test_call_args_comparison#s"

��z"MockTest.test_call_args_comparisoncCs�t��}|�||k�|�||k�|�|t��k�|�|t��k�|�|tjk�|�|tjk�|�tj|k�|�tj|k�t�t���}t�tj�}|�||k�|�||k�|�||k�|�||k�dSr)rr	r;r7�ANYr)rZmmZcall1Zcall2rrr�test_calls_equal_with_any9sz"MockTest.test_calls_equal_with_anycCsdt�}|�|��|�t|jd�|��|�t|j�|dddddd�|jdddddd�dS)NrKrirjrlZnothing�r%r&)r
rsrP�AssertionErrorr~rFrrr�test_assert_called_withNsz MockTest.test_assert_called_withcCs t�}|t��|�tj�dSr)r	rsrr��r�mrrr�test_assert_called_with_any]s
z$MockTest.test_assert_called_with_anyc	Cs�ddd�}t|d�}|dddd�|�ddd�|jdddd�|jt|jdddd�|�t��}|jd	d
�W5QRX|�|jjt�dS)NcSsdSrrr-rrrrJdr*z9MockTest.test_assert_called_with_function_spec.<locals>.fr^rKrirj�r&r'�r%r&r'���e)N)r
rsrPr��assertIsInstance�	exception�	__cause__rN�rrJr�cmrrr�%test_assert_called_with_function_speccs


�z.MockTest.test_assert_called_with_function_speccsz�fdd�}tt�jd�}||�ttjd�}||�tt�jd�}||�ttjd�}||�tt�jd�}||�dS)NcsF|dddd�|�ddd�|jdddd��jt|jdddd�dS)NrKrirjr�r�)rsrPr�rrrr�_checkts
�z<MockTest.test_assert_called_with_method_spec.<locals>._checkr^)r
r#r)r,r.)rr�rrrr�#test_assert_called_with_method_specssz,MockTest.test_assert_called_with_method_specc	Cs\d}|�t|�d���t���W5QRX|�t|�d���tdd���W5QRXdS)Nz"Expected '{0}' to have been calledrZ	test_namerS)ryr��formatr
�
assert_called)r�msgrrr�$test_assert_called_exception_message�s
z-MockTest.test_assert_called_exception_messagecs�t���������|�t�j����|�t�j��dddd��jdddd�����dddd�|�t�fdd��dS)NrRrUri�rYcs�jdddd�S)N�bobrUrir���assert_called_once_withrrrr�<lambda>�r*z7MockTest.test_assert_called_once_with.<locals>.<lambda>)r
r�rPr�r~rrrr�test_assert_called_once_with�s
�z%MockTest.test_assert_called_once_withcs6t���d��d�|�tt�d��fdd��dS)NrKrizCalls: [call(1), call(2)]cs
��d�S)Nrir�r�r�rrr��r*zAMockTest.test_assert_called_once_with_call_list.<locals>.<lambda>)r
ryr��re�escaperrr�r�&test_assert_called_once_with_call_list�s
�z/MockTest.test_assert_called_once_with_call_listc	Cs�ddd�}t|d�}|dddd�|�ddd�|jdddd�|jt|jdddd�|�t��}|jd	d
�W5QRX|�|jjt�|ddd
�|�t|jddd�|�t|jddd
�dS)NcSsdSrrr-rrrrJ�r*z>MockTest.test_assert_called_once_with_function_spec.<locals>.fr^rKrirjr�r�r�r����)N)r
r�rPr�r�r�r�rNr�rrr�*test_assert_called_once_with_function_spec�s0


�
�
�z3MockTest.test_assert_called_once_with_function_speccCsbt�}|j}|�t|t�d�|�|j|d�t�}d|j_|�|��dd�|�|jjd�dS)Nzattribute isn't a mockz+different attributes returned for same namerjzmethod returned wrong valuez!method didn't record being called)r
r2r;rr9r<r8�rrr2rrr�#test_attribute_access_returns_mocks�s
�
�z,MockTest.test_attribute_access_returns_mockscCs0t�}|j}|�|jdd�|�|j|d�dS)Nr2z attribute name not set correctlyz"attribute parent not set correctly)r
r2r9rrCr�rrr�(test_attributes_have_name_and_parent_set�s
�
�z1MockTest.test_attributes_have_name_and_parent_setcCstt�}|jddd�|jjdtjd�|�|jjdddtjifgd�|�|jdd	d
difdddtjifgd�dS)Nrjrkr�)�caker2)r�r�z#method calls not recorded correctly)rjrlzsomething_else.something)r
r2�something_elserZCaker9r?rFrrr�test_method_calls_recorded�s
���z#MockTest.test_method_calls_recordedcCs�t�}|��|�|jdg�|�|jddifg�t�}|�d�|�|jdg�|�|jddifg�t�}|jdd�|�|jdd	difg�|�|jddd	difg�t�}|jdd
d�|�|jdddd
ifg�dS)
Nr}r2r�	different)r2�r�r�rK��xr�Zmore)�somer�)r
r2r9r?rFrrr� test_method_calls_compare_easily�s&

��z)MockTest.test_method_calls_compare_easilyc	CsDdgdfD]4}dD]*}tf||i�}|j|�tdt|d�qq
dS)Nr2r})r_raz-Mock object has no attribute 'something_else'r�)r
r2ry�AttributeError�getattr)rr_�argrrrr�test_only_allowed_methods_exists�z(MockTest.test_only_allowed_methods_existcs>Gdd�dt�}�fdd�}|t|d��|t|�d��dS)Nc@seZdZdZdZdd�ZdS)z*MockTest.test_from_spec.<locals>.SomethingrjNcSsdSrrrrrr�yr*z,MockTest.test_from_spec.<locals>.Something.y)rr r!r��
__something__r�rrrrr#sr#cs:|j|j|j��tdt|d���tdt|d�dS)Nz Mock object has no attribute 'z'�zz)Mock object has no attribute '__foobar__'Z
__foobar__)r�r�r�ryr�r�rrrr�test_attributess"��z0MockTest.test_from_spec.<locals>.test_attributesr^)rbr
)rr#r�rrr�test_from_specszMockTest.test_from_speccCsJt�}t|d�}|�|�|��|��|dddd�|jdddd�dS)N��wrapsrKrirjrk)r
r9r~rs�r�realrrrr�test_wraps_calls.s
zMockTest.test_wraps_callscs8Gdd�dt�}|�}t|d��|�t�fdd��dS)Nc@seZdZdS)zFMockTest.test_wraps_prevents_automatic_creation_of_mocks.<locals>.RealNr\rrrr�Real;sr�r�cs���Sr)Znew_attrrrrrr�Ar*zJMockTest.test_wraps_prevents_automatic_creation_of_mocks.<locals>.<lambda>)rbr
rPr�)rr�r�rrr�/test_wraps_prevents_automatic_creation_of_mocks:s
z8MockTest.test_wraps_prevents_automatic_creation_of_mockscCs4t�}t|d�}d|_|�|�d�|�|j�dS)Nr�rj)r
r<r9r7r8r�rrr�,test_wraps_call_with_nondefault_return_valueDs

z5MockTest.test_wraps_call_with_nondefault_return_valuecs�Gdd�dt�}|�}t|d��|����|���|�t�fdd��|��j|j��jjdddd	�}|jjjdddd	�|�||j���dS)
Nc@seZdZe�ZdS)z,MockTest.test_wraps_attributes.<locals>.RealN)rr r!r
�	attributerrrrr�Osr�r�cs�jSrrkrrrrr�Vr*z0MockTest.test_wraps_attributes.<locals>.<lambda>rKrirjrk)	rbr
r9r�rPr��assertNotEqualZfrogrs)rr�r�r�rrr�test_wraps_attributesNs
zMockTest.test_wraps_attributescCsdGdd�dt�}|�}t|d�}tjtg|j_|�|��tj�|�|��tj�|�	t
|j�dS)Nc@seZdZdd�ZdS)z[MockTest.test_customize_wrapped_object_with_side_effect_iterable_with_default.<locals>.RealcSstjSr)r�ORIGINAL_VALUErrrr�method`szbMockTest.test_customize_wrapped_object_with_side_effect_iterable_with_default.<locals>.Real.methodN�rr r!r�rrrrr�_sr�r�)rbr
r�VALUE1rr�rOr9r�rP�
StopIteration�rr�r�rrrr�Dtest_customize_wrapped_object_with_side_effect_iterable_with_default^s
zMMockTest.test_customize_wrapped_object_with_side_effect_iterable_with_defaultcCsfGdd�dt�}|�}t|d�}tjtjg|j_|�|��tj�|�|��tj�|�t	|j�dS)Nc@seZdZdd�ZdS)zNMockTest.test_customize_wrapped_object_with_side_effect_iterable.<locals>.RealcSsdSrrrrrrr�nr*zUMockTest.test_customize_wrapped_object_with_side_effect_iterable.<locals>.Real.methodNr�rrrrr�msr�r�)
rbr
rr��VALUE2r�rOr9rPr�r�rrr�7test_customize_wrapped_object_with_side_effect_iterablels
z@MockTest.test_customize_wrapped_object_with_side_effect_iterablecCs:Gdd�dt�}|�}t|d�}t|j_|�t|j�dS)Nc@seZdZdd�ZdS)zOMockTest.test_customize_wrapped_object_with_side_effect_exception.<locals>.RealcSsdSrrrrrrr�{r*zVMockTest.test_customize_wrapped_object_with_side_effect_exception.<locals>.Real.methodNr�rrrrr�zsr�r�)rbr
�RuntimeErrorr�rOrPr�rrr�8test_customize_wrapped_object_with_side_effect_exceptionys

zAMockTest.test_customize_wrapped_object_with_side_effect_exceptioncCsFGdd�dt�}dd�}|�}t|d�}||j_|�|��tj�dS)Nc@seZdZdd�ZdS)zNMockTest.test_customize_wrapped_object_with_side_effect_function.<locals>.RealcSsdSrrrrrrr��r*zUMockTest.test_customize_wrapped_object_with_side_effect_function.<locals>.Real.methodNr�rrrrr��sr�cSstjSr)r�VALUErrrrrO�szUMockTest.test_customize_wrapped_object_with_side_effect_function.<locals>.side_effectr�)rbr
r�rOr9rr�)rr�rOr�rrrr�7test_customize_wrapped_object_with_side_effect_function�s
z@MockTest.test_customize_wrapped_object_with_side_effect_functioncCs@Gdd�dt�}|�}t|d�}tj|j_|�|��tj�dS)Nc@seZdZdd�ZdS)zFMockTest.test_customize_wrapped_object_with_return_value.<locals>.RealcSsdSrrrrrrr��r*zMMockTest.test_customize_wrapped_object_with_return_value.<locals>.Real.methodNr�rrrrr��sr�r�)rbr
rr�r�r<r9r�rrr�/test_customize_wrapped_object_with_return_value�s


z8MockTest.test_customize_wrapped_object_with_return_valuecCspGdd�dt�}|�}t|d�}tjtjg|j_tj|j_|�	|��tj�|�	|��tj�|�
t|j�dS)Nc@seZdZdd�ZdS)zVMockTest.test_customize_wrapped_object_with_return_value_and_side_effect.<locals>.RealcSsdSrrrrrrr��r*z]MockTest.test_customize_wrapped_object_with_return_value_and_side_effect.<locals>.Real.methodNr�rrrrr��sr�r�)rbr
rr�r�r�rOZWRONG_VALUEr<r9rPr�r�rrr�?test_customize_wrapped_object_with_return_value_and_side_effect�s

zHMockTest.test_customize_wrapped_object_with_return_value_and_side_effectcCsLGdd�dt�}|�}t|d�}dd�|j_tj|j_|�|��tj�dS)Nc@seZdZdd�ZdS)zWMockTest.test_customize_wrapped_object_with_return_value_and_side_effect2.<locals>.RealcSsdSrrrrrrr��r*z^MockTest.test_customize_wrapped_object_with_return_value_and_side_effect2.<locals>.Real.methodNr�rrrrr��sr�r�cSstSrrrrrrrr��r*z[MockTest.test_customize_wrapped_object_with_return_value_and_side_effect2.<locals>.<lambda>)rbr
r�rOrr�r<r9r�rrr�@test_customize_wrapped_object_with_return_value_and_side_effect2�s

zIMockTest.test_customize_wrapped_object_with_return_value_and_side_effect2cCsnGdd�dt�}|�}t|d�}tjtg|j_tj|j_|�	|��tj�|�	|��tj�|�
t|j�dS)Nc@seZdZdd�ZdS)z^MockTest.test_customize_wrapped_object_with_return_value_and_side_effect_default.<locals>.RealcSsdSrrrrrrr��r*zeMockTest.test_customize_wrapped_object_with_return_value_and_side_effect_default.<locals>.Real.methodNr�rrrrr��sr�r�)rbr
rr�rr�rOrur<r9rPr�r�rrr�Gtest_customize_wrapped_object_with_return_value_and_side_effect_default�s

zPMockTest.test_customize_wrapped_object_with_return_value_and_side_effect_defaultcCs4ttd�}|�t|�ttd�d�}|�t|�dS�NrqrR)r
r�rPrFrrr�test_exceptional_side_effect�s
z%MockTest.test_exceptional_side_effectcCs4ttd�}|�t|�ttd�d�}|�t|�dSr�)r
�KeyboardInterruptrPrFrrr� test_baseexceptional_side_effect�s
z)MockTest.test_baseexceptional_side_effectcCst�}|�td|j�dS)Nz
not called)r
ryr�rsrFrrr�test_assert_called_with_message�s�z(MockTest.test_assert_called_with_messagecCstdd�}|�td|j�dS)NZgeoffreyrSz'Expected 'geoffrey' to be called once\.)r
ryr�r�rFrrr�$test_assert_called_once_with_message�s

�z-MockTest.test_assert_called_once_with_messagecs2t��|�t�fdd��d�_|��jd�dS)Ncs�jSr)rrrrrr��r*z'MockTest.test__name__.<locals>.<lambda>rR)r
rPr�rr9rrrr�test__name__�szMockTest.test__name__cCsJGdd�dt�}t|dg�d�}|�d�|j�d�|�tt|d�dS)Nc@seZdZdS)z-MockTest.test_spec_list_subclass.<locals>.SubNr\rrrr�Sub�sr�rRr^rj)�listr
�appendrsrPr�r�)rr�rrrr�test_spec_list_subclass�s

z MockTest.test_spec_list_subclasscCs�Gdd�dt�}t|d�}|�||�t|�d�}|�||�|�|j|�|�t�jjd�t|d�}|�||�t|�d�}|�||�dS)Nc@seZdZdS)z#MockTest.test_spec_class.<locals>.XNr\rrrrr]�sr]r^r
r`)rbr
r��assertIs�	__class__r9rrcrrr�test_spec_class�s

zMockTest.test_spec_classcCs�Gdd�d�}t|d�}|�||�t|�d�}|�||�|�|j|�|�t�jjd�t|d�}|�||�t|�d�}|�||�dS)Nc@seZdZdS)z2MockTest.test_spec_class_no_object_base.<locals>.XNr\rrrrr]
sr]r^r
r`)r
r�r�r�r9rrcrrr�test_spec_class_no_object_base	s

z'MockTest.test_spec_class_no_object_basecsLGdd�dt�}t|d��d�_t|d���fdd�}d�_|�t|�dS)Nc@seZdZdZdS)z8MockTest.test_setting_attribute_with_spec_set.<locals>.XrjN)rr r!r�rrrrr]sr]r^rRr`cs
d�_dS�NrRr�rrrr�set_attr%sz?MockTest.test_setting_attribute_with_spec_set.<locals>.set_attr)rbr
r�r�rPr�)rr]r�rrr�$test_setting_attribute_with_spec_sets

z-MockTest.test_setting_attribute_with_spec_setcCs4t��}|�tj|�t�td��t�t��dS)Nge��A)�sys�getrecursionlimit�
addCleanup�setrecursionlimit�int�copyr
)r�currentrrr�	test_copy,szMockTest.test_copycs\Gdd�dt�}||d��|��jd��fdd�}|�t|��fdd�}|�t|�dS)Nc@s&eZdZdd�Zdd�Zeee�ZdS)z8MockTest.test_subclass_with_properties.<locals>.SubClasscSsdS�Nrjrrrrr�_get8sz=MockTest.test_subclass_with_properties.<locals>.SubClass._getcSstd��dS)Nz
strange error)�	NameError)r�valuerrr�_set:sz=MockTest.test_subclass_with_properties.<locals>.SubClass._setN)rr r!r�r�property�some_attributerrrr�SubClass7srr`rjcs
d�_dSr�)rr��srr�testAsz4MockTest.test_subclass_with_properties.<locals>.testcs
d�_dS)NrU�rRrrrrrEs)r
r9rrPrr�)rrrrrr�test_subclass_with_properties6s
z&MockTest.test_subclass_with_propertiescCs>t�}dd�}|t|�_|d�|�d�|�t|dd�dS)NcSs|�|�|�|�Sr)Z_increment_mock_callZ
_mock_callr�rrr�__call__Ls
z,MockTest.test_setting_call.<locals>.__call__�one�two)r
�typerrsrPrN)rrrrrr�test_setting_callJs

zMockTest.test_setting_callcCs�t�}tt|��}tdd�tt�D��}|�t�||�|j|jf|�dt|��|�dt|��d|_|_|�dt|��|�dt|��dd�|_	|�d	t|��dS)
NcSsg|]}|�d�s|�qS)�_)�
startswith)�.0r�rrr�
<listcomp>Zs
z%MockTest.test_dir.<locals>.<listcomp>r%r&r'r(cSstg�Sr)rrrrrr�jr*z#MockTest.test_dir.<locals>.<lambda>r)
r
�set�dirr9r%r&rVr'r(r)rr�attrs�
type_attrsrrr�test_dirWs
zMockTest.test_dircCsXttjd�}tttj��}tt|��}|�t�||�d|_|�t|��d�d�dS)Nr^rj�versionrK)r
�unittest�TestCaserrr9r�count)rrZtestcase_attrsrrrr�test_dir_from_specnszMockTest.test_dir_from_speccCsVt�tdd�}|��z0ttt���}ttt��}|�t�||�W5|��XdS)NZ
FILTER_DIRF)	rrbr�start�stoprrr
r9)rZpatcherrrrrr�test_filter_dir{szMockTest.test_filter_dircCs6t�}d|j_|�dt|��|`|�dt|��dS)NrKr{)r
r{r<rVrr@rFrrr�,test_dir_does_not_include_deleted_attributes�s
z5MockTest.test_dir_does_not_include_deleted_attributescCs�tdd�}|�|jd�tdd�}|�|jd�tdt�d�}tf|�}|�t|�|�|j��d�|�|jt�t�}|jf|�|�t|�|�|j��d�|�|jt�dS)NrUr	�!)rOzfoo.bar.return_valuerR)	r
r9rRr	�KeyErrorrPrUr�Zconfigure_mock)rrrgrrr�test_configure_mock�s 

�
zMockTest.test_configure_mockc	Os:|�|��}|||�W5QRXt|j�}|�||�dSr)rP�strr�r9)rr��message�funcrfrg�contextr�rrr�assertRaisesWithMsg�s
zMockTest.assertRaisesWithMsgc
Cst�}d}d}d}|jt|||f|jddddd�|jddddd	�|jj|jjg}|D]0}d
}d}d}|jt|||f|ddddd�qZ|D]*}d
}d}d}|jt|||f|dd�q�|D],}d
}d
}d}|�t|||f|ddd�q�|D]&}d
}d}d}|�t|||f|�q�dS)Nznot called.zmock(1, '2', 3, bar='foo')z0expected call not found.
Expected: %s
Actual: %srK�2rjrR)rUr	zfoo(1, '2', 3, foo='foo')zfoo(1, '2', 3, bar='foo')zfoo(bar='foo')zfoo(1, 2, 3)rizfoo())rr)r�rsrRr�)rr�actual�expectedr&Z	assertersr)rrr�'test_assert_called_with_failure_message�sz
��
�
�
�
�z0MockTest.test_assert_called_with_failure_messagec	Cs�t�}|�|jgkd�t�}|�ddifg}|�|j|�|��|�t���|�|j|�|�|jjddifg�t�}|�jdddddd	�ddifd
dtddd	�fg}|�|j|�|�|jjjddtddd	�fg�|�|jjddtddd	�fg�t�}|�j�	��
�ddifd
difddifg}|�|j|�|�|�jtj�	��
����t�tdd�fD�]$}tf|�}t|j�ddifg}|�|j|�tf|�}|�
��ddifddifg}|�|j|�|�|�
�jt�g�tf|�}|d�d�d�|�|jtd�d�d����|�|�jtd�d����|�|��jtd����tf|�}|d�d�d�j
j�d�|�|jtd�d�d�j
j�d����|�|�jtd�d�j
j�d����|�|��jtd�j
j�d����tf|�}t|�j�	��
��ddif}|�|jd|�|�|�jtj�	��
������|�|�j�	�jt�
������|�|�j�	�j
jt�������qpdS)NT�rrKrirjr�r�r�z().foo�rKrirjrRz
().foo.barz().foo.bar().bazrUrSzfoo.__int__r%za()z().foo.bar().baz().__int__���)r	r�r�r9rRr�r�dictr<rUrY�	call_listr�r%r&r'�__int__)rrr,rgZ	last_callrrr�test_mock_calls�s���
��
�





�
��


���zMockTest.test_mock_callscCsFt�}|�}|��|�|jt�t���g�|�|jt��g�dSr)r
Zwibbler9r�r)rr�r�rrr�test_child_mock_call_equal4s
z#MockTest.test_child_mock_call_equalcCsFt�}|����|�|jdt�����|�|jdt���dS�NrKr)r
rRr2r�r�rr�r9r�rrr�test_mock_call_not_equal_leaf>sz&MockTest.test_mock_call_not_equal_leafcCsFt�}|����|�|jdt�����|�|jdt���dSr6�r
rRrUr�r�rrYr�rrr�!test_mock_call_not_equal_non_leafEsz*MockTest.test_mock_call_not_equal_non_leafcCs8t�}|jdd���|�|jdtjdd����dS)NrKr�ri)r
rRrUr9r�rr�rrr�2test_mock_call_not_equal_non_leaf_params_differentLsz;MockTest.test_mock_call_not_equal_non_leaf_params_differentcCs,t�}|j��|�|jdtj���dS�Nrr8r�rrr�&test_mock_call_not_equal_non_leaf_attrSs
z/MockTest.test_mock_call_not_equal_non_leaf_attrcCs.t�}|j��|�|jdt�����dSr;)r
rRrUr�r�rr�rrr�2test_mock_call_not_equal_non_leaf_call_versus_attrYs
z;MockTest.test_mock_call_not_equal_non_leaf_call_versus_attrcCs^t�}|����j��|�t|jd�d�|�t|jd�d�|�t|jd�d�dS)Nrz
call.foo()rKzcall.foo().bar()rizcall.foo().bar().baz.bob())r
rRrUrYr�r9rWr�r�rrr�test_mock_call_repr_s
zMockTest.test_mock_call_reprcCs0t�}||_t|���|�t|���d�dS)Nz<Mock name='mock\(\)' id='\d+'>)r
rRrWZassertRegexr�rrr�test_mock_call_repr_loopgsz!MockTest.test_mock_call_repr_loopcCst�}|�t�g|jk�dSr)r
r7rr�r�rrr�test_mock_calls_containsnsz!MockTest.test_mock_calls_containscCshGdd�dt�}|�}|�|j|�|�|�|�Gdd�dt�}|�}|�|j|�|�|�|�dS)Nc@seZdZdS)�+MockTest.test_subclassing.<locals>.SubclassNr\rrrr�SubclasstsrBc@seZdZdd�ZdS)rAc[s
tf|�Sr)r
)rrgrrr�_get_child_mock|sz;MockTest.test_subclassing.<locals>.Subclass._get_child_mockN)rr r!rCrrrrrB{s)r
r�rR�assertNotIsInstance)rrBrrrr�test_subclassingsszMockTest.test_subclassingcs�t�t�t�t�g}�fdd�}|D]z}||�t|�rb|�|dd�|dd�|��||�|��|jjddd�|�d����d�|��||�q$dS)Ncs@d}|D]2}t||�}��|t���|t���|g�qdS)N)r>r?r�)r�r�rr�r9)r�namesrT�attrrrr�assert_attrs�s
z-MockTest.test_arg_lists.<locals>.assert_attrsrKrirjr1)	r
r	rr�callabler~rRrUrY)rrZrHrrrr�test_arg_lists�s&�

zMockTest.test_arg_listscCs�t�}|ddd�|ddd�|�t|j�d�|�|jjd�|�|jjtdd��dtdd�fdtdd�fg}t||j�D]@\}}|�t|�d�|�|d	|d	�|�|d|d�q~dS)
NrKrjr1rir��r&)ri�rKr)	r
r9�lenr=rfrgr1�zipr>)rrZ
expected_listr,r=rrr�test_call_args_two_tuple�sz!MockTest.test_call_args_two_tuplecCsttdddg�d�}|�|�|�|�gdddg�|�t|�tdddgd�}|�|�|�|�gdddg�|�t|�tdd�}|�|�|�|�gd	d
dg�|�t|�Gdd
�d
t�}t|d�}|�|�|�tt�d�}|�|�|�|�|�gddddg�|�t|�dS)NrKrirjrqr%r&r'Zghi�g�h�ic@seZdZdS)z/MockTest.test_side_effect_iterator.<locals>.FooNr\rrrr�Foo�srSrrrr)	r
rr9rPr�r	rbr�r)rrrSrrr�test_side_effect_iterator�s"


�z"MockTest.test_side_effect_iteratorcCs\ttfD]N}tdtdf}||d�}|�t|�|�|�d�|�t|�|�|�d�qdS)Nrjr�rq)r
r	rxr#rPr9)r�Klass�iterabler�rrr�$test_side_effect_iterator_exceptions�s
z-MockTest.test_side_effect_iterator_exceptionscCs�t�}tdddg�|_|�|�|�|�gdddg�|�t|�|j}|�|ttg���dddg|_|�|�|�|�gdddg�|�t|�|j}|�|ttg���t�}||_|�|�|�|�|�gddd	d
g�|�t|�|�	|j|�dS)NrKrirjr%r&r'rrrr)
r
rrOr9rPr�r�rrr�)rrrOZ	this_iterrrr�!test_side_effect_setting_iterator�s$
�z*MockTest.test_side_effect_setting_iteratorcCs4tdd�}tdtg�|_|�|�|�gddg�dS)NrirHrK)r
rrrOr9rFrrr�!test_side_effect_iterator_default�s
z*MockTest.test_side_effect_iterator_defaultcCs�t�}|dd�|dd�|dd�|dd�|dd�tdd�ddifd	d
ddifddddifdd
ifdd
ddifg}|D]}|j|gdd�q|tdd�tdd�t�dddfD]}|jt|j|gdd�q�tdd�tdd�gtdd�tdd�gtdd�tdd�gg}|D]}|j|dd��q
tdd�tdd�tdd�gtdd�tdd�gtdd�tdd�tdd�gtdd�tdd�tdd�tdd�tdd�gg}|D]}|jt|j|dd��q�dS)NrKrirjr1r�r�rKr%�)rjr�r)r.�rKrir.r[T�Z	any_orderr*rRr��)r
r�assert_has_callsrPr�)rr�kalls�kallZ
kall_listsZ	kall_listrrr�test_assert_has_calls_any_order�sT






�"��*��z(MockTest.test_assert_has_calls_any_orderc	
Cs�tdd�ddifdtdd�dd	d
difg}t��t�d�g}|�t��jdd����|�tjt�id��	dg����g}t
�t�fD]F}|dd�|dd�|dd
�|dd�|ddd�|�||f�q�t
�}|��|�d�|��jdd�|jt�id��	dg�|�||f�|D]j\}}t
t|��D]R}dD]F}||||�}|�|�t|�dk�r>|�t|jtt|����q>�q6�q"dS)NrKrir%rjrZr�rKr.rLr&r1r	r�r/)rrRrU�extendZspamrYr2Zbamrrlr
r	r��rangerMr^rPr�r��reversed)	rZkalls1Zkalls2rZrr_rR�stepZtheserrr�test_assert_has_callssD�"






�zMockTest.test_assert_has_callsc	CsFGdd�d�}t|�}||�fD]H}|jddddd�|�tjddddd�g�|�t�dddd�g�q |��||�fD]l}|�t|jt��g�|�d��dd�|�t�d�t�d��dd�g�|j�td�t��dd�g�q||��t�d�t�	d�t���	d�t���dddd�g}|D]}|�t|j|g��q(dS)Nc@s,eZdZdd�Zddd�ZGdd�d�ZdS)	z=MockTest.test_assert_has_calls_nested_spec.<locals>.SomethingcSsdSrrrrrrrJr*zFMockTest.test_assert_has_calls_nested_spec.<locals>.Something.__init__NcSsdSrrr$rrrr)Kr*zBMockTest.test_assert_has_calls_nested_spec.<locals>.Something.methc@seZdZdd�Zdd�ZdS)zAMockTest.test_assert_has_calls_nested_spec.<locals>.Something.FoocSsdSrrr�rrrrOr*zJMockTest.test_assert_has_calls_nested_spec.<locals>.Something.Foo.__init__cSsdSrr)rr%r&rrr�meth1Pr*zGMockTest.test_assert_has_calls_nested_spec.<locals>.Something.Foo.meth1N)rr r!rrgrrrrrSMsrS)N)rr r!rr)rSrrrrr#Hs
r#rKrirj�r(r�)
rr)r^rr~rPr�rSrgZnon_existent)rr#Z
mock_classr�Z
invalid_callsr`rrr�!test_assert_has_calls_nested_specGs.
" ��z*MockTest.test_assert_has_calls_nested_speccCsJt�}|�������|������t��������}|�	|�dSr)
r	rRrUrYrr
�threerr2r^)rr��callsrrr�)test_assert_has_calls_nested_without_specos
z2MockTest.test_assert_has_calls_nested_without_specc	Cs�ddd�}t|d�}|dddd�|dd	d
dd�|d
ddd�ddifddddifdifg}|�|�|j|dd�|�|dd��|j|dd�dd�|�|dd��|j|dd�dd�tt|��}|�t��|�|�W5QRX|j|dd�|�t��|�|dd��W5QRX|j|dd�dd�|�t��|�|dd��W5QRX|j|dd�dd�dS)NcSsdSrrr-rrrrJxr*z<MockTest.test_assert_has_calls_with_function_spec.<locals>.fr^rKrirjr�r�r�r�r]�r'r(�
��)r'r.r/)r�r�r�r()rnrorpTr\r0)N)r
r^r�rdrPr�)rrJrrkrrr�(test_assert_has_calls_with_function_specws2

�
z1MockTest.test_assert_has_calls_with_function_specc	Cs�d	dd�}t|d�}|d�|�td�t�d����}|�t�g�W5QRX|�|j	j
�|�td�t�d����}|�t�tdd�g�W5QRX|�|j	j
t�dS)
NcSsdSrrr�rrrrJ�r*zAMockTest.test_assert_has_calls_not_matching_spec_error.<locals>.fr^rKz^{}$z5Calls not found.
Expected: [call()]
Actual: [call(1)]z�Error processing expected calls.
Errors: [None, TypeError('too many positional arguments')]
Expected: [call(), call(1, 2)]
Actual: [call(1)]ri)N)
r
ryr�r�r�r�r^rrBr�r�r�rNr�rrr�-test_assert_has_calls_not_matching_spec_error�s.

����� z6MockTest.test_assert_has_calls_not_matching_spec_errorcCs�t�}|dd�|dd�|ddd�|�dd�|jdd�|jddd�|�t|j�|�t|jdd�|jt|jdd�dS)NrKrirjr1r�rKr�)r
�assert_any_callrPr�rFrrr�test_assert_any_call�s,

���zMockTest.test_assert_any_callc	Cs�ddd�}t|d�}|dddd�|dd	d
dd�|�ddd�|jdddd
�|�dd	d
d�|jdd	d
dd�|jt|jdddd�|�t��}|jdd�W5QRX|�|jjt�dS)NcSsdSrrr-rrrrJ�r*z;MockTest.test_assert_any_call_with_function_spec.<locals>.fr^rKrirjr�r�r�r�r]rmr�r-r�r�)N)r
rsrPr�r�r�r�rNr�rrr�'test_assert_any_call_with_function_spec�s 


�z0MockTest.test_assert_any_call_with_function_speccCsfdd�}t�}||_t|�t|�jg}|D]6}|dd�|dd�|�|jtdd�tdd�g�q*dS)NcSsdSrrr�rrrrJ�r*z3MockTest.test_mock_calls_create_autospec.<locals>.frKrirjr�)rrJrr9r�r)rrJ�objZfuncsr'rrr�test_mock_calls_create_autospec�s�

�z(MockTest.test_mock_calls_create_autospeccCs$tjt�dd�}|�dt|��dS)NZ
sweet_funcrS)rrrbrVrWr�rrr�test_create_autospec_with_name�sz'MockTest.test_create_autospec_with_namec
Cs`Gdd�d�}dD]H}|j|d��2t�t||��}|�|��|�t|d�W5QRXqdS)Nc@s$eZdZedd��Zedd��ZdS)zMMockTest.test_create_autospec_classmethod_and_staticmethod.<locals>.TestClasscSsdSrr)r+rrr�class_method�szZMockTest.test_create_autospec_classmethod_and_staticmethod.<locals>.TestClass.class_methodcSsdSrrrrrr�
static_method�sz[MockTest.test_create_autospec_classmethod_and_staticmethod.<locals>.TestClass.static_methodN)rr r!r/ryr0rzrrrr�	TestClass�s
r{)ryrz)r�Z	extra_arg)ZsubTestrrr�r�rPrN)rr{r�Zmock_methodrrr�1test_create_autospec_classmethod_and_staticmethod�sz:MockTest.test_create_autospec_classmethod_and_staticmethodc	Csht�}d}|�t|��|��W5QRX|�t|��|��W5QRXtdd�}|��|��dS)Nz1Attributes cannot start with 'assert' or 'assret'T)Zunsafe)r
ryr�Zassert_foo_callZassret_foo_call)rr�r�rrr�test_mock_unsafes
zMockTest.test_mock_unsafec	Cs<t�}|j��|��|�t��|j��W5QRXdSr)r
�hello�assert_not_calledrPr�r�rrr�test_assert_not_calleds

zMockTest.test_assert_not_calledcCs*t�}|dd�|�tt�d�|j�dS)NrKrizCalls: [call(1, 2)])r
ryr�r�r�rr�rrr�test_assert_not_called_messages
�z'MockTest.test_assert_not_called_messagec	CsNt�}|�t��|j��W5QRX|��|j��|��|j��dSr)r
rPr�r~r�r�rrr�test_assert_calleds
zMockTest.test_assert_calledc	Csdt�}|�t��|j��W5QRX|��|j��|��|�t��|j��W5QRXdSr)r
rPr�r~�assert_called_oncer�rrr�test_assert_called_once(s
z MockTest.test_assert_called_oncecCs2t�}|dd�|d�|�tt�d�|j�dS)NrKrirjzCalls: [call(1, 2), call(3)])r
ryr�r�r�r�r�rrr�test_assert_called_once_message3s
�z(MockTest.test_assert_called_once_messagec	Cs:t�}|�t��}|��W5QRX|�dt|j��dS)NzCalls:)r
rPr�r�r@r%r�)rr�r�rrr�*test_assert_called_once_message_not_called;sz3MockTest.test_assert_called_once_message_not_calledcCs0t�}|jddd�d}|�t|jj�|�dS)Nr~Zhero)rTZdaddyz call(name='hello', daddy='hero'))r
r~r9rWr=)rr��textrrr�test_ordered_call_signatureBsz$MockTest.test_ordered_call_signaturecCsVt��}t�dd�}t�}|��|�dd�|�|jd|�|�|jd|�dS)N�r~rrK)rr�indexr
r9r?)rr'rRr�rrr�test_override_tuple_methodsIsz$MockTest.test_override_tuple_methodscCs>tdddgd�}|jddd�|�|jt�|�|jd�dS)Nrnrirj�r<rOT)r
r~r�r<r9rOr�rrr�test_reset_return_sideeffectRsz%MockTest.test_reset_return_sideeffectcCs<tdddgd�}|jdd�|�|jt�|�|jd�dS)Nrnrirjr�TrH)r
r~r�r<r�rOr�rrr�test_reset_returnXszMockTest.test_reset_returncCs<tdddgd�}|jdd�|�|jd�|�|jd�dS)Nrnrirjr�Trq)r
r~r9r<rOr�rrr�test_reset_sideeffect^szMockTest.test_reset_sideeffectc	s�Gdd�dt�}Gdd�dt�}Gdd�dt��ttttg}t|�D]0}|�|f�fdd�	�|�|f�fd	d�	�qD|D�]}t�td
d�fD]�}|�}|j|j	|j
f||fdgd
gffD]�\}}t�td
d�fD]�}|j|f|�|j|�t
t|d
�|�t
t|d�d|k�r*|�t
t|dd�|j|f|�|�t
t|d�|j	|�t
t|d�d|kr�|�t
t|dd�q�q�q�qzdS)Nc@seZdZdZdS)z)MockTest.test_mock_add_spec.<locals>._OnerKN)rr r!rrrrr�_Oneesr�c@seZdZdZdS)z)MockTest.test_mock_add_spec.<locals>._TworiN)rr r!r
rrrr�_Twogsr�c@seZdZdZZZdS)z-MockTest.test_mock_add_spec.<locals>.AnythingZfourN)rr r!rr
rjrrrr�Anythingisr�cs
|�d�S)Nr^r��K�r�rrr�pr*z-MockTest.test_mock_add_spec.<locals>.<lambda>cs
|�d�S)Nr`rr�r�rrr�qr*Tr`rr
rjra)rbr
r	rrr�r�r1rr
rj�
mock_add_specrPr�r��setattr)	rr�r�ZklassesrUrgrZOneZTworr�r�test_mock_add_specdsz�
��
����zMockTest.test_mock_add_speccs|ttfD]n}|��t����t�|�tt��|���dd�j_��t�|�	t��d�|�t�fdd��qdS)NrRr�cs�dSr�rrrrrr��r*z;MockTest.test_mock_add_spec_magic_methods.<locals>.<lambda>)
r	rr�r�rbrPrNr3r<r9)rrUrrr� test_mock_add_spec_magic_methods�s

z)MockTest.test_mock_add_spec_magic_methodscCs�tttttfD]�}|�}t�|_|��|�|jt��g�|�|j	t��g�|�}tdd�|_
|�
�|�|jg�|�|j	g�|�}t��|_|��|�|jg�|�|j	g�qdS)NrTrS)rr
r	rr
rRr9r?rr�rUrY�rrUrrrr�test_adding_child_mock�s$�
zMockTest.test_adding_child_mockcCs@ttfD]2}|�}t�|_|��|�|jt�t��g�qdSr)r
r	r<r9r�rr�rrr�test_adding_return_value_mock�s
z&MockTest.test_adding_return_value_mockcCs�Gdd�dt�}t�}t�|d�}t�|d�}|��}|�|j�|��}|�|j�|�|d�|�|d�|��|��|�	|j
t��t��g�dS)Nc@seZdZdZdZdS)z'MockTest.test_manager_mock.<locals>.Foorr
N)rr r!rr
rrrrrS�srSrr
)rbr
rrr�r�attach_mockr
rr9r�r)rrS�managerZp1Zp2Zmock_oneZmock_tworrr�test_manager_mock�szMockTest.test_manager_mockcCshttfD]Z}|�}tdd�|_tdd�|_t|�t|�|�|jt��t��g�|�|j	g�qdS)NrjrHg@)
r
r	r3�	__float__r��floatr9r�rr?)rrUr�rrr�test_magic_methods_mock_calls�sz&MockTest.test_magic_methods_mock_callscCs<tjdd�}|d�}|��}|d�}|��}|�||�dS)N�data�Z	read_data�a-namezanother-name)rr��readr9)r�mocked_open�f1Zf1_data�f2Zf2_datarrr� test_mock_open_reuse_issue_21750�sz)MockTest.test_mock_open_reuse_issue_21750cCsVtjdd�}|d�}dd�|D�}|�|dd�|�|dd	�|�t|�g�dS)
NzRemarkable
Norwegian Bluer�r�cSsg|]}|�qSrr�r�linerrrr�sz=MockTest.test_mock_open_dunder_iter_issue.<locals>.<listcomp>rzRemarkable
rKzNorwegian Blue)rr�r9r�)rr�r��linesrrr� test_mock_open_dunder_iter_issue�sz)MockTest.test_mock_open_dunder_iter_issuec	Cs�tjdd�}|d�}t|�}|��}dd�|D�}|�|d�|�|d�|�|dd	�|�t|�g�|�t��t|�W5QRXdS)
Nz1st line
2nd line
3rd liner�r�cSsg|]}|�qSrrr�rrrrsz6MockTest.test_mock_open_using_next.<locals>.<listcomp>z	1st line
z	2nd line
rz3rd line)rr�rr"r9r�rPr�)rr�r�Zline1Zline2r�rrr�test_mock_open_using_next�sz"MockTest.test_mock_open_using_nextc	CsXt�tjdd��}t�d|��0|j}|j}td�|_dd�}|�t|�W5QRXdS)NZJLVrSztempfile.NamedTemporaryFilezTest 2 ErrorcSst���d�dS)NZasd)�tempfile�NamedTemporaryFile�writerrrr�attemptsz.MockTest.test_mock_open_write.<locals>.attempt)	rr�r	rr<r��OSErrorrOrP)rZmock_namedtempZmock_filehandleZ
mock_writer�rrr�test_mock_open_writes
zMockTest.test_mock_open_writecCsJtjdd�}dd�|jj_|���}|���}|�d|�|�d|�dS)Nzfoo
barnr�cWsdS)N�abcr)rfrrrr�r*z8MockTest.test_mock_open_alter_readline.<locals>.<lambda>r�)rr�r<�readlinerOr9)rZmopen�first�secondrrr�test_mock_open_alter_readlines

z&MockTest.test_mock_open_alter_readlinecCs�tjdd�}|d�}|��|�d|���|�d|���|�d|���|�d|���|�g|���|�g|���dS)NrRr�rUr.)rr�r�r9r��	readlines)r�_openrQrrr�test_mock_open_after_eofsz!MockTest.test_mock_open_after_eofcCs
ttfD]�}|�}t|�}||_|�|�|�|�t|�|�|��|�|�|�|�t|�|�|�}|j|_|�	dt|j��|�	dt|j��|��|�	dt|j��|�	dt|j��|�}t|�}|�|_||j_|�t|�|�|�t|���|�qdS)Nz
name='mock.a')
r
r	rWr<r�r9r~r%r&rV)rrUr�Z
original_reprrrr�test_mock_parents+s,zMockTest.test_mock_parentscCs�ttttf}|D]�}|D]z}|�}|dd�}|�|d�|�|j|�|�dt|��|j�	d�|�
|jtj�	d�g�|�
|j
tj�	d�g�qqdS)NrRrSrUzname='mock.bar'rK)r
r	rrr�r�rUrVrWrYr9r�rr?�r�classesrUZKlass2r�Zm2rrr�test_attach_mockHs
zMockTest.test_attach_mockcCs�ttttf}ttfD]h}|D]^}|�}|dd�}|�|d�|�|�|�|�dt|��|��|�	|j
t������qqdS)NrRrSr<z
name='mock()')
r
r	rrr�r�rVrWrRr9r�rr2r�rrr�test_attach_mock_return_valueYs
z&MockTest.test_attach_mock_return_valuec	Cs�t�}tjt�d�dd���}|�|j��d�|�|d�|�d�td�|d�t	�d�t	�d�t	�d�g}t	d�t	d�t	d�g}|�|j
|�|�|jj
|�|�tj
|�|�|j
|�|�d	t|jj��|�|j��d	�W5QRXdS)
N�
.somethingT�Zautospecr2r{rKrirj�
mock.child)
r
rrrr9Z_extract_mock_namer�r{r2rr�rVrW)rr|Z	mock_funcZparent_callsZchild_callsrrr�test_attach_mock_patch_autospecis
z(MockTest.test_attach_mock_patch_autospecc
Cs�tjt�d�dd���}t�}|�|d�t�}|jddddd	�|�tj	tj
ddddd	�g�|j�ttj
ddddd	�g�|�ttj
ddddd	�g�W5QRXtjt�d
�dd��R}t�}|�|d�td�|�t�d�g�t�td�g�|�td�g�W5QRXtjt�d�dd���}t�}|�|d
�t�}|jddddd	�|�t�
�t�
�jddddd	�g�|j�tddddd	�g�|�t�t�jddddd	�g�W5QRXdS)Nz.Something.methTr��attach_methrKrirjr�rhr��attach_funcz
.Something�
attach_obj)rrrr
r�r#r)r^rr�r�r2r�r�)rZmockedr�rvrrr�)test_attach_mock_patch_autospec_signature}s2&
�z2MockTest.test_attach_mock_patch_autospec_signaturecCsft�t�t�t�fD]L}|�t|d��|`|�t|d��|`|�t|d��|�	t
t|d�qdS)Nr�rJ)r
r	rrr;�hasattrr�r7rJrPr�r�rFrrr�test_attribute_deletion�s�z MockTest.test_attribute_deletioncCs�t�t�t�t�fD]t}d|_|�t|d��|�|jd�|`|�t|d��d|_|�t|d��|�|jd�|`|�t|d��qdS)NrjrRr�)	r
r	rrrRr;r�r9r7rFrrr�7test_mock_does_not_raise_on_repeated_attribute_deletion�s�z@MockTest.test_mock_does_not_raise_on_repeated_attribute_deletionc
Cs<t�t�t�t�fD]"}|`|�t��
|`W5QRXqdSr)r
r	rrrRrPr�rFrrr�4test_mock_raises_when_deleting_nonexistent_attribute�s�z=MockTest.test_mock_raises_when_deleting_nonexistent_attributecCs,t�}d|_|`|��|�t|d��dS)NTr{)r
r{r~r7r�rFrrr�/test_reset_mock_does_not_raise_on_attr_deletion�s
z8MockTest.test_reset_mock_does_not_raise_on_attr_deletioncCs:t�t�fD](}|�|t�t|_|�|t�|jqdSr)r
r	rDr�r�r�rRrFrrr�test_class_assignable�s
zMockTest.test_class_assignablecCs8|�tj�|�ttj�t�|�tt��j�t�dSr)�assertIsNotNonerrTr9rrrrrr�test_name_attribute_of_call�sz$MockTest.test_name_attribute_of_callcCs8|�tj�|�ttj�t�|�tt��j�t�dSr)r�rr|r9rrrrrr�test_parent_attribute_of_call�sz&MockTest.test_parent_attribute_of_callcCsddd�}t�}t|�|_|�dd�|�t|jd�|�|jt�dd�g�|�dt	|jj
��dS)NcSsdSrrr�rrrrR�r*zBMockTest.test_parent_propagation_with_create_autospec.<locals>.foorKrir�)r
rr{rPrNr9r�rrVrWr)rrRrrrr�,test_parent_propagation_with_create_autospec�s
z5MockTest.test_parent_propagation_with_create_autospeccCspdd�}t�}|�t|dd�d�|�dd�|�t|jd�|�|jjt�dd�g�|�	dt
|jj��dS)	NcSsdSrrr�rrrrR�r*zGMockTest.test_parent_propagation_with_autospec_attach_mock.<locals>.foorUrSr{rKrir�)r
r�rr{rPrNr9r�rrVrWr)rrRr|rrr�1test_parent_propagation_with_autospec_attach_mock�sz:MockTest.test_parent_propagation_with_autospec_attach_mockc		s�tjj}|�dd�|�t�d��|tjd=�fdd��|�tjt���t���ddl	m
}m}m}m
}||||tg}|D]}|td	�}|�|t�q~W5QRXdS)
NcSsttjd|�S)Nr)r�rr)rrrrr�
r*z9MockTest.test_isinstance_under_settrace.<locals>.<lambda>zsys.modulesz
unittest.mockcs�Srr)�frame�eventr���tracerrr�sz6MockTest.test_isinstance_under_settrace.<locals>.tracer)r
r	rrr^)rrrr�r1r��modules�settrace�gettrace�
unittest.mockr
r	rrr
r#r�)	rZ	old_patchr
r	rrrZrrvrr�r�test_isinstance_under_settrace�s&	
�
�
z'MockTest.test_isinstance_under_settraceN)�rr r!r5rGrIrMrQr[rdrvrwrzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
rrrr r!r$r)r-r4r5r7r9r:r<r=r>r?r@rErJrOrTrWrXrYrarfrirlrqrrrtrurwrxr|r}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr3+s	)&	










	8N
#
,((
	5	




r3�__main__)r�r�r�r�rZunittest.test.testmock.supportrrr�rrrrr	r
rrr
rrrrbrr#r2rr3r�mainrrrr�<module>s:8

	

F1le Man4ger