HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/unittest/test/testmock/__pycache__/testmock.cpython-37.opt-2.pyc
B

"��g��@s�ddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZGdd�de�ZGdd�de�Zd	d
�ZGdd�dej�Zed
kr�e��dS)�N)�is_instance)�mock)�call�DEFAULT�patch�sentinel�	MagicMock�Mock�NonCallableMock�NonCallableMagicMock�_Call�	_CallList�create_autospecc@s(eZdZdd�Zdd�Zdd�ZeZdS)�ItercCstddddg�|_dS)N�this�is�an�iter)r�thing)�self�r�;/usr/local/lib/python3.7/unittest/test/testmock/testmock.py�__init__sz
Iter.__init__cCs|S)Nr)rrrr�__iter__sz
Iter.__iter__cCs
t|j�S)N)�nextr)rrrrrsz	Iter.nextN)�__name__�
__module__�__qualname__rrr�__next__rrrrrsrc@s2eZdZddd�Zed	dd��Zed
dd��ZdS)�	SomethingNcCsdS)Nr)r�a�b�c�drrr�methszSomething.methcCsdS)Nr)�clsr r!r"r#rrr�cmeth"szSomething.cmethcCsdS)Nr)r r!r"r#rrr�smeth&szSomething.smeth)N)N)N)rrrr$�classmethodr&�staticmethodr'rrrrrs

rcCsdS)Nr)r rrr�	something+�r*c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
e�de
jkd�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Z d7d8�Z!d9d:�Z"d;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�Z0dWdX�Z1dYdZ�Z2d[d\�Z3d]d^�Z4d_d`�Z5dadb�Z6dcdd�Z7dedf�Z8dgdh�Z9didj�Z:dkdl�Z;dmdn�Z<dodp�Z=dqdr�Z>dsdt�Z?dudv�Z@dwdx�ZAdydz�ZBd{d|�ZCd}d~�ZDdd��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�S)��MockTestcCstd�dS)Nzfrom unittest.mock import *)�exec)rrrr�test_all0szMockTest.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 correctlyz(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_constructor7s(





zMockTest.test_constructorcCstdd�}|�|jd�dS)N)r4z(return value in constructor not honoured)r	r:r4)rrrrr� test_return_value_in_constructorSs
z)MockTest.test_return_value_in_constructorcCs�tdd�}|�dt|��|�dt|�t|��t�dftdd�dfg}x�|D]�\}}|�d|t|j��|�d|t|����|�d|t|��j��|�d	|t|���|�d
|t|����|�d|t|��jj��j��qPWdS)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�idrBr@Zbing�baz)rr�mocksrArrr�	test_reprYs

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)rrrrrrr�XjsrI)�specz
 spec='X' )�spec_setz spec_set='X' r@)rJrAz name='foo' )rArJ)�objectr	rCrDr8)rrIrrrr�test_repr_with_specis$


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>.effect���)�fishcs���S)N)�popr)�resultsrrrQ�szside effect not used correctly)�side_effectz#side effect in constructor not usedcSstS)N)rrrrrrX�sz.MockTest.test_side_effect.<locals>.side_effect)rXr4)	r	rX�assertRaisesrN�assert_called_withr1r�
SideEffect�RETURN)rrrQrXr)rWr�test_side_effect�s 
zMockTest.test_side_effectcs�dddg��fdd�}dd�}t|�}dddg|_|�|�|�|�gdddgd�dddg�t|�}||_|�|�|�|�gdddgd	�dS)
NrRrSrTcs���S)N)rVr)rWrrrQ�sz2MockTest.test_autospec_side_effect.<locals>.effectcSsdS)Nrrrrr�f�sz-MockTest.test_autospec_side_effect.<locals>.fz1side effect not used correctly in create_autospecz'callable side effect not used correctly)rrXr1)rrQr^rr)rWr�test_autospec_side_effect�s

z"MockTest.test_autospec_side_effectcCs,dd�}t|�}td�|_|�td|�dS)NcSsdS)Nrrrrrr^�sz7MockTest.test_autospec_side_effect_exception.<locals>.fzBazinga!)r�
ValueErrorrX�assertRaisesRegex)rr^rrrr�#test_autospec_side_effect_exception�s
z,MockTest.test_autospec_side_effect_exception�javaz This test only applies to JythoncCsdddl}t|j�d�d�}y|dddd�Wn|jjk
rDYnX|�d�|jdddd�dS)	NrzBoom!)rXrRrSrT)rUzjava exception not raised)rcr	�langZRuntimeException�failrZ)rrcrrrr�test_java_exception_side_effect�s
z(MockTest.test_java_exception_side_effectcCsRt�}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)Nr*�child)rA�parentrJ)r*zname 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	rrZ
SomethingElser*r[rXr4�
reset_mockr1�
_mock_namer;r<r/r0r2r5r6r7�
mock_callsr=)rrhrJrr*r4rrr�test_reset_mock�sD





zMockTest.test_reset_mockcCst�}||_|��dS)N)r	r4ri)rrrrr�test_reset_mock_recursion�sz"MockTest.test_reset_mock_recursioncCst��}|��dS)N)r�	mock_openri)rr rrr�(test_reset_mock_on_mock_open_issue_18622�sz1MockTest.test_reset_mock_on_mock_open_issue_18622cCst�}|�t|jt�d�|�}|�|�|d�|��|tj�}|�|jd�|�|j	dd�|�|j
tjfifd�|�|jtjfifgd�tj|_|tjtj
d�}|�|tjd	�|�|j	d
d�|�|j
tjfdtj
ifd�|�|jtjfiftjfdtj
ifgd
�dS)Nz%Default return_value should be a Mockz'different result from consecutive callszcalled not setrRzcall_count incoreectzcall_args not setz(call_args_list not initialised correctly)�keyzincorrect return valuerSzcall_count incorrectrpzcall_args_list not set)r	r3rr4r1rir�Argr0r2r5r6ZReturnValueZKeyArg)rr�resultZret_valrrr�	test_calls4



zMockTest.test_callc	Cs�t�}|�|tj�|tjd�|tjtjd�|�|jdtjffdtjiftjfdtjifg�|�|jtjfdtjif�|�|jdk�dS)N)�kwrrtza long sequence)r	rrqZKwargr1r6r5r/)rrrrr�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�dS)N)rrr3r/�ANYr)rZmmZcall1Zcall2rrr�test_calls_equal_with_any8sz"MockTest.test_calls_equal_with_anycCsdt�}|�|��|�t|jd�|��|�t|j�|dddddd�|jdddddd�dS)NrRrSrTrUZnothing)r r!)r	rZrY�AssertionErrorri)rrrrr�test_assert_called_withMsz MockTest.test_assert_called_withcCs t�}|t��|�tj�dS)N)rrZrrv)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
�WdQRX|�|jjt�dS)NcSsdS)Nr)r r!r"r#rrrr^csz9MockTest.test_assert_called_with_function_spec.<locals>.f)rJrRrSrT)r!r")r r!r"�)�e)N)r	rZrYrx�assertIsInstance�	exception�	__cause__�	TypeError)rr^r�cmrrr�%test_assert_called_with_function_specbs


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)NrRrSrT)r!r")r r!r")rZrYrx)r)rrr�_checkts

z<MockTest.test_assert_called_with_method_spec.<locals>._check)rJ)r	rr$r&r')rr�rr)rr�#test_assert_called_with_method_specssz,MockTest.test_assert_called_with_method_speccs�t���������|�t�j����|�t�j��dddd��jdddd�����dddd�|�t�fdd��dS)Nr@rBrS)rFcs�jdddd�S)N�bobrBrS)rF)�assert_called_once_withr)rrr�<lambda>�r+z7MockTest.test_assert_called_once_with.<locals>.<lambda>)r	r�rYrxri)rr)rr�test_assert_called_once_with�sz%MockTest.test_assert_called_once_withc	Cs�ddd�}t|d�}|dddd�|�ddd�|jdddd�|jt|jdddd�|�t��}|jd	d
�WdQRX|�|jjt�|ddd
�|�t|jddd�|�t|jddd
�dS)NcSsdS)Nr)r r!r"r#rrrr^�sz>MockTest.test_assert_called_once_with_function_spec.<locals>.f)rJrRrSrT)r!r")r r!r"r|)r}���)N)r	r�rYrxr~rr�r�)rr^rr�rrr�*test_assert_called_once_with_function_spec�s





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 namerTzmethod returned wrong valuez!method didn't record being called)r	r*r3rr1r4r0)rrr*rrr�#test_attribute_access_returns_mocks�s

z,MockTest.test_attribute_access_returns_mockscCs0t�}|j}|�|jdd�|�|j|d�dS)Nr*z attribute name not set correctlyz"attribute parent not set correctly)r	r*r1rjr;)rrr*rrr�(test_attributes_have_name_and_parent_set�s

z1MockTest.test_attributes_have_name_and_parent_setcCstt�}|jddd�|jjdtjd�|�|jjdddtjifgd�|�|jdd	d
difdddtjifgd�dS)NrT)rUr�)�caker*)r�r�z#method calls not recorded correctly)rTrUzsomething_else.something)r	r*�something_elserZCaker1r7)rrrrr�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)
N)r*r*r�	different)r*)r�)r�rR)�xr�Zmore)�somer�)r	r*r1r7)rrrrr� test_method_calls_compare_easily�s"
z)MockTest.test_method_calls_compare_easilyc	CsLxFdgdfD]8}x2dD]*}tf||i�}|j|�tdt|d�qWqWdS)Nr*)r*)rJrKz-Mock object has no attribute 'something_else'r�)r	r*ra�AttributeError�getattr)rrJ�argrrrr�test_only_allowed_methods_exist�s
z(MockTest.test_only_allowed_methods_existcs>Gdd�dt�}�fdd�}|t|d��|t|�d��dS)Nc@seZdZdZdZdd�ZdS)z*MockTest.test_from_spec.<locals>.SomethingrTNcSsdS)Nr)rrrr�y	sz,MockTest.test_from_spec.<locals>.Something.y)rrrr��
__something__r�rrrrrsrcs:|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�rar�r�)r)rrr�test_attributess
z0MockTest.test_from_spec.<locals>.test_attributes)rJ)rLr	)rrr�r)rr�test_from_specszMockTest.test_from_speccCsJt�}t|d�}|�|�|��|��|dddd�|jdddd�dS)N)�wrapsrRrSrT)rU)r	r1rirZ)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>.RealN)rrrrrrr�Real-sr�)r�cs���S)N)Znew_attrr)rrrr�3r+zJMockTest.test_wraps_prevents_automatic_creation_of_mocks.<locals>.<lambda>)rLr	rYr�)rr�r�r)rr�/test_wraps_prevents_automatic_creation_of_mocks,s
z8MockTest.test_wraps_prevents_automatic_creation_of_mockscCs4t�}t|d�}d|_|�|�d�|�|j�dS)N)r�rT)r	r4r1r/r0)rr�rrrr�,test_wraps_call_with_nondefault_return_value6s

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)rrrr	�	attributerrrrr�Asr�)r�cs�jS)N)rUr)rrrr�Hr+z0MockTest.test_wraps_attributes.<locals>.<lambda>rRrSrT)rU)	rLr	r1r�rYr��assertNotEqualZfrogrZ)rr�r�rrr)rr�test_wraps_attributes@s
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>.RealcSstjS)N)r�ORIGINAL_VALUE)rrrr�methodRszbMockTest.test_customize_wrapped_object_with_side_effect_iterable_with_default.<locals>.Real.methodN)rrrr�rrrrr�Qsr�)r�)rLr	r�VALUE1rr�rXr1r�rY�
StopIteration)rr�r�rrrr�Dtest_customize_wrapped_object_with_side_effect_iterable_with_defaultPs
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>.RealcSs
t��dS)N)�NotImplementedError)rrrrr�`szUMockTest.test_customize_wrapped_object_with_side_effect_iterable.<locals>.Real.methodN)rrrr�rrrrr�_sr�)r�)
rLr	rr��VALUE2r�rXr1rYr�)rr�r�rrrr�7test_customize_wrapped_object_with_side_effect_iterable^s
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>.RealcSs
t��dS)N)r�)rrrrr�nszVMockTest.test_customize_wrapped_object_with_side_effect_exception.<locals>.Real.methodN)rrrr�rrrrr�msr�)r�)rLr	�RuntimeErrorr�rXrY)rr�r�rrrr�8test_customize_wrapped_object_with_side_effect_exceptionls

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>.RealcSs
t��dS)N)r�)rrrrr�zszUMockTest.test_customize_wrapped_object_with_side_effect_function.<locals>.Real.methodN)rrrr�rrrrr�ysr�cSstjS)N)r�VALUErrrrrX}szUMockTest.test_customize_wrapped_object_with_side_effect_function.<locals>.side_effect)r�)rLr	r�rXr1rr�)rr�rXr�rrrr�7test_customize_wrapped_object_with_side_effect_functionxs
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>.RealcSs
t��dS)N)r�)rrrrr��szMMockTest.test_customize_wrapped_object_with_return_value.<locals>.Real.methodN)rrrr�rrrrr��sr�)r�)rLr	rr�r�r4r1)rr�r�rrrr�/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>.RealcSs
t��dS)N)r�)rrrrr��sz]MockTest.test_customize_wrapped_object_with_return_value_and_side_effect.<locals>.Real.methodN)rrrr�rrrrr��sr�)r�)rLr	rr�r�r�rXZWRONG_VALUEr4r1rYr�)rr�r�rrrr�?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>.RealcSs
t��dS)N)r�)rrrrr��sz^MockTest.test_customize_wrapped_object_with_return_value_and_side_effect2.<locals>.Real.methodN)rrrr�rrrrr��sr�)r�cSstS)N)rrrrrr��r+z[MockTest.test_customize_wrapped_object_with_return_value_and_side_effect2.<locals>.<lambda>)rLr	r�rXrr�r4r1)rr�r�rrrr�@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>.RealcSs
t��dS)N)r�)rrrrr��szeMockTest.test_customize_wrapped_object_with_return_value_and_side_effect_default.<locals>.Real.methodN)rrrr�rrrrr��sr�)r�)rLr	rr�rr�rXr\r4r1rYr�)rr�r�rrrr�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)N)rXr@)r	r�rY)rrrrr�test_exceptional_side_effect�s
z%MockTest.test_exceptional_side_effectcCs4ttd�}|�t|�ttd�d�}|�t|�dS)N)rXr@)r	�KeyboardInterruptrY)rrrrr� test_baseexceptional_side_effect�s
z)MockTest.test_baseexceptional_side_effectcCst�}|�td|j�dS)Nz
Not called)r	rarxrZ)rrrrr�test_assert_called_with_message�sz(MockTest.test_assert_called_with_messagecCstdd�}|�td|j�dS)NZgeoffrey)rAz'Expected 'geoffrey' to be called once\.)r	rarxr�)rrrrr�$test_assert_called_once_with_message�s
z-MockTest.test_assert_called_once_with_messagecs2t��|�t�fdd��d�_|��jd�dS)Ncs�jS)N)rr)rrrr��r+z'MockTest.test__name__.<locals>.<lambda>r@)r	rYr�rr1)rr)rr�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>.SubN)rrrrrrr�Sub�sr�r@)rJrT)�listr	�appendrZrYr�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>.XN)rrrrrrrrI�srI)rJr	)rK)rLr	r~�assertIs�	__class__r1r)rrIrrrr�test_spec_class�s

zMockTest.test_spec_classcsLGdd�dt�}t|d��d�_t|d���fdd�}d�_|�t|�dS)Nc@seZdZdZdS)z8MockTest.test_setting_attribute_with_spec_set.<locals>.XrTN)rrrr�rrrrrIsrI)rJr@)rKcs
d�_dS)Nr@)r�r)rrr�set_attrsz?MockTest.test_setting_attribute_with_spec_set.<locals>.set_attr)rLr	r�r�rYr�)rrIr�r)rr�$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	)rZcurrentrrr�	test_copyszMockTest.test_copycs\Gdd�dt�}||d��|��jd��fdd�}|�t|��fdd�}|�t|�dS)Nc@s&eZdZdd�Zdd�Zeee�ZdS)z8MockTest.test_subclass_with_properties.<locals>.SubClasscSsdS)NrTr)rrrr�_getsz=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)rrrr�r��property�some_attributerrrr�SubClasssr�)rKrTcs
d�_dS)NrT)r�r)�srr�test'sz4MockTest.test_subclass_with_properties.<locals>.testcs
d�_dS)NrB)r@r)r�rrr�+s)r	r1r�rYr�r�)rr�r�r)r�r�test_subclass_with_propertiess
z&MockTest.test_subclass_with_propertiescCs>t�}dd�}|t|�_|d�|�d�|�t|dd�dS)NcSs
|�|�S)N)Z
_mock_call)rr rrr�__call__2sz,MockTest.test_setting_call.<locals>.__call__�one�two)r	�typer�rZrYr�)rrr�rrr�test_setting_call0s

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)�.0rzrrr�
<listcomp>?sz%MockTest.test_dir.<locals>.<listcomp>r r!r"r#cSstg�S)N)r)r�rrrr�Or+z#MockTest.test_dir.<locals>.<lambda>r)
r	�set�dirr1r r!rCr"r#r)rr�attrs�
type_attrsrrr�test_dir<s
zMockTest.test_dircCsXttjd�}tttj��}tt|��}|�t�||�d|_|�t|��d�d�dS)N)rJrT�versionrR)r	�unittest�TestCaser�r�r1r��count)rrZtestcase_attrsr�rrr�test_dir_from_specSszMockTest.test_dir_from_speccCsVt�tdd�}|��z0ttt���}ttt��}|�t�||�Wd|��XdS)NZ
FILTER_DIRF)	rrLr�startr�r�r	r1�stop)rZpatcherr�r�rrr�test_filter_dir`szMockTest.test_filter_dircCs6t�}d|j_|�dt|��|`|�dt|��dS)NrRrg)r	rgr4rCr�r8)rrrrr�,test_dir_does_not_include_deleted_attributesms
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)NrB)r@�!)rXzfoo.bar.return_valuer@)	r	r1r@r�KeyErrorrYrBr~Zconfigure_mock)rrrPrrr�test_configure_mockvs



zMockTest.test_configure_mockcOs\y|||�Wn$t��d}|�||�YnX|�d|f�t|�}|�||�dS)NrRzException %r not raised)r��exc_infor~re�strr1)rr�message�funcrOrP�instance�msgrrr�assertRaisesWithMsg�szMockTest.assertRaisesWithMsgc
Cs(t�}d}d}|jt||f|jddddd�|jddddd�|jj|jjg}x8|D]0}d	}d
}d}|jt|||f|ddddd�qVWx2|D]*}d	}d}d}|jt|||f|dd�q�Wx4|D],}d	}d
}d}|�t|||f|ddd�q�Wx.|D]&}d	}d}d}|�t|||f|�q�WdS)Nzmock(1, '2', 3, bar='foo')zExpected call: %s
Not calledrR�2rTr@)rB)r@zfoo(1, '2', 3, foo='foo')zfoo(1, '2', 3, bar='foo')z!Expected call: %s
Actual call: %szfoo(bar='foo')zfoo(1, 2, 3)rSzfoo())r
r�rxrZr@r�)rr�expectedr�Z	assertersr$�actualrrr�'test_assert_called_with_failure_message�sF




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�	��
�����x: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�������qtWdS)NT�rrRrSrTr�r�)r r!z().foo)rRrSrTr@z
().foo.barz().foo.bar().bazrB)rAzfoo.__int__r za()z().foo.bar().baz().__int__���)rr�rkr1r@r�r�dictr4rBrF�	call_listr�r r!r"�__int__)rrr�rPZ	last_callrrr�test_mock_calls�st







 



zMockTest.test_mock_callscCsFt�}|�}|��|�|jt�t���g�|�|jt��g�dS)N)r	Zwibbler1rkr)rrzrrrrr�test_child_mock_call_equals
z#MockTest.test_child_mock_call_equalcCsFt�}|����|�|jdt�����|�|jdt���dS)NrRr)r	r@r*r�rkrr�r1)rrzrrr�test_mock_call_not_equal_leaf(sz&MockTest.test_mock_call_not_equal_leafcCsFt�}|����|�|jdt�����|�|jdt���dS)NrRr)r	r@rBr�rkrrF)rrzrrr�!test_mock_call_not_equal_non_leaf/sz*MockTest.test_mock_call_not_equal_non_leafcCs8t�}|jdd���|�|jdtjdd����dS)NrR)r�rS)r	r@rBr1rkr)rrzrrr�2test_mock_call_not_equal_non_leaf_params_different6sz;MockTest.test_mock_call_not_equal_non_leaf_params_differentcCs,t�}|j��|�|jdtj���dS)Nr)r	r@rBr�rkrrF)rrzrrr�&test_mock_call_not_equal_non_leaf_attr=s
z/MockTest.test_mock_call_not_equal_non_leaf_attrcCs.t�}|j��|�|jdt�����dS)Nr)r	r@rBr�rkr)rrzrrr�2test_mock_call_not_equal_non_leaf_call_versus_attrCs
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()rRzcall.foo().bar()rSzcall.foo().bar().baz.bob())r	r@rBrFr�r1rDrk)rrzrrr�test_mock_call_reprIs
zMockTest.test_mock_call_reprcCshGdd�dt�}|�}|�|j|�|�|�|�Gdd�dt�}|�}|�|j|�|�|�|�dS)Nc@seZdZdS)z+MockTest.test_subclassing.<locals>.SubclassN)rrrrrrr�SubclassRsrc@seZdZdd�ZdS)z+MockTest.test_subclassing.<locals>.Subclassc[s
tf|�S)N)r	)rrPrrr�_get_child_mockZsz;MockTest.test_subclassing.<locals>.Subclass._get_child_mockN)rrrrrrrrrYs)r	r~r@�assertNotIsInstance)rrrrrr�test_subclassingQszMockTest.test_subclassingcs�t�t�t�t�g}�fdd�}x�|D]z}||�t|�rd|�|dd�|dd�|��||�|��|jjddd�|�d����d�|��||�q&WdS)NcsDd}x:|D]2}t||�}��|t���|t���|g�q
WdS)N)r6r7rk)r�r~r
r�r1)r�namesrA�attr)rrr�assert_attrsjs

z-MockTest.test_arg_lists.<locals>.assert_attrsrRrSrT)r )	r	rr
r�callablerir@rBrF)rrGrrr)rr�test_arg_listsbs$


zMockTest.test_arg_listscCs�t�}|ddd�|ddd�|�t|j�d�|j\}}|�|d�|�|tdd��dtdd�fdtdd�fg}xPt||j�D]@\}}|�t|�d�|�|d	|d	�|�|d|d�q�WdS)
NrRrT)r rSr�)r!)rS)rRr)r	r1�lenr5r�zipr6)rrrOrPZ
expected_listr�r5rrr�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)NrRrSrT)rXr r!r"Zghi�g�h�ic@seZdZdS)z/MockTest.test_side_effect_iterator.<locals>.FooN)rrrrrrr�Foo�srrrrr)	r	rr1rYr�rrLr~r)rrrrrr�test_side_effect_iterator�s 

z"MockTest.test_side_effect_iteratorcCs`xZttfD]N}tdtdf}||d�}|�t|�|�|�d�|�t|�|�|�d�q
WdS)NrTr�)rX)r	rr`r�rYr1)r�Klass�iterablerzrrr�$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)NrRrSrTr r!r"rrrr)
r	rrXr1rYr�r~r�rr�)rrrXZ	this_iterrrr�!test_side_effect_setting_iterator�s"z*MockTest.test_side_effect_setting_iteratorcCs4tdd�}tdtg�|_|�|�|�gddg�dS)NrS)r4rR)r	rrrXr1)rrrrr�!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}x|D]}|j|gdd�q~Wx<tdd�tdd�t�dddfD]}|jt|j|gdd�q�Wtdd�tdd�gtdd�tdd�gtdd�tdd�gg}x|D]}|j|dd��qWtdd�tdd�tdd�gtdd�tdd�gtdd�tdd�tdd�gtdd�tdd�tdd�tdd�tdd�gg}x"|D]}|jt|j|dd��q�WdS)NrRrSrT)r r�r�)r!r ))rTr�r)r�)rRrSr�)rRrST)�	any_orderr�r@r��)r	r�assert_has_callsrYrx)rr�kalls�kallZ
kall_listsZ	kall_listrrr�test_assert_has_calls_any_order�s:





$
.
z(MockTest.test_assert_has_calls_any_orderc	
Cs�tdd�ddifdtdd�dd	d
difg}t��t�d�g}|�t��jdd����|�tjt�id��	dg����g}xVt
�t�fD]F}|dd�|dd�|dd
�|dd�|ddd�|�||f�q�Wt
�}|��|�d�|��jdd�|jt�id��	dg�|�||f�xz|D]r\}}xft
t|��D]V}xNdD]F}||||�}|�|�t|�dk�rH|�t|jtt|����qHW�q>W�q(WdS)NrRrSr rT))rTr�r�)r!r�)rRr!)r )r@r�)rRrSrT)rr@rB�extendZspamrFrZbamr�rUr	rr��rangerr#rYrxr��reversed)	rZkalls1Zkalls2rGrr$r�stepZtheserrr�test_assert_has_calls�s<
"






zMockTest.test_assert_has_callsc	CsRGdd�d�}t|�}xV||�gD]H}|jddddd�|�tjddddd�g�|�t�dddd�g�q"W|��xz||�gD]l}|�t|jt��g�|�d��dd�|�t�d�t�d��dd�g�|j�td�t��dd�g�q�W|��t�d�t�	d�t���	d�t���dddd�g}x |D]}|�t|j|g��q2WdS)Nc@s,eZdZdd�Zddd�ZGdd�d�ZdS)	z=MockTest.test_assert_has_calls_nested_spec.<locals>.SomethingcSsdS)Nr)rrrrr)r+zFMockTest.test_assert_has_calls_nested_spec.<locals>.Something.__init__NcSsdS)Nr)rr r!r"r#rrrr$*r+zBMockTest.test_assert_has_calls_nested_spec.<locals>.Something.methc@seZdZdd�Zdd�ZdS)zAMockTest.test_assert_has_calls_nested_spec.<locals>.Something.FoocSsdS)Nr)rr rrrr.r+zJMockTest.test_assert_has_calls_nested_spec.<locals>.Something.Foo.__init__cSsdS)Nr)rr r!rrr�meth1/r+zGMockTest.test_assert_has_calls_nested_spec.<locals>.Something.Foo.meth1N)rrrrr,rrrrr,sr)N)rrrrr$rrrrrr's
rrRrSrT)r#r�)
rr$r#rrirYrxrr,Znon_existent)rrZ
mock_classrzZ
invalid_callsr%rrr�!test_assert_has_calls_nested_spec&s*
""
z*MockTest.test_assert_has_calls_nested_speccCsJt�}|�������|������t��������}|�	|�dS)N)
rr@rBrFr�r��threerrr#)rrz�callsrrr�)test_assert_has_calls_nested_without_specNs
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��|�|�WdQRX|j|dd�|�t��|�|dd��WdQRX|j|dd�dd�|�t��|�|dd��WdQRX|j|dd�dd�dS)NcSsdS)Nr)r r!r"r#rrrr^Wsz<MockTest.test_assert_has_calls_with_function_spec.<locals>.f)rJrRrSrT)r!r"r�r�r�r")r"r#�
��)r"r�)rRrSrT)r�r�r�r#)r1r2r3T)r!r�)N)r	r#r�r)rYrx)rr^rr/rrr�(test_assert_has_calls_with_function_specVs0



z1MockTest.test_assert_has_calls_with_function_specc	Cs�d	dd�}t|d�}|d�|�td�t�d����}|�t�g�WdQRX|�|j	j
�|�td�t�d����}|�t�tdd�g�WdQRX|�|j	j
t�dS)
NcSsdS)Nr)r�rrrr^wr+zAMockTest.test_assert_has_calls_not_matching_spec_error.<locals>.f)rJrRz^{}$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)]rS)N)
r	rarx�format�re�escaper#rr:rr�r~r�)rr^rr�rrr�-test_assert_has_calls_not_matching_spec_errorvs$


 z6MockTest.test_assert_has_calls_not_matching_spec_errorcCs�t�}|dd�|dd�|ddd�|�dd�|jdd�|jddd�|�t|j�|�t|jdd�|jt|jdd�dS)NrRrSrT)r r�)r!r�)r	�assert_any_callrYrx)rrrrr�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�WdQRX|�|jjt�dS)NcSsdS)Nr)r r!r"r#rrrr^�sz;MockTest.test_assert_any_call_with_function_spec.<locals>.f)rJrRrSrT)r!r"r�r�r�r")r"r#)r r!r")r r!r"r#r|)r})N)r	r9rYrxr~rr�r�)rr^rr�rrr�'test_assert_any_call_with_function_spec�s


z0MockTest.test_assert_any_call_with_function_speccCsjdd�}t�}||_t|�t|�jg}x>|D]6}|dd�|dd�|�|jtdd�tdd�g�q,WdS)NcSsdS)Nr)r r!rrrr^�sz3MockTest.test_mock_calls_create_autospec.<locals>.frRrSrTr�)rr^rr1rkr)rr^�objZfuncsr�rrr�test_mock_calls_create_autospec�s


z(MockTest.test_mock_calls_create_autospeccCs$tjt�dd�}|�dt|��dS)NZ
sweet_func)rA)rrrLrCrD)rrzrrr�test_create_autospec_with_name�sz'MockTest.test_create_autospec_with_namec
CsdGdd�d�}xPdD]H}|j|d��2t�t||��}|�|��|�t|d�WdQRXqWdS)Nc@s$eZdZedd��Zedd��ZdS)zMMockTest.test_create_autospec_classmethod_and_staticmethod.<locals>.TestClasscSsdS)Nr)r%rrr�class_method�szZMockTest.test_create_autospec_classmethod_and_staticmethod.<locals>.TestClass.class_methodcSsdS)Nrrrrr�
static_method�sz[MockTest.test_create_autospec_classmethod_and_staticmethod.<locals>.TestClass.static_methodN)rrrr(r?r)r@rrrr�	TestClass�srA)r?r@)r�Z	extra_arg)ZsubTestrrr�r�rYr�)rrAr�Zmock_methodrrr�1test_create_autospec_classmethod_and_staticmethod�s
z:MockTest.test_create_autospec_classmethod_and_staticmethodc	Cs`t�}|�t��|��WdQRX|�t��|��WdQRXtdd�}|��|��dS)NT)Zunsafe)r	rYr�Zassert_foo_callZassret_foo_call)rrzrrr�test_mock_unsafe�s
zMockTest.test_mock_unsafec	Cs<t�}|j��|��|�t��|j��WdQRXdS)N)r	�helloZassert_not_calledrYrx)rrzrrr�test_assert_not_called�s

zMockTest.test_assert_not_calledc	CsNt�}|�t��|j��WdQRX|��|j��|��|j��dS)N)r	rYrxrDZ
assert_called)rrzrrr�test_assert_called�s
zMockTest.test_assert_calledc	Csdt�}|�t��|j��WdQRX|��|j��|��|�t��|j��WdQRXdS)N)r	rYrxrDZassert_called_once)rrzrrr�test_assert_called_onces
z MockTest.test_assert_called_oncecCs0t�}|jddd�d}|�t|jj�|�dS)NrDZhero)rAZdaddyz call(daddy='hero', name='hello'))r	rDr1rDr5)rrz�textrrr�test_sorted_call_signaturesz#MockTest.test_sorted_call_signaturecCsVt��}t�dd�}t�}|��|�dd�|�|jd|�|�|jd|�dS)N�rDrrR)rr��indexr	r1r7)rr"rrzrrr�test_override_tuple_methodssz$MockTest.test_override_tuple_methodscCs>tdddgd�}|jddd�|�|jt�|�|jd�dS)Nr1rSrT)r4rXT)r	rir~r4r1rX)rrzrrr�test_reset_return_sideeffect sz%MockTest.test_reset_return_sideeffectcCs<tdddgd�}|jdd�|�|jt�|�|jd�dS)Nr1rSrT)r4rXT)r4)r	rir~r4r�rX)rrzrrr�test_reset_return&szMockTest.test_reset_returncCs<tdddgd�}|jdd�|�|jd�|�|jd�dS)Nr1rSrT)r4rXT)rX)r	rir1r4rX)rrzrrr�test_reset_sideeffect,szMockTest.test_reset_sideeffectc	s�Gdd�dt�}Gdd�dt�}Gdd�dt��ttttg}x<t|�D]0}|�|f�fdd�	�|�|f�fd	d�	�qFW�x|D�]}�xt�td
d�fD]�}|�}|j|j	|j
fx�||fdgd
gfgD]�\}}x�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�Wq�Wq�Wq�WdS)Nc@seZdZdZdS)z)MockTest.test_mock_add_spec.<locals>._OnerRN)rrrr�rrrr�_One3srPc@seZdZdZdS)z)MockTest.test_mock_add_spec.<locals>._TworSN)rrrr�rrrr�_Two5srQc@seZdZdZZZdS)z-MockTest.test_mock_add_spec.<locals>.AnythingZfourN)rrrr�r�r.rrrr�Anything7srRcs
|�d�S)N)rJr)�K)rRrrr�>r+z-MockTest.test_mock_add_spec.<locals>.<lambda>cs
|�d�S)N)rKr)rS)rRrrr�?r+T)rKr�r�r.rK)rLr	rr
rr�r�rr�r�r.�
mock_add_specrYr�r��setattr)	rrPrQZklassesrrPrZOneZTwor)rRr�test_mock_add_spec2s>
zMockTest.test_mock_add_speccs�xzttfD]n}|��t����t�|�tt��|���dd�j_��t�|�	t��d�|�t�fdd��q
WdS)Nr@r�cs�dS)Nr@rr)rrrr�ur+z;MockTest.test_mock_add_spec_magic_methods.<locals>.<lambda>)
rrr�rTrLrYr�rr4r1)rrr)rr� test_mock_add_spec_magic_methodsgs

z)MockTest.test_mock_add_spec_magic_methodscCs�x�ttttfD]�}|�}t�|_|��|�|jt��g�|�|jt��g�|�}tdd�|_	|�	�|�|jg�|�|jg�|�}t��|_
|�
�|�|jg�|�|jg�qWdS)NrA)rA)r
r	rrr@r1r7rrkrBrF)rrrrrr�test_adding_child_mockxs 
zMockTest.test_adding_child_mockcCsDx>ttfD]2}|�}t�|_|��|�|jt�t��g�q
WdS)N)r	rr4r1rkr)rrrrrr�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)rrrr�r�rrrrr�srr�r�)rLr	rr�r�r��attach_mockr�r�r1rkr)rr�managerZp1Zp2Zmock_oneZmock_tworrr�test_manager_mock�szMockTest.test_manager_mockcCslxfttfD]Z}|�}tdd�|_tdd�|_t|�t|�|�|jt��t��g�|�|j	g�q
WdS)NrT)r4g@)
r	rr�	__float__r��floatr1rkrr7)rrrzrrr�test_magic_methods_mock_calls�sz&MockTest.test_magic_methods_mock_callscCs<tjdd�}|d�}|��}|d�}|��}|�||�dS)N�data)�	read_dataza-namezanother-name)rrn�readr1)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 Blue)raza-namecSsg|]}|�qSrr)r��linerrrr��sz=MockTest.test_mock_open_dunder_iter_issue.<locals>.<listcomp>rzRemarkable
rRzNorwegian Blue)rrnr1r�)rrcrd�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|�WdQRXdS)
Nz1st line
2nd line
3rd line)raza-namecSsg|]}|�qSrr)r�rgrrrr��sz6MockTest.test_mock_open_using_next.<locals>.<listcomp>z	1st line
z	2nd line
rz3rd line)rrnrrr1r�rYr�)rrcrdZline1Zline2rhrrr�test_mock_open_using_next�sz"MockTest.test_mock_open_using_nextc	CsXt�tjdd��}t�d|��0|j}|j}td�|_dd�}|�t|�WdQRXdS)NZJLV)rAztempfile.NamedTemporaryFilezTest 2 ErrorcSst���d�dS)NZasd)�tempfileZNamedTemporaryFile�writerrrr�attempt�sz.MockTest.test_mock_open_write.<locals>.attempt)	rrnrrr4rl�OSErrorrXrY)rZmock_namedtempZmock_filehandleZ
mock_writermrrr�test_mock_open_write�s
zMockTest.test_mock_open_writecCsJtjdd�}dd�|jj_|���}|���}|�d|�|�d|�dS)Nzfoo
barn)racWsdS)N�abcr)rOrrrr��r+z8MockTest.test_mock_open_alter_readline.<locals>.<lambda>rp)rrnr4�readlinerXr1)rZmopen�first�secondrrr�test_mock_open_alter_readline�s

z&MockTest.test_mock_open_alter_readlinecCs�tjdd�}|d�}|��|�d|���|�d|���|�d|���|�d|���|�g|���|�g|���dS)Nr@)rarBr�)rrnrbr1rq�	readlines)rZ_openrrrr�test_mock_open_after_eof�sz!MockTest.test_mock_open_after_eofcCs�xttfD]�}|�}t|�}||_|�|�|�|�t|�|�|��|�|�|�|�t|�|�|�}|j|_|�	dt|j��|�	dt|j��|��|�	dt|j��|�	dt|j��|�}t|�}|�|_||j_|�t|�|�|�t|���|�qWdS)Nz
name='mock.a')
r	rrDr4r�r1rir r!rC)rrrzZ
original_reprrrr�test_mock_parents�s,zMockTest.test_mock_parentscCs�ttttf}x�|D]�}x�|D]z}|�}|dd�}|�|d�|�|j|�|�dt|��|j�	d�|�
|jtj�	d�g�|�
|j
tj�	d�g�qWqWdS)Nr@)rArBzname='mock.bar'rR)r	rrr
rZr�rBrCrDrFr1rkrr7)r�classesr�Klass2rz�m2rrr�test_attach_mocks


zMockTest.test_attach_mockcCs�ttttf}xxttfD]l}xf|D]^}|�}|dd�}|�|d�|�|�|�|�dt|��|��|�	|j
t������q WqWdS)Nr@)rAr4z
name='mock()')
r	rrr
rZr�rCrDr@r1rkrr)rrxrryrzrzrrr�test_attach_mock_return_value&s

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	�WdQRXdS)
Nz
.somethingT)�autospecr*rgrRrSrTz
mock.child)
r	rrrr1Z_extract_mock_namerZrgr*rrkrCrD)rrhZ	mock_funcZparent_callsZchild_callsrrr�test_attach_mock_patch_autospec6s
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�WdQRXtjt�d
�dd��R}t�}|�|d�td�|�t�d�g�t�td�g�|�td�g�WdQRXtjt�d�dd���}t�}|�|d
�t�}|jddddd	�|�t�
�t�
�jddddd	�g�|j�tddddd	�g�|�t�t�jddddd	�g�WdQRXdS)Nz.Something.methT)r}�attach_methrRrSrTr�)r#z
.something�attach_funcz
.Something�
attach_obj)rrrr	rZrr$r#rrrvr*r�r�)rZmockedr[r<rrr�)test_attach_mock_patch_autospec_signatureJs0&
z2MockTest.test_attach_mock_patch_autospec_signaturecCsjxdt�t�t�t�fD]L}|�t|d��|`|�t|d��|`|�t|d��|�	t
t|d�qWdS)Nrzr^)r	rrr
r3�hasattrrzr/r^rYr�r�)rrrrr�test_attribute_deletiongsz MockTest.test_attribute_deletioncCs�x�t�t�t�t�fD]t}d|_|�t|d��|�|jd�|`|�t|d��d|_|�t|d��|�|jd�|`|�t|d��qWdS)NrTr@r�)	r	rrr
r@r3r�r1r/)rrrrr�7test_mock_does_not_raise_on_repeated_attribute_deletiontsz@MockTest.test_mock_does_not_raise_on_repeated_attribute_deletionc
Cs@x:t�t�t�t�fD]"}|`|�t��
|`WdQRXqWdS)N)r	rrr
r@rYr�)rrrrr�4test_mock_raises_when_deleting_nonexistent_attribute�s
z=MockTest.test_mock_raises_when_deleting_nonexistent_attributecCs,t�}d|_|`|��|�t|d��dS)NTrg)r	rgrir/r�)rrrrr�/test_reset_mock_does_not_raise_on_attr_deletion�s
z8MockTest.test_reset_mock_does_not_raise_on_attr_deletioncCs>x8t�t�fD](}|�|t�t|_|�|t�|jqWdS)N)r	rr
r�r�r~r@)rrrrr�test_class_assignable�s
zMockTest.test_class_assignablecCs8|�tj�|�ttj�t�|�tt��j�t�dS)N)�assertIsNotNonerrAr1r�r)rrrr�test_name_attribute_of_call�sz$MockTest.test_name_attribute_of_callcCs8|�tj�|�ttj�t�|�tt��j�t�dS)N)r�rrhr1r�r)rrrr�test_parent_attribute_of_call�sz&MockTest.test_parent_attribute_of_callcCsddd�}t�}t|�|_|�dd�|�t|jd�|�|jt�dd�g�|�dt	|jj
��dS)NcSsdS)Nr)r r!rrrr@�szBMockTest.test_parent_propagation_with_create_autospec.<locals>.foorRrSz
mock.child)r	rrgrYr�r1rkrrCrDr)rr@rrrr�,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)	NcSsdS)Nr)r r!rrrr@�r+zGMockTest.test_parent_propagation_with_autospec_attach_mock.<locals>.foorB)rArgrRrSz
mock.child)r	rZrrgrYr�r1rkrrCrDr)rr@rhrrr�1test_parent_propagation_with_autospec_attach_mock�sz:MockTest.test_parent_propagation_with_autospec_attach_mockc		s�tjj}|�dd�|�t�d��ztjd=�fdd��t���|�tjd�ddlm	}m
}m}m}||||g}x"|D]}|t
d	�}|�|t
�qzWWdQRXdS)
NcSsttjd|�S)Nr)rUr�r)rrrrr��r+z9MockTest.test_isinstance_under_settrace.<locals>.<lambda>zsys.modulesz
unittest.mockcs�S)Nr)�frameZeventr�)�tracerrr��sz6MockTest.test_isinstance_under_settrace.<locals>.tracer)r	rr
r)rJ)r�rrr�rr��modules�settrace�
unittest.mockr	rr
rrr~)	rZ	old_patchr	rr
rrGrr<r)r�r�test_isinstance_under_settrace�s	



z'MockTest.test_isinstance_under_settraceN)~rrrr.r>r?rHrMr]r_rbr�Z
skipUnlessr��platformrfrlrmrorsrurwryr{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�rrrrrrr	r
rrrrrrr r&r+r-r0r4r8r:r;r=r>rBrCrErFrGrIrLrMrNrOrVrWrXrYr\r_rfrirjrortrvrwr{r|r~r�r�r�r�r�r�r�r�r�r�r�rrrrr,.s�	)"






	7N
#
,(( 
	5	





r,�__main__)r�r6r�rkr�Zunittest.test.testmock.supportrrr�rrrrrr	r
rrr
rrLrrr*r�r,r�mainrrrr�<module>s84

R