Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/unittest/test/testmock/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/unittest/test/testmock/__pycache__/testmock.cpython-34.pyo

�
j f���@s�ddlZddlZddlZddlZddlmZddlmZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZGdd�de�ZGdd�de�ZGd	d
�d
ej�Zedkr�ej�ndS)�N)�is_instance)�mock)
�call�DEFAULT�patch�sentinel�	MagicMock�Mock�NonCallableMock�NonCallableMagicMock�	_CallList�create_autospecc@s:eZdZdd�Zdd�Zdd�ZeZdS)�ItercCstddddg�|_dS)N�this�is�an�iter)r�thing)�self�r�D/opt/alt/python34/lib64/python3.4/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__rrrrrsrc@sIeZdZddd�Zeddd��Zeddd��ZdS)�	SomethingNcCsdS)Nr)r�a�b�c�drrr�methszSomething.methcCsdS)Nr)�clsrr r!r"rrr�cmeth!szSomething.cmethcCsdS)Nr)rr r!r"rrr�smeth%szSomething.smeth)rrrr#�classmethodr%�staticmethodr&rrrrrs
rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
jdej
kd�dd��Zdd�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�S)��MockTestcCstd�dS)Nzfrom unittest.mock import *)�exec)rrrr�test_all,szMockTest.test_allcCs�t�}|j|jd�|j|jdd�|jt|jt�d�|j|jdd�|j|j	gd�|j|j
gd�|jd|jd	�|j
|jd
�|j
|jd�|j|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_constructor3s(	zMockTest.test_constructorcCs&tdd�}|j|jd�dS)Nr1z(return value in constructor not honoured)r	r7r1)rrrrr� test_return_value_in_constructorOsz)MockTest.test_return_value_in_constructorcCsPtdd�}|jdt|��|jdt|�t|��t�dftdd�dfg}x�|D]�\}}|jd|t|j��|jd|t|j���|jd|t|j�j��|jd	|t|���|jd
|t|����|jd|t|��jjj�j��qpWdS)N�name�fooz'%s'r�barz%s.barz%s.foo()z
%s.foo().bingz%s()z%s()()z%s()().foo.bar.baz().bing)r	�assertIn�repr�idr?r>Zbing�baz)rr�mocksr=rrr�	test_reprUs $ # 
zMockTest.test_reprcCsaGdd�dt�}td|�}|jdt|��td|��}|jdt|��td|�}|jdt|��td|��}|jdt|��td|dd�}|jdt|��|jd	t|��tdd�}|jdt|��t�}|jdt|��tddg�}|jdt|��dS)
Nc@seZdZdS)z'MockTest.test_repr_with_spec.<locals>.XN)rrrrrrr�XfsrF�specz
 spec='X' �spec_setz spec_set='X' r=r>z name='foo' )�objectr	r@rAr5)rrFrrrr�test_repr_with_speces$	zMockTest.test_repr_with_speccst�}dd�}||_|jt|dddd�|jdddd�dddg��fdd�}||_|j|�|�|�gdddgd�td	tj�}|j|jtjd
�dd�}td	|d
tj�}|j|�tj�dS)Nc_std��dS)NZkablooie)�SystemError)�args�kwargsrrr�effect�sz)MockTest.test_side_effect.<locals>.effect���fish�cs
�j�S)N)�popr)�resultsrrrN�szside effect not used correctly�side_effectz#side effect in constructor not usedcSstS)N)rrrrrrU�sz.MockTest.test_side_effect.<locals>.side_effectr1)	r	rU�assertRaisesrK�assert_called_withr.r�
SideEffectZRETURN)rrrNrUr)rTr�test_side_effect�s 			'zMockTest.test_side_effectcs�dddg��fdd�}dd�}t|�}dddg|_|j|�|�|�gdddgd�dddg�t|�}||_|j|�|�|�gdddgd	�dS)
NrOrPrRcs
�j�S)N)rSr)rTrrrN�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)r
rUr.)rrNrZrr)rTr�test_autospec_side_effect�s'	'z"MockTest.test_autospec_side_effect�javaz This test only applies to Jythonc
Cs�ddl}td|jjd��}y|dddd�Wn|jjk
rXYnX|jd�|jdddd�dS)	NrrUzBoom!rOrPrQrRzjava exception not raised)r\r	ZlangZRuntimeException�failrW)rr\rrrr�test_java_exception_side_effect�s
z(MockTest.test_java_exception_side_effectcCs�t�}dg}tddd|d|�}|tjdtj�|j}|j�tj|_|j}|�|j�|j	|j
dd�|j	|j|d�|j	|j|d�|j
|jd	�|j	|jd
d�|j	|jdd�|j	|jgd
�|j	|jgd|jgf�|j	|jg�|j	|jtjd�|j	|j|d�|j
|jd�|j	|ji|d6d�|j	|j|d�|j
|jjd�dS)N�	somethingr=Zchild�parentrGzname 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_rXrUr1�
reset_mockr.�
_mock_namer8r9r,r-r/r2r3r4�
mock_callsr:)rr`rGrr_r1rrr�test_reset_mock�sD			
	
zMockTest.test_reset_mockcCs t�}||_|j�dS)N)r	r1ra)rrrrr�test_reset_mock_recursion�s		z"MockTest.test_reset_mock_recursioncCstj�}|j�dS)N)r�	mock_openra)rrrrr�(test_reset_mock_on_mock_open_issue_18622�sz1MockTest.test_reset_mock_on_mock_open_issue_18622cCs�t�}|jt|jt�d�|�}|j|�|d�|j�|tj�}|j|jd�|j|j	dd�|j|j
tjfifd�|j|jtjfifgd�tj|_|tjdtj
�}|j|tjd	�|j|j	d
d�|j|j
tjfitj
d6fd�|j|jtjfiftjfitj
d6fgd�dS)
Nz%Default return_value should be a Mockz'different result from consecutive callszcalled not setrOzcall_count incoreectzcall_args not setz(call_args_list not initialised correctly�keyzincorrect return valuerPzcall_count incorrectzcall_args_list not set)r	r0rr1r.rar�Argr-r/r2r3ZReturnValueZKeyArg)rr�resultZret_valrrr�	test_call�s4		
zMockTest.test_callc	Cs�t�}|�|tj�|dtj�|tjdtj�|j|jftjffitjd6ftjfitjd6fg�|j|jtjfitjd6f�|j|jdk�dS)N�kwza long sequence)r	rriZKwargr.r3r2r,)rrrrr�test_call_args_comparisons	
 z"MockTest.test_call_args_comparisoncCs�t�}|�|j�|jt|jd�|j�|jt|j�|ddddddd�|jddddddd�dS)NrOrPrRrrQr Znothing)r	rWrV�AssertionErrorra)rrrrr�test_assert_called_with*s	

z MockTest.test_assert_called_withc
Cs�ddd�}td|�}|ddddd�|jddd�|jd	ddddd�|jt|jddddd�|jt��}|jd
d�WdQX|j|jjt�dS)NcSsdS)Nr)rr r!r"rrrrZ:sz9MockTest.test_assert_called_with_function_spec.<locals>.frGrOr rPr!rRr�e�)r	rWrVrn�assertIsInstance�	exception�	__cause__�	TypeError)rrZr�cmrrr�%test_assert_called_with_function_spec9sz.MockTest.test_assert_called_with_function_speccs��fdd�}tdt�j�}||�tdtj�}||�tdt�j�}||�tdtj�}||�tdt�j�}||�dS)Ncsk|ddddd�|jddd�|jdddddd��jt|jddddd�dS)NrOr rPr!rRr)rWrVrn)r)rrr�_checkKs
z<MockTest.test_assert_called_with_method_spec.<locals>._checkrG)r	rr#r%r&)rrxrr)rr�#test_assert_called_with_method_specJs



z,MockTest.test_assert_called_with_method_speccs�t�����j���|jt�j��j�|jt�j��dddd��jdddd��j��dddd�|jt�fdd��dS)Nr>r?rCrPcs�jdddd�S)NZbobr?rCrP)�assert_called_once_withr)rrr�<lambda>rsz7MockTest.test_assert_called_once_with.<locals>.<lambda>)r	rzrVrnra)rr)rr�test_assert_called_once_with^s	


z%MockTest.test_assert_called_once_withcCsddd�}td|�}|ddddd�|jddd�|jd	ddddd�|jt|jddddd�|jt��}|jd
d�WdQX|j|jjt�|dd
d�|jt|jddd�|jt|jdd
d�dS)NcSsdS)Nr)rr r!r"rrrrZwsz>MockTest.test_assert_called_once_with_function_spec.<locals>.frGrOr rPr!rRrrprq���)r	rzrVrnrrrsrtru)rrZrrvrrr�*test_assert_called_once_with_function_specvs
z3MockTest.test_assert_called_once_with_function_speccCs�t�}|j}|jt|t�d�|j|j|d�t�}d|j_|j|j�dd�|j|jjd�dS)Nzattribute isn't a mockz+different attributes returned for same namerRzmethod returned wrong valuez!method didn't record being called)r	r_r0rr.r1r-)rrr_rrr�#test_attribute_access_returns_mocks�s			z,MockTest.test_attribute_access_returns_mockscCsBt�}|j}|j|jdd�|j|j|d�dS)Nr_z attribute name not set correctlyz"attribute parent not set correctly)r	r_r.rbr8)rrr_rrr�(test_attributes_have_name_and_parent_set�s		z1MockTest.test_attributes_have_name_and_parent_setcCs�t�}|jddd�|jjddtj�|j|jjdditjd6fgd�|j|jdd	idd6fdd
itjd6fgd�dS)NrRrQrZcaker_z#method calls not recorded correctlyzsomething_else.something)r)rR)r)r	r_�something_elserZCaker.r4)rrrrr�test_method_calls_recorded�s	z#MockTest.test_method_calls_recordedcCs;t�}|j�|j|jdg�|j|jdfifg�t�}|jd�|j|jd	g�|j|jdd
ifg�t�}|jdd�|j|jdidd6fg�|j|jdfidd6fg�t�}|jddd�|j|jddidd6fg�dS)Nr_�	different�xrOZsomeZmore)�	something�r�)r�r�)r�)r�)r	r_r.r4)rrrrr� test_method_calls_compare_easily�s"	
	
	#&	z)MockTest.test_method_calls_compare_easilycCsbx[dgdfD]J}xAdD]9}ti||6�}|j|jtdt|d�qWqWdS)Nr_rGrHz-Mock object has no attribute 'something_else'r�)z	something)zspeczspec_set)r	r_�assertRaisesRegex�AttributeError�getattr)rrG�argrrrr�test_only_allowed_methods_exist�s
z(MockTest.test_only_allowed_methods_existcsUGdd�dt�}�fdd�}|td|��|td|���dS)Nc@s(eZdZdZdZdd�ZdS)z*MockTest.test_from_spec.<locals>.SomethingrRNcSsdS)Nr)rrrr�y�sz,MockTest.test_from_spec.<locals>.Something.y)rrrr��
__something__r�rrrrr�srcsK|j|j|j�jtdt|d��jtdt|d�dS)Nz Mock object has no attribute 'z'�zz)Mock object has no attribute '__foobar__'Z
__foobar__)r�r�r�r�r�r�)r)rrr�test_attributes�s
z0MockTest.test_from_spec.<locals>.test_attributesrG)rIr	)rrr�r)rr�test_from_spec�szMockTest.test_from_speccCset�}td|�}|j|�|��|j�|dddd�|jdddd�dS)N�wrapsrOrPrQrR)r	r.rarW)r�realrrrr�test_wraps_calls�s	
zMockTest.test_wraps_callscCsHt�}td|�}d|_|j|�d�|j|j�dS)Nr�rR)r	r1r.r,r-)rr�rrrr�,test_wraps_call_with_nondefault_return_values
		z5MockTest.test_wraps_call_with_nondefault_return_valuecs�Gdd�dt�}|�}td|��|j�j�|j��|jt�fdd��|j�j|j��jjdddd	�}|jjjdddd	�|j||jj��dS)
Nc@seZdZe�ZdS)z,MockTest.test_wraps_attributes.<locals>.RealN)rrrr	�	attributerrrr�Realsr�r�cs�jS)N)rQr)rrrr{sz0MockTest.test_wraps_attributes.<locals>.<lambda>rOrPrQrR)	rIr	r.r�rVr�ZassertNotEqualZfrogrW)rr�r�rjr)rr�test_wraps_attributes
s	zMockTest.test_wraps_attributescCsHtdt�}|jt|�tdtd��}|jt|�dS)NrUr>)r	r�rV)rrrrr�test_exceptional_side_effectsz%MockTest.test_exceptional_side_effectcCsHtdt�}|jt|�tdtd��}|jt|�dS)NrUr>)r	�KeyboardInterruptrV)rrrrr� test_baseexceptional_side_effect%sz)MockTest.test_baseexceptional_side_effectcCs#t�}|jtd|j�dS)Nz
Not called)r	r�rnrW)rrrrr�test_assert_called_with_message-s	z(MockTest.test_assert_called_with_messagecCs)tdd�}|jtd|j�dS)Nr=Zgeoffreyz'Expected 'geoffrey' to be called once\.)r	r�rnrz)rrrrr�$test_assert_called_once_with_message3s	z-MockTest.test_assert_called_once_with_messagecsEt��|jt�fdd��d�_|j�jd�dS)Ncs�jS)N)rr)rrrr{<sz'MockTest.test__name__.<locals>.<lambda>r>)r	rVr�rr.)rr)rr�test__name__:s		zMockTest.test__name__cCseGdd�dt�}td|dg��}|jd�|jjd�|jtt|d�dS)Nc@seZdZdS)z-MockTest.test_spec_list_subclass.<locals>.SubN)rrrrrrr�SubCsr�rGr>rR)�listr	�appendrWrVr�r�)rr�rrrr�test_spec_list_subclassBs

z MockTest.test_spec_list_subclasscCs�Gdd�dt�}td|�}|j||�td|��}|j||�|j|j|�|jt�jjd�td|�}|j||�td|��}|j||�dS)Nc@seZdZdS)z#MockTest.test_spec_class.<locals>.XN)rrrrrrrrFMsrFrGr	rH)rIr	rr�assertIs�	__class__r.r)rrFrrrr�test_spec_classLszMockTest.test_spec_classcslGdd�dt�}td|��d�_td|���fdd�}d�_|jt|�dS)Nc@seZdZdZdS)z8MockTest.test_setting_attribute_with_spec_set.<locals>.XrRN)rrrr�rrrrrFasrFrGr>rHcs
d�_dS)Nr>)r�r)rrr�set_attrhsz?MockTest.test_setting_attribute_with_spec_set.<locals>.set_attr)rIr	r�r�rVr�)rrFr�r)rr�$test_setting_attribute_with_spec_set`s		z-MockTest.test_setting_attribute_with_spec_setcCsFtj�}|jtj|�tjtd��tjt��dS)Nge��A)�sys�getrecursionlimit�
addCleanup�setrecursionlimit�int�copyr	)rZcurrentrrr�	test_copyoszMockTest.test_copycs�Gdd�dt�}|d|��|j�jd��fdd�}|jt|��fdd�}|jt|�dS)Nc@s7eZdZdd�Zdd�Zeee�ZdS)z8MockTest.test_subclass_with_properties.<locals>.SubClasscSsdS)NrRr)rrrr�_get{sz=MockTest.test_subclass_with_properties.<locals>.SubClass._getcSstd��dS)Nz
strange error)�	NameError)r�valuerrr�_set}sz=MockTest.test_subclass_with_properties.<locals>.SubClass._setN)rrrr�r��property�some_attributerrrr�SubClasszsr�rHrRcs
d�_dS)NrR)r�r)�srr�test�sz4MockTest.test_subclass_with_properties.<locals>.testcs
d�_dS)Nr?)r>r)r�rrr��s)r	r.r�rVr�r�)rr�r�r)r�r�test_subclass_with_propertiesysz&MockTest.test_subclass_with_propertiescCsUt�}dd�}|t|�_|d�|jd�|jt|dd�dS)NcSs
|j|�S)N)Z
_mock_call)rrrrr�__call__�sz,MockTest.test_setting_call.<locals>.__call__�one�two)r	�typer�rWrVru)rrr�rrr�test_setting_call�s	

zMockTest.test_setting_callcCs�t�}tt|��}tdd�tt�D��}|jt�||�|j|jf|jdt|��|jdt|��d|_|_|jdt|��|jdt|��dd�|_	|jd	t|��dS)
NcSs%g|]}|jd�s|�qS)�_)�
startswith)�.0�mrrr�
<listcomp>�s	z%MockTest.test_dir.<locals>.<listcomp>rr r!r"cSs
tg�S)N)r)r�rrrr{�sz#MockTest.test_dir.<locals>.<lambda>r)
r	�set�dirr.rr r@r!r"r)rr�attrs�
type_attrsrrr�test_dir�s	zMockTest.test_dircCs|tdtj�}tttj��}tt|��}|jt�||�d|_|jt|�jd�d�dS)NrGrR�versionrO)r	�unittest�TestCaser�r�r.r��count)rrZtestcase_attrsr�rrr�test_dir_from_spec�s	zMockTest.test_dir_from_specc
Csstjtdd�}|j�zBttt���}ttt��}|jt�||�Wd|j�XdS)NZ
FILTER_DIRF)	rrIr�startr�r�r	r.�stop)rZpatcherr�r�rrr�test_filter_dir�s
zMockTest.test_filter_dircCstdd�}|j|jd�tdd�}|j|jd�itd6dd6t�d6}t|�}|jt|�|j|jj�d�|j|jt�t�}|j|�|jt|�|j|jj�d�|j|jt�dS)Nr>r?rU�!zfoo.bar.return_value)	r	r.r>r�KeyErrorrVr?rrZconfigure_mock)rrrMrrr�test_configure_mock�s
	
zMockTest.test_configure_mockc	Ospy|||�Wn(tj�d}|j||�YnX|jd|f�t|�}|j||�dS)NrOzException %r not raised)r��exc_inforrr]�strr.)rrs�message�funcrLrM�instance�msgrrr�assertRaisesWithMsg�szMockTest.assertRaisesWithMsgc
Cs�t�}d}d}|jt||f|jddddd�|jddddd�|jj|jjg}xL|D]D}d}d	}d
}|jt|||f|ddddd�qyWxC|D];}d}d}d
}|jt|||f|dd�q�WxF|D]>}d}d}d
}|jt|||f|dd
d�qWx=|D]5}d}d}d
}|jt|||f|�qWWdS)Nzmock(1, '2', 3, bar='foo')zExpected call: %s
Not calledrO�2rRr?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)rPzfoo())r
r�rnrWr>rz)rr�expectedr�Z	assertersr#Zactualrrr�'test_assert_called_with_failure_message�sF	




z0MockTest.test_assert_called_with_failure_messagec	Cst�}|j|jgkd�t�}|�dfifg}|j|j|�|j�|jtj��|j|j|�|j|jjdfifg�t�}|�jddddddd	�dfifd
dtdddd	�fg}|j|j|�|j|jjjddtdddd	�fg�|j|jjddtdddd	�fg�t�}|�jj	�j
�dfifdfifd
fifg}|j|j|�|j|�jtjj	�j
�j��xt�tdd�fD]�}t|�}t|j�dfifg}|j|j|�t|�}|j
��dfifdfifg}|j|j|�|j|j
�jt�g�t|�}|d�d�d�|j|jtd�d�d�j��|j|�jtd�d�j��|j|��jtd�j��t|�}|d�d�d�j
jjd�|j|jtd�d�d�j
jjd�j��|j|�jtd�d�j
jjd�j��|j|��jtd�j
jjd�j��t|�}t|�jj	�j
��dfif}|j|jd|�|j|�jtjj	�j
�j�j��|j|�jj	�jtj
�j�j��|j|�jj	�j
jt�j�j��qWdS)NT�rOrPrRrr}r r~z().foor>z
().foo.barz().foo.bar().bazr=r?zfoo.__int__za()z().foo.bar().baz().__int__)rOrPrR)rOrPrR)rOrPrR���)rr�rcr.r>r�r�dictr1r?rC�	call_listr�rr r!�__int__)rrr�rMZ	last_callrrr�test_mock_calls$st		
"	"-""	

+(%%.(""zMockTest.test_mock_callscCs�Gdd�dt�}|�}|j|j|�|j|�|�Gdd�dt�}|�}|j|j|�|j|�|�dS)Nc@seZdZdS)z+MockTest.test_subclassing.<locals>.SubclassN)rrrrrrr�Subclassssr�c@seZdZdd�ZdS)z+MockTest.test_subclassing.<locals>.Subclassc[s
t|�S)N)r	)rrMrrr�_get_child_mock{sz;MockTest.test_subclassing.<locals>.Subclass._get_child_mockN)rrrr�rrrrr�zs)r	rrr>�assertNotIsInstance)rr�rrrr�test_subclassingrs		zMockTest.test_subclassingcs�t�t�t�t�g}�fdd�}x�|D]�}||�t|�r�|�|dd�|dd�|j�||�n|j�|jjddd�|jd�j�jd�|j�||�q7WdS)NcsZd}xM|D]E}t||�}�j|t��j|t��j|g�q
WdS)Nr3r4rc)zcall_args_listzmethod_callsz
mock_calls)r�rrrr�r.)r�namesr=�attr)rrr�assert_attrs�s
z-MockTest.test_arg_lists.<locals>.assert_attrsrOrPrrR)	r	rr
r�callablerar>r?rC)rrDr�rr)rr�test_arg_lists�s$







zMockTest.test_arg_listscCst�}|ddd�|ddd�|jt|j�d�|j\}}|j|d�|j|tdd��d	tdd�fd
tdd�fg}xft||j�D]R\}}|jt|�d�|j|d|d�|j|d|d�q�WdS)NrOrrRrPr r}r)rP)rO)rP)r	r.�lenr2r��zipr3)rrrLrMZ
expected_listr�r2rrr�test_call_args_two_tuple�s	*z!MockTest.test_call_args_two_tuplecCs�tdtdddg��}|j|�|�|�gdddg�|jt|�tddddg�}|j|�|�|�gdddg�|jt|�tdd�}|j|�|�|�gd	d
dg�|jt|�Gdd
�d
t�}td|�}|j|�|�tdt��}|j|�|�|�|�gddddg�|jt|�dS)NrUrOrPrRrr r!Zghi�g�h�ic@seZdZdS)z/MockTest.test_side_effect_iterator.<locals>.FooN)rrrrrrr�Foo�sr�rrrr)	r	rr.rV�
StopIterationrrIrrr)rrr�rrr�test_side_effect_iterator�s +++!z"MockTest.test_side_effect_iteratorcCs�x{ttfD]m}tdtdf}|d|�}|jt|�|j|�d�|jt|�|j|�d�q
WdS)NrRrrU)r	r�
ValueErrorr�rVr.)r�Klass�iterabler�rrr�$test_side_effect_iterator_exceptions�sz-MockTest.test_side_effect_iterator_exceptionscCs`t�}tdddg�|_|j|�|�|�gdddg�|jt|�|j}|j|ttg���dddg|_|j|�|�|�gdddg�|jt|�|j}|j|ttg���t�}||_|j|�|�|�|�gddd	d
g�|jt|�|j	|j|�dS)NrOrPrRrr r!rrrr)
r	rrUr.rVr�rrr�rr�)rrrUZ	this_iterrrr�!test_side_effect_setting_iterator�s"	+	+			!z*MockTest.test_side_effect_setting_iteratorcCsJtdd�}tdtg�|_|j|�|�gddg�dS)Nr1rPrO)r	rrrUr.)rrrrr�!test_side_effect_iterator_default�sz*MockTest.test_side_effect_iterator_defaultcCs�t�}|dd�|dd�|dd�|dd�|dd�tdd�idd6fdfidd6fddidd6fddifdfidd6fg}x$|D]}|j|gd	d
�q�WxTtdd�tdd�t�dddfD]%}|jt|j|gd	d
�qWtdd�tdd�gtdd�tdd�gtdd�tdd�gg}x!|D]}|j|d	d
�q�Wtdd�tdd�tdd�gtdd�tdd�gtdd�tdd�td
d�gtdd�tdd�tdd�tdd�tdd�gg}x*|D]"}|jt|j|d	d
�q\WdS)NrOrPrrRr}r rr��	any_orderTr�r>r~��rRr})r��rOrP)r�r)rOrP)r	r�assert_has_callsrVrn)rr�kallsZkallZ
kall_listsZ	kall_listrrr�test_assert_has_calls_any_order�s:	




%
4	!
''E
	z(MockTest.test_assert_has_calls_any_orderc		Cs8tdd�idd6fdtdd�ddidd6fg}tj�tjd�g}|jtj�jdd�j��|jtjt�d	i�j	dg�j��g}xqt
�t�fD]]}|dd�|dd�|dd�|dd�|ddd�|j||f�q�Wt
�}|j�|jd�|j�jdd�|jt�d	i�j	dg�|j||f�x�|D]�\}}x�t
t|��D]o}xfd
D]^}||||�}|j|�t|�dkr�|jt|jtt|���q�q�Wq�Wq�WdS)NrOrPrRrr}r rr�r>�rRr})r)rO)rOrPrR)rr>r?�extendZspamrCr�Zbamr�rQr	rr��ranger�rrVrnr��reversed)	rZkalls1Zkalls2rDrrr��stepZtheserrr�test_assert_has_callss<%1



	

"

zMockTest.test_assert_has_callscCs�ddd�}td|�}|ddddd�|d	d
dddd
�|dddd�ddifddid
d6fdifg}|j|�|j|dd�|j|dd��|j|dd�dd�|j|dd��|j|dd�dd�tt|��}|jt��|j|�WdQX|j|dd�|jt��|j|dd��WdQX|j|dd�dd�|jt��|j|dd��WdQX|j|dd�dd�dS)NcSsdS)Nr)rr r!r"rrrrZHsz<MockTest.test_assert_has_calls_with_function_spec.<locals>.frGrOr rPr!rRr}r~rr"r��
��r�r�T)rOrPrR)r}r~r)r
rrr�r�r�r�)r	rr�rrVrn)rrZrZcallsrrr�(test_assert_has_calls_with_function_specGs0
z1MockTest.test_assert_has_calls_with_function_speccCs�t�}|dd�|dd�|ddd�|jdd�|jdd�|jddd�|jt|j�|jt|jdd�|jt|jdd�dS)NrOrPrrRr rr})r	�assert_any_callrVrn)rrrrr�test_assert_any_callhs$	



	zMockTest.test_assert_any_callc
Csddd�}td|�}|ddddd�|d	d
dddd
�|jddd�|jdddddd�|jd	d
dd
�|jdd	dd
dddd
�|jt|jddddd�|jt��}|jdd�WdQX|j|jjt�dS)NcSsdS)Nr)rr r!r"rrrrZ�sz;MockTest.test_assert_any_call_with_function_spec.<locals>.frGrOr rPr!rRr}r~rr"r�rrprq)r	rrVrnrrrsrtru)rrZrrvrrr�'test_assert_any_call_with_function_spec�s"z0MockTest.test_assert_any_call_with_function_speccCs�dd�}t�}||_t|�t|�jg}xS|D]K}|dd�|dd�|j|jtdd�tdd�g�q@WdS)NcSsdS)Nr)rr rrrrZ�sz3MockTest.test_mock_calls_create_autospec.<locals>.frOrPrRr})rrZr
r.rcr)rrZ�objZfuncsr�rrr�test_mock_calls_create_autospec�s			


z(MockTest.test_mock_calls_create_autospeccCs2tjt�dd�}|jdt|��dS)Nr=Z
sweet_func)rr
rIr@rA)rr�rrr�test_create_autospec_with_name�sz'MockTest.test_create_autospec_with_namec	
s"Gdd�dt�}Gdd�dt�}Gdd�dt��ttttg}xLt|�D]>}|j|�fdd��|j|�fd	d��qaWxx|D]p}xgt�td
d�fD]M}|�}|j|j	|j
fx%||fdgd
gfgD]\}}x�t�td
d�fD]�}|j||�|j|jt
t|d
�|jt
t|d�d
|kr�|jt
t|dd�n|j||�|jt
t|d�|j	|jt
t|d�d
|kr2|jt
t|dd�q2q2Wq
Wq�Wq�WdS)Nc@seZdZdZdS)z)MockTest.test_mock_add_spec.<locals>._OnerON)rrrr�rrrr�_One�src@seZdZdZdS)z)MockTest.test_mock_add_spec.<locals>._TworPN)rrrr�rrrr�_Two�src@seZdZdZZZdS)z-MockTest.test_mock_add_spec.<locals>.AnythingZfourN)rrrr�r��threerrrr�Anything�srcs
|d��S)NrGr)�K)rrrr{�sz-MockTest.test_mock_add_spec.<locals>.<lambda>cs
|d��S)NrHr)r)rrrr{�srHTr�r�r)rIr	rr
rr�r�r�r�r�r�
mock_add_specrVr�r��setattr)	rrrZklassesr�rMrZOneZTwor)rr�test_mock_add_spec�s> 
	+zMockTest.test_mock_add_speccs�x�ttfD]�}|��t���jt�|jtt��|���dd�j_�jt�|j	t��d�|jt�fdd��q
WdS)Nr>r}cs�dS)Nr>rr)rrrr{�sz;MockTest.test_mock_add_spec_magic_methods.<locals>.<lambda>)
rrr�rrIrVrur�r1r.)rr�r)rr� test_mock_add_spec_magic_methods�s	

	
z)MockTest.test_mock_add_spec_magic_methodscCsxttttfD]�}|�}t�|_|j�|j|jtj�g�|j|jtj�g�|�}tdd�|_	|j	�|j|jg�|j|jg�|�}t��|_
|j
�|j|jg�|j|jg�qWdS)Nr=)r
r	rrr>r.r4rrcr?rC)rr�rrrr�test_adding_child_mock�s 	
	
	
zMockTest.test_adding_child_mockcCs\xUttfD]G}|�}t�|_|��|j|jt�t��g�q
WdS)N)r	rr1r.rcr)rr�rrrr�test_adding_return_value_mocks
	
z&MockTest.test_adding_return_value_mockcCs�Gdd�dt�}t�}tj|d�}tj|d�}|j�}|j|j�|j�}|j|j�|j|d�|j|d�|j�|j�|j	|j
tj�tj�g�dS)Nc@seZdZdZdZdS)z'MockTest.test_manager_mock.<locals>.Foor�r�N)rrrr�r�rrrrr�sr�r�r�)rIr	rr�r�r��attach_mockr�r�r.rcr)rr�ZmanagerZp1Zp2Zmock_oneZmock_tworrr�test_manager_mocks	

zMockTest.test_manager_mockcCs�x�ttfD]}|�}tdd�|_tdd�|_t|�t|�|j|jtj�tj�g�|j|j	g�q
WdS)Nr1rRg@)
r	rr��	__float__r��floatr.rcrr4)rr�r�rrr�test_magic_methods_mock_calls*s	

%z&MockTest.test_magic_methods_mock_callscCsVtjdd�}|d�}|j�}|d�}|j�}|j||�dS)N�	read_data�dataza-namezanother-name)rrf�readr.)rZmocked_open�f1Zf1_data�f2Zf2_datarrr� test_mock_open_reuse_issue_217505sz)MockTest.test_mock_open_reuse_issue_21750c
Csutjtjdd��}tjd|��B|j}|j}td�|_dd�}|jt|�WdQXdS)Nr=ZJLVztempfile.NamedTemporaryFilezTest 2 ErrorcSstj�jd�dS)NZasd)�tempfileZNamedTemporaryFile�writerrrr�attemptDsz.MockTest.test_mock_open_write.<locals>.attempt)	rrfrrr1r+�OSErrorrUrV)rZmock_namedtempZmock_filehandleZ
mock_writer,rrr�test_mock_open_write=s		zMockTest.test_mock_open_writecCsitjdd�}dd�|jj_|�j�}|�j�}|jd|�|jd|�dS)Nr$zfoo
barncWsdS)N�abcr)rLrrrr{Jsz8MockTest.test_mock_open_alter_readline.<locals>.<lambda>r/)rrfr1�readlinerUr.)rZmopen�first�secondrrr�test_mock_open_alter_readlineHsz&MockTest.test_mock_open_alter_readlinecCswxpttfD]b}|�}t|�}||_|j|�|�|jt|�|�|j�|j|�|�|jt|�|�|�}|j|_|j	dt|j��|j	dt|j��|j�|j	dt|j��|j	dt|j��|�}t|�}|�|_||j_|jt|�|�|jt|j��|�q
WdS)Nz
name='mock.a')
r	rrAr1r�r.rarr r@)rr�r�Z
original_reprrrr�test_mock_parentsPs,		
	
	zMockTest.test_mock_parentscCs�ttttf}x�|D]�}x�|D]�}|�}|dd�}|j|d�|j|j|�|jdt|��|jj	d�|j
|jtjj	d�g�|j
|j
tjj	d�g�q&WqWdS)Nr=r>r?zname='mock.bar'rO)r	rrr
rr�r?r@rArCr.rcrr4)r�classesr��Klass2r��m2rrr�test_attach_mockms

	"zMockTest.test_attach_mockcCs�ttttf}x�ttfD]�}x�|D]�}|�}|dd�}|j|d�|j|�|�|jdt|��|j�|j	|j
t�j�j��q,WqWdS)Nr=r>r1z
name='mock()')
r	rrr
rr�r@rAr>r.rcrr�)rr5r�r6r�r7rrr�test_attach_mock_return_value~s
	
z&MockTest.test_attach_mock_return_valuecCs�x�t�t�t�t�fD]j}|jt|d��|`|jt|d��|`|jt|d��|j	t
t|d�qWdS)Nr�rZ)r	rrr
r0�hasattrr�r,rZrVr�r�)rrrrr�test_attribute_deletion�sz MockTest.test_attribute_deletioncCsQxJt�t�fD]6}|j|t�t|_|j|t�|jqWdS)N)r	rr�r�r�rrr>)rrrrr�test_class_assignable�s
	zMockTest.test_class_assignableN)Prrrr+r;r<rErJrYr[r�Z
skipUnlessr��platformr^rdrergrkrmrorwryr|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�rr	r
rrrrrrrrr r#r)r.r3r4r8r9r;r<rrrrr)*s�)"





7N#
,(!5	
r)�__main__)r�r�r*r�Zunittest.test.testmock.supportrrZ
unittest.mockrrrrrr	r
rrr
rIrrr�r)r�mainrrrr�<module>s F

�����