Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/unittest/test/testmock/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/unittest/test/testmock/__pycache__/testmock.cpython-35.opt-1.pyc



��YfO��@s�ddlZddlZddlZddlZddlmZddlmZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZGdd�de�ZGdd�de�ZGd	d
�d
ej�Zedkr�ej�dS)�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/python35/lib64/python3.5/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	dd�Z
ej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�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_effectcCs>dd�}t|�}td�|_|jtd|�dS)NcSsdS)NrrrrrrZ�sz7MockTest.test_autospec_side_effect_exception.<locals>.fzBazinga!)r
�
ValueErrorrU�assertRaisesRegex)rrZrrrr�#test_autospec_side_effect_exception�sz,MockTest.test_autospec_side_effect_exception�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	|jd|id�|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
SomethingElserbrXrUr1�
reset_mockr.�
_mock_namer8r9r,r-r/r2r3r4�
mock_callsr:)rrcrGrrbr1rrr�test_reset_mock�sD			
	
zMockTest.test_reset_mockcCs t�}||_|j�dS)N)r	r1rd)rrrrr�test_reset_mock_recursion�s		z"MockTest.test_reset_mock_recursioncCstj�}|j�dS)N)r�	mock_openrd)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
tjfdtj
ifd�|j|jtjfiftjfdtj
ifgd�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.rdr�Argr-r/r2r3ZReturnValueZKeyArg)rr�resultZret_valrrr�	test_call�s4		
zMockTest.test_callcCs�t�}|�|tj�|dtj�|tjdtj�|j|jftjffdtjiftjfdtjifg�|j|jtjfdtjif�|j|jdk�dS)N�kwza long sequence)r	rrlZKwargr.r3r2r,)rrrrr�test_call_args_comparison s	
z"MockTest.test_call_args_comparisoncCs3tj�}|j||k�|j||k�|j|tj�k�|j|tj�k�|j|tjk�|j|tjk�|jtj|k�|jtj|k�tjtj��}tjtj�}|j||k�|j||k�|j||k�|j||k�dS)N)rrr0r,�ANYr)rZmmZcall1Zcall2rrr�test_calls_equal_with_any4sz"MockTest.test_calls_equal_with_anycCs�t�}|�|j�|jt|jd�|j�|jt|j�|ddddddd�|jddddddd�dS)NrOrPrRrrQr Znothing)r	rWrV�AssertionErrorrd)rrrrr�test_assert_called_withIs	

z MockTest.test_assert_called_withcCs*t�}|t��|jtj�dS)N)rrWrrq)r�mrrr�test_assert_called_with_anyXs	
z$MockTest.test_assert_called_with_anyc
Cs�ddd�}td|�}|ddddd�|jddd�|jd	ddddd�|jt|jddddd�|jt��}|jd
d�WdQRX|j|jjt�dS)NcSsdS)Nr)rr r!r"rrrrZ_sz9MockTest.test_assert_called_with_function_spec.<locals>.frGrOr rPr!rRr�e�)r	rWrVrs�assertIsInstance�	exception�	__cause__�	TypeError)rrZr�cmrrr�%test_assert_called_with_function_spec^sz.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)rWrVrs)r)rrr�_checkps
z<MockTest.test_assert_called_with_method_spec.<locals>._checkrG)r	rr#r%r&)rrrr)rr�#test_assert_called_with_method_specos



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>�sz7MockTest.test_assert_called_once_with.<locals>.<lambda>)r	r�rVrsrd)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�WdQRX|j|jjt�|dd
d�|jt|jddd�|jt|jdd
d�dS)NcSsdS)Nr)rr r!r"rrrrZ�sz>MockTest.test_assert_called_once_with_function_spec.<locals>.frGrOr rPr!rRrrwrx���)r	r�rVrsryrzr{r|)rrZrr}rrr�*test_assert_called_once_with_function_spec�s
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	rbr0rr.r1r-)rrrbrrr�#test_attribute_access_returns_mocks�s			z,MockTest.test_attribute_access_returns_mockscCsBt�}|j}|j|jdd�|j|j|d�dS)Nrbz attribute name not set correctlyz"attribute parent not set correctly)r	rbr.rer8)rrrbrrr�(test_attributes_have_name_and_parent_set�s		z1MockTest.test_attributes_have_name_and_parent_setcCs�t�}|jddd�|jjddtj�|j|jjdddtjifgd�|j|jdd	ddifdd
dtjifgd�dS)NrRrQr�Zcakerbz#method calls not recorded correctlyzsomething_else.something)r�)rR)r�)r	rb�something_elserZCaker.r4)rrrrr�test_method_calls_recorded�s	z#MockTest.test_method_calls_recordedcCs8t�}|j�|j|jdg�|j|jdfifg�t�}|jd�|j|jd	g�|j|jdd
ifg�t�}|jdd�|j|jdddifg�|j|jdfddifg�t�}|jddd�|j|jddddifg�dS)Nrb�	different�xrOZsomeZmore)rb�r�)rbr�)r�)r�)r	rbr.r4)rrrrr� test_method_calls_compare_easily�s"	
	
	"%	z)MockTest.test_method_calls_compare_easilycCsaxZdgdfD]I}x@dD]8}t||i�}|j|jtdt|d�qWqWdS)NrbrGrHz-Mock object has no attribute 'something_else'r�)rb)rGrH)r	rbr]�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�ysz,MockTest.test_from_spec.<locals>.Something.y)rrrr��
__something__r�rrrrrs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_attributess
z0MockTest.test_from_spec.<locals>.test_attributesrG)rIr	)rrr�r)rr�test_from_specszMockTest.test_from_speccCset�}td|�}|j|�|��|j�|dddd�|jdddd�dS)N�wrapsrOrPrQrR)r	r.rdrW)r�realrrrr�test_wraps_callss	
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_value(s
		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�Real3sr�r�cs�jS)N)rQr)rrrr�:sz0MockTest.test_wraps_attributes.<locals>.<lambda>rOrPrQrR)	rIr	r.r�rVr�ZassertNotEqualZfrogrW)rr�r�rmr)rr�test_wraps_attributes2s	zMockTest.test_wraps_attributescCsHtdt�}|jt|�tdtd��}|jt|�dS)NrUr>)r	r�rV)rrrrr�test_exceptional_side_effectBsz%MockTest.test_exceptional_side_effectcCsHtdt�}|jt|�tdtd��}|jt|�dS)NrUr>)r	�KeyboardInterruptrV)rrrrr� test_baseexceptional_side_effectJsz)MockTest.test_baseexceptional_side_effectcCs#t�}|jtd|j�dS)Nz
Not called)r	r]rsrW)rrrrr�test_assert_called_with_messageRs	z(MockTest.test_assert_called_with_messagecCs)tdd�}|jtd|j�dS)Nr=Zgeoffreyz'Expected 'geoffrey' to be called once\.)r	r]rsr�)rrrrr�$test_assert_called_once_with_messageXs	z-MockTest.test_assert_called_once_with_messagecsEt��|jt�fdd��d�_|j�jd�dS)Ncs�jS)N)rr)rrrr�asz'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�Subhsr�rGr>rR)�listr	�appendrWrVr�r�)rr�rrrr�test_spec_list_subclassgs

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)rrrrrrrrFrsrFrGr	rH)rIr	ry�assertIs�	__class__r.r)rrFrrrr�test_spec_classqszMockTest.test_spec_classcslGdd�dt�}td|��d�_td|���fdd�}d�_|jt|�dS)Nc@seZdZdZdS)z8MockTest.test_setting_attribute_with_spec_set.<locals>.XrRN)rrrr�rrrrrF�srFrGr>rHcs
d�_dS)Nr>)r�r)rrr�set_attr�sz?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_copy�s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�SubClass�s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_properties�sz&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�rWrVr|)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)�.0rurrr�
<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_dircCs�tdd�}|j|jd�tdd�}|j|jd�dtdddt�i}t|�}|jt|�|j|jj�d�|j|jt�t�}|j|�|jt|�|j|jj�d�|j|jt�dS)Nr>r?rUzfoo.bar.return_value�!)	r	r.r>r�KeyErrorrVr?ryZconfigure_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_inforyr`�strr.)rrz�message�funcrLrM�instance�msgrrr�assertRaisesWithMsgs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�rsrWr>r�)rr�expectedr�Z	assertersr#Zactualrrr�'test_assert_called_with_failure_messagesF	




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�rfr.r>r�r�dictr1r?rC�	call_listr�rr r!�__int__)rrr�rMZ	last_callrrr�test_mock_callsIst		
"	"-""	

+(%%.(""zMockTest.test_mock_callscCs�Gdd�dt�}|�}|j|j|�|j|�|�Gdd�dt�}|�}|j|j|�|j|�|�dS)Nc@seZdZdS)z+MockTest.test_subclassing.<locals>.SubclassN)rrrrrrr�Subclass�s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��s)r	ryr>�assertNotIsInstance)rr�rrrr�test_subclassing�s		zMockTest.test_subclassingcs�t�t�t�t�g}�fdd�}x�|D]�}||�t|�r�|�|dd�|dd�|j�||�|j�|jjddd�|jd�j�jd�|j�||�q7WdS)NcsZd}xM|D]E}t||�}�j|t��j|t��j|g�q
WdS)Nr3r4rf)r3r4rf)r�ryrr�r.)r�namesr=�attr)rrr�assert_attrs�s
z-MockTest.test_arg_lists.<locals>.assert_attrsrOrPrrR)	r	rr
r�callablerdr>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�
StopIterationrrIryr)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)NrRr�rU)r	rr\r�rVr.)r�Klass�iterablerurrr�$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�ryr�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_defaultsz*MockTest.test_side_effect_iterator_defaultcCs�t�}|dd�|dd�|dd�|dd�|dd�tdd�ddifdfddifddddifddifdfddifg}x$|D]}|j|gd	d
�q�WxTtdd�tdd�t�dddfD]%}|jt|j|gd	d
�q�Wtdd�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
�qXWdS)NrOrPrrRr�r r�r��	any_orderTr�r>r���rRr�)r�rOrP)r�r)rOrP)r	r�assert_has_callsrVrs)rr�kallsZkallZ
kall_listsZ	kall_listrrr�test_assert_has_calls_any_orders:	




$
4	!
''E
	z(MockTest.test_assert_has_calls_any_orderc		Cs3tdd�ddifdtdd�ddddifg}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]l}xcd
D][}||||�}|j|�t|�dkr�|jt|jtt|���q�Wq�Wq�WdS)NrOrPrrRr�r r�r�r>�rRr�)r)rO)rOrPrR)rr>r?�extendZspamrCr�Zbamr�rQr	rr��ranger�rrVrsr��reversed)	rZkalls1Zkalls2rDrrr��stepZtheserrr�test_assert_has_callsDs<%1



	

"

zMockTest.test_assert_has_callscCs�ddd�}td|�}|ddddd�|d	d
dddd
�|dddd�ddifdddd
ifdifg}|j|�|j|dd�|j|dd��|j|dd�dd�|j|dd��|j|dd�dd�tt|��}|jt��|j|�WdQRX|j|dd�|jt��|j|dd��WdQRX|j|dd�dd�|jt��|j|dd��WdQRX|j|dd�dd�dS)NcSsdS)Nr)rr r!r"rrrrZmsz<MockTest.test_assert_has_calls_with_function_spec.<locals>.frGrOr rPr!rRr�r�r�r"r�
��r�rT)rOrPrR)r�r�r�)r
rrr�r�r�r�)r	rr�r
rVrs)rrZrZcallsrrr�(test_assert_has_calls_with_function_specls0
z1MockTest.test_assert_has_calls_with_function_speccCs�t�}|dd�|dd�|ddd�|jdd�|jdd�|jddd�|jt|j�|jt|jdd�|jt|jdd�dS)NrOrPrrRr r�r�)r	�assert_any_callrVrs)rrrrr�test_assert_any_call�s$	



	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�WdQRX|j|jjt�dS)NcSsdS)Nr)rr r!r"rrrrZ�sz;MockTest.test_assert_any_call_with_function_spec.<locals>.frGrOr rPr!rRr�r�r�r"rrrwrx)r	rrVrsryrzr{r|)rrZrr}rrr�'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.rfr)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)rrurrr�test_create_autospec_with_name�sz'MockTest.test_create_autospec_with_namecCsrt�}|jt��|j�WdQRX|jt��|j�WdQRXtdd�}|j�|j�dS)NZunsafeT)r	rVr�Zassert_foo_callZassret_foo_call)rrurrr�test_mock_unsafe�s	
zMockTest.test_mock_unsafec	CsHt�}|jj�|j�|jt��|jj�WdQRXdS)N)r	�helloZassert_not_calledrVrs)rrurrr�test_assert_not_called�s
	

zMockTest.test_assert_not_calledcCsEt�}|jdddd�d}|jt|jj�|�dS)Nr=rZdaddyZheroz call(daddy='hero', name='hello'))r	rr.rAr2)rru�textrrr�test_sorted_call_signature�s	z#MockTest.test_sorted_call_signaturecCsstj�}tjdd�}t�}|j�|jdd�|j|jd|�|j|jd|�dS)N�rrrO)rr��indexr	r.r4)rr!r�rurrr�test_override_tuple_methods�s	
z$MockTest.test_override_tuple_methodsc	
sGdd�dt�}Gdd�dt�}Gdd�dt��ttttg}xLt|�D]>}|j|�fdd��|j|�fd	d��qaWxr|D]j}xat�td
d�fD]G}|�}|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�|j||�|jt
t|d�|j	|jt
t|d�d
|kr2|jt
t|dd�q2Wq
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r c@seZdZdZZZdS)z-MockTest.test_mock_add_spec.<locals>.AnythingZfourN)rrrr�r��threerrrr�Anything�sr"cs
|d��S)NrGr)�K)r"rrr�sz-MockTest.test_mock_add_spec.<locals>.<lambda>cs
|d��S)NrHr)r#)r"rrr�srHTr�r�r!)rIr	rr
rr�r�r�r�r�r!�
mock_add_specrVr�r��setattr)	rrr Zklassesr�rMrZOneZTwor)r"r�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�9sz;MockTest.test_mock_add_spec_magic_methods.<locals>.<lambda>)
rrr�r$rIrVr|r�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.r4rrfr?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.rfr)rr�rrrr�test_adding_return_value_mockTs
	
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.rfr)rr�ZmanagerZp1Zp2Zmock_oneZmock_tworrr�test_manager_mock]s	

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.rfrr4)rr�rurrr�test_magic_methods_mock_callsss	

%z&MockTest.test_magic_methods_mock_callscCsVtjdd�}|d�}|j�}|d�}|j�}|j||�dS)N�	read_data�dataza-namezanother-name)rri�readr.)rZmocked_open�f1Zf1_data�f2Zf2_datarrr� test_mock_open_reuse_issue_21750~sz)MockTest.test_mock_open_reuse_issue_21750c
Csvtjtjdd��}tjd|��B|j}|j}td�|_dd�}|jt|�WdQRXdS)Nr=ZJLVztempfile.NamedTemporaryFilezTest 2 ErrorcSstj�jd�dS)NZasd)�tempfileZNamedTemporaryFile�writerrrr�attempt�sz.MockTest.test_mock_open_write.<locals>.attempt)	rrirrr1r6�OSErrorrUrV)rZmock_namedtempZmock_filehandleZ
mock_writer7rrr�test_mock_open_write�s		zMockTest.test_mock_open_writecCsitjdd�}dd�|jj_|�j�}|�j�}|jd|�|jd|�dS)Nr/zfoo
barncWsdS)N�abcr)rLrrrr��sz8MockTest.test_mock_open_alter_readline.<locals>.<lambda>r:)rrir1�readlinerUr.)rZmopen�first�secondrrr�test_mock_open_alter_readline�sz&MockTest.test_mock_open_alter_readlinecCs�tjdd�}|d�}|j�|jd|j��|jd|j��|jd|j��|jd|j��|jg|j��|jg|j��dS)Nr/r>r?r�)rrir1r.r;�	readlines)rZ_openr�rrr�test_mock_open_after_eof�s
z!MockTest.test_mock_open_after_eofcCswxpttfD]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.rdrr r@)rr�ruZ
original_reprrrr�test_mock_parents�s,		
	
	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
r*r�r?r@rArCr.rfrr4)r�classesr��Klass2ru�m2rrr�test_attach_mock�s

	"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
r*r�r@rAr>r.rfrr�)rrBr�rCrurDrrr�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)NrurZ)r	rrr
r0�hasattrrur,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�ryr>)rrrrr�test_class_assignable�s
	zMockTest.test_class_assignableN)Xrrrr+r;r<rErJrYr[r^r�Z
skipUnlessr��platformrargrhrjrnrprrrtrvr~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�rrrrrrrrrrrr&r'r(r)r+r.r4r9r>r@rArErFrHrIrrrrr)*s�	)"





7N#
,(!	5	
r)�__main__)r�r�r5r�Zunittest.test.testmock.supportrrZ
unittest.mockrrrrrr	r
rrr
rIrrr�r)r�mainrrrr�<module>s F

������