Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/mock/tests/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/mock/tests/__pycache__/testmock.cpython-35.opt-1.pyc



�0�V&��@snddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZddlmZddlmZmZmZyeWnek
r�eZYnXGdd�de�ZGdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�dej�Z e!dkrjej"�dS)�N)	�call�DEFAULT�patch�sentinel�	MagicMock�Mock�NonCallableMock�NonCallableMagicMock�create_autospec)�	_CallList)�callable�is_instance�nextc@s:eZdZdd�Zdd�Zdd�ZeZdS)�ItercCstddddg�|_dS)N�this�is�an�iter)r�thing)�self�r�D/opt/alt/python35/lib/python3.5/site-packages/mock/tests/testmock.py�__init__!sz
Iter.__init__cCs|S)Nr)rrrr�__iter__$sz
Iter.__iter__cCs
t|j�S)N)rr)rrrrr'sz	Iter.nextN)�__name__�
__module__�__qualname__rrr�__next__rrrrr src@sIeZdZddd�Zeddd��Zeddd��ZdS)�	SomethingNcCsdS)Nr)r�a�b�c�drrr�meth.szSomething.methcCsdS)Nr)�clsrr r!r"rrr�cmeth1szSomething.cmethcCsdS)Nr)rr r!r"rrr�smeth5szSomething.smeth)rrrr#�classmethodr%�staticmethodr&rrrrr-s
rc@seZdZdS)�SubclassN)rrrrrrrr):sr)c@seZdZdZdZdS)�Thing��barN)rrr�	attribute�foorrrrr*>sr*c@sBeZdZdd�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+ej,e-j.dM�dNdO��Z/ej,e-j.dM�dPdQ��Z0dRdS�Z1dTdU�Z2dVdW�Z3dXdY�Z4dZd[�Z5d\d]�Z6d^d_�Z7d`da�Z8dbdc�Z9ddde�Z:dfdg�Z;dhdi�Z<djdk�Z=dldm�Z>dndo�Z?dpdq�Z@drds�ZAdtdu�ZBdvdw�ZCdxdy�ZDdzd{�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[ej\d�d���Z]d�S)��MockTestcCstd�dS)Nzfrom mock import *)�exec)rrrr�test_allFszMockTest.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 correctly�_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)r�mockrrr�test_constructorMs(	zMockTest.test_constructorcCs&tdd�}|j|jd�dS)Nr8z(return value in constructor not honoured)rr>r8)rrBrrr� test_return_value_in_constructoris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�namer.z'%s'rBr,z%s.barz%s.foo()z
%s.foo().bingz%s()z%s()()z%s()().foo.bar.baz().bing)r�assertIn�repr�idr,r.Zbing�baz)rrB�mocksrErrr�	test_repros $ # 
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�X�srL�specz
 spec='X' �spec_setz spec_set='X' rEr.z name='foo' )�objectrrFrGr<)rrLrBrrr�test_repr_with_specs$	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)�resultsrrrT�szside effect not used correctly�side_effectz#side effect in constructor not usedcSstS)N)rrrrrr[�sz.MockTest.test_side_effect.<locals>.side_effectr8)	rr[�assertRaisesrQ�assert_called_withr5r�
SideEffectZRETURN)rrBrTr[r)rZr�test_side_effect�s 			'zMockTest.test_side_effectcs�dddg��fdd�}dd�}t|�}dddg|_|j|�|�|�gdddgd�dddg�t|�}||_|j|�|�|�gdddgd	�dS)
NrUrVrXcs
�j�S)N)rYr)rZrrrT�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
r[r5)rrTr`rBr)rZr�test_autospec_side_effect�s'	'z"MockTest.test_autospec_side_effectcCs>dd�}t|�}td�|_|jtd|�dS)NcSsdS)Nrrrrrr`�sz7MockTest.test_autospec_side_effect_exception.<locals>.fzBazinga!)r
�
ValueErrorr[�assertRaisesRegex)rr`rBrrr�#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)	Nrr[zBoom!rUrVrWrXzjava exception not raised)rerZlangZRuntimeException�failr])rrerBrrr�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�	somethingrEZchild�parentrMzname 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)rrrZ
SomethingElserhr^r[r8�
reset_mockr5�
_mock_namer?r@r3r4r6r9r:r;�
mock_callsrA)rrirMrBrhr8rrr�test_reset_mock�sD			
	
zMockTest.test_reset_mockcCs t�}||_|j�dS)N)rr8rj)rrBrrr�test_reset_mock_recursion
s		z"MockTest.test_reset_mock_recursioncCstj�}|j�dS)N)rB�	mock_openrj)rrrrr�(test_reset_mock_on_mock_open_issue_18622s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 setrUzcall_count incoreectzcall_args not setz(call_args_list not initialised correctly�keyzincorrect return valuerVzcall_count incorrectzcall_args_list not set)rr7r
r8r5rjr�Argr4r6r9r:ZReturnValueZKeyArg)rrB�resultZret_valrrr�	test_calls4		
zMockTest.test_callcCs�t�}|�|tj�|dtj�|tjdtj�|j|jftjffdtjiftjfdtjifg�|j|jtjfdtjif�|j|jdk�dS)N�kwza long sequence)rrrrZKwargr5r:r9r3)rrBrrr�test_call_args_comparison:s	
z"MockTest.test_call_args_comparisoncCs�t�}|�|j�|jt|jd�|j�|jt|j�|ddddddd�|jddddddd�dS)NrUrVrXrrWr Znothing)rr]r\�AssertionErrorrj)rrBrrr�test_assert_called_withMs	

z MockTest.test_assert_called_withc
Cs�ddd�}td|�}|ddddd�|jddd�|jd	ddddd�|jt|jddddd�|jt��}|jd
d�WdQRXt|jd�r�|j|jjt�dS)
NcSsdS)Nr)rr r!r"rrrr`]sz9MockTest.test_assert_called_with_function_spec.<locals>.frMrUr rVr!rXr�e��	__cause__)	rr]r\rw�hasattr�	exception�assertIsInstancer{�	TypeError)rr`rB�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)NrUr rVr!rXr)r]r\rw)rB)rrr�_checkos
z<MockTest.test_assert_called_with_method_spec.<locals>._checkrM)rrr#r%r&)rr�rBr)rr�#test_assert_called_with_method_specns



z,MockTest.test_assert_called_with_method_speccs�t�����j���|jt�j��j�|jt�j��dddd��jdddd��j��dddd�|jt�fdd��dS)Nr.r,rIrVcs�jdddd�S)NZbobr,rIrV)�assert_called_once_withr)rBrr�<lambda>�sz7MockTest.test_assert_called_once_with.<locals>.<lambda>)rr�r\rwrj)rr)rBr�test_assert_called_once_with�s	


z%MockTest.test_assert_called_once_withc
Cs"ddd�}td|�}|ddddd�|jddd�|jd	ddddd�|jt|jddddd�|jt��}|jd
d�WdQRXt|jd�r�|j|jjt�|d
dd�|jt|jddd�|jt|jd
dd�dS)NcSsdS)Nr)rr r!r"rrrr`�sz>MockTest.test_assert_called_once_with_function_spec.<locals>.frMrUr rVr!rXrryrzr{��r+)	rr�r\rwr|r}r~r{r)rr`rBr�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 namerXzmethod returned wrong valuez!method didn't record being called)rrhr7r
r5r8r4)rrBrhrrr�#test_attribute_access_returns_mocks�s			z,MockTest.test_attribute_access_returns_mockscCsBt�}|j}|j|jdd�|j|j|d�dS)Nrhz attribute name not set correctlyz"attribute parent not set correctly)rrhr5rkr?)rrBrhrrr�(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)NrXrWr+Zcakerhz#method calls not recorded correctlyzsomething_else.something)r+)rX)r+)rrh�something_elserZCaker5r;)rrBrrr�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)Nrh�	different�xrUZsomeZmore)rh�r�)rhr�)r�)r�)rrhr5r;)rrBrrr� test_method_calls_compare_easily�s"	
	
	"%	z)MockTest.test_method_calls_compare_easilycCsaxZdgdfD]I}x@dD]8}t||i�}|j|jtdt|d�qWqWdS)NrhrMrNz-Mock object has no attribute 'something_else'r�)rh)rMrN)rrhrc�AttributeError�getattr)rrM�argrBrrr�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>.SomethingrXNcSsdS)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�rcr�r�)rB)rrr�test_attributess
z0MockTest.test_from_spec.<locals>.test_attributesrM)rOr)rrr�r)rr�test_from_specszMockTest.test_from_speccCset�}td|�}|j|�|��|j�|dddd�|jdddd�dS)N�wrapsrUrVrWrX)rr5rjr])r�realrBrrr�test_wraps_callss	
zMockTest.test_wraps_callscCsHt�}td|�}d|_|j|�d�|j|j�dS)Nr�rX)rr8r5r3r4)rr�rBrrr�,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)rrrrr-rrrr�Real3sr�r�cs�jS)N)rWr)rBrrr�:sz0MockTest.test_wraps_attributes.<locals>.<lambda>rUrVrWrX)	rOrr5r-r\r�ZassertNotEqualZfrogr])rr�r�rsr)rBr�test_wraps_attributes2s	zMockTest.test_wraps_attributescCsHtdt�}|jt|�tdtd��}|jt|�dS)Nr[r.)rr�r\)rrBrrr�test_exceptional_side_effectBsz%MockTest.test_exceptional_side_effectcCsHtdt�}|jt|�tdtd��}|jt|�dS)Nr[r.)r�KeyboardInterruptr\)rrBrrr� test_baseexceptional_side_effectJsz)MockTest.test_baseexceptional_side_effectcCs#t�}|jtd|j�dS)Nz
Not called)rrcrwr])rrBrrr�test_assert_called_with_messageRs	z(MockTest.test_assert_called_with_messagecCs)tdd�}|jtd|j�dS)NrEZgeoffreyz'Expected 'geoffrey' to be called once\.)rrcrwr�)rrBrrr�$test_assert_called_once_with_messageXs	z-MockTest.test_assert_called_once_with_messagecsEt��|jt�fdd��d�_|j�jd�dS)Ncs�jS)N)rr)rBrrr�asz'MockTest.test__name__.<locals>.<lambda>r.)rr\r�rr5)rr)rBr�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�rMr.rX)�listr�appendr]r\r�r�)rr�rBrrr�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)rrrrrrrrLrsrLrMrrN)rOrr~�assertIs�	__class__r5r)rrLrBrrr�test_spec_classqszMockTest.test_spec_classcslGdd�dt�}td|��d�_td|���fdd�}d�_|jt|�dS)Nc@seZdZdZdS)z8MockTest.test_setting_attribute_with_spec_set.<locals>.XrXN)rrrr�rrrrrL�srLrMr.rNcs
d�_dS)Nr.)r�r)rBrr�set_attr�sz?MockTest.test_setting_attribute_with_spec_set.<locals>.set_attr)rOrr�r�r\r�)rrLr�r)rBr�$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_copyz no old style classes in Python 3cs�Gdd�d�}td|��d�_|jt�fdd��td|���d�_|jt�fdd��dS)Nc@seZdZdZdS)z1MockTest.test_spec_old_style_classes.<locals>.Foo�N)rrrr,rrrr�Foo�sr�rMr+cs�jS)N)r.r)rBrrr��sz6MockTest.test_spec_old_style_classes.<locals>.<lambda>cs�jS)N)r.r)rBrrr��s)rr,r\r�)rr�r)rBr�test_spec_old_style_classes�s		z$MockTest.test_spec_old_style_classescs�Gdd�d�}td|��d�_|jt�fdd���fdd�}|jt|�td|���d�_|jt�fd	d���fd
d�}|jt|�dS)Nc@seZdZdZdS)z5MockTest.test_spec_set_old_style_classes.<locals>.Foor�N)rrrr,rrrrr��sr�rNr+cs�jS)N)r.r)rBrrr��sz:MockTest.test_spec_set_old_style_classes.<locals>.<lambda>cs
d�_dS)NrX)r.r)rBrr�_set�sz6MockTest.test_spec_set_old_style_classes.<locals>._setcs�jS)N)r.r)rBrrr��scs
d�_dS)NrX)r.r)rBrrr��s)rr,r\r�)rr�r�r)rBr�test_spec_set_old_style_classes�s		z(MockTest.test_spec_set_old_style_classescs�Gdd�dt�}|d|��|j�jd��fdd�}|jt|��fdd�}|jt|�dS)Nc@s7eZdZdd�Zdd�Zeee�ZdS)z8MockTest.test_subclass_with_properties.<locals>.SubClasscSsdS)NrXr)rrrr�_get�sz=MockTest.test_subclass_with_properties.<locals>.SubClass._getcSstd��dS)Nz
strange error)�	NameError)r�valuerrrr��sz=MockTest.test_subclass_with_properties.<locals>.SubClass._setN)rrrr�r��property�some_attributerrrr�SubClass�sr�rNrXcs
d�_dS)NrX)r�r)�srr�test�sz4MockTest.test_subclass_with_properties.<locals>.testcs
d�_dS)Nr,)r.r)r�rrr��s)rr5r�r\r�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�r]r\r)rrBr�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�dirr5rr rFr!r"r)rrB�attrs�
type_attrsrrr�test_dir�s	zMockTest.test_dircCs|tdtj�}tttj��}tt|��}|jt�||�d|_|jt|�jd�d�dS)NrMrX�versionrU)r�unittest�TestCaser�r�r5r��count)rrBZtestcase_attrsr�rrr�test_dir_from_spec�s	zMockTest.test_dir_from_specc
Csstjtdd�}|j�zBttt���}ttt��}|jt�||�Wd|j�XdS)NZ
FILTER_DIRF)	rrOrB�startr�r�rr5�stop)rZpatcherr�r�rrr�test_filter_dirs
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,r[zfoo.bar.return_value�!)	rr5r.r�KeyErrorr\r,r~Zconfigure_mock)rrBrSrrr�test_configure_mocks	
zMockTest.test_configure_mockc	Ospy|||�Wn(tj�d}|j||�YnX|jd|f�t|�}|j||�dS)NrUzException %r not raised)r��exc_infor~rf�strr5)rr}�message�funcrRrS�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 calledrU�2rXr,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)rVzfoo())rr�rwr]r.r�)rrB�expectedr�Z	assertersr#Zactualrrr�'test_assert_called_with_failure_message6sF	




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�rUrVrXrr�r r�z().foor.z
().foo.barz().foo.bar().bazrEr,zfoo.__int__za()z().foo.bar().baz().__int__)rUrVrX)rUrVrX)rUrVrX���)rr�rlr5r.r�r�dictr8r,rI�	call_listr�rr r!�__int__)rrBr�rSZ	last_callrrr�test_mock_callsmst		
"	"-""	

+(%%.(""zMockTest.test_mock_callscCs�Gdd�dt�}|�}|j|j|�|j|�|�Gdd�dt�}|�}|j|j|�|j|�|�dS)Nc@seZdZdS)z+MockTest.test_subclassing.<locals>.SubclassN)rrrrrrrr)�sr)c@seZdZdd�ZdS)z+MockTest.test_subclassing.<locals>.Subclassc[s
t|�S)N)r)rrSrrr�_get_child_mock�sz;MockTest.test_subclassing.<locals>.Subclass._get_child_mockN)rrrr�rrrrr)�s)rr~r.�assertNotIsInstance)rr)rBrrr�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)Nr:r;rl)r:r;rl)r�r~rr�r5)rB�namesrE�attr)rrr�assert_attrs�s
z-MockTest.test_arg_lists.<locals>.assert_attrsrUrVrrX)	rrrr	rrjr.r,rI)rrJr�rBr)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)NrUrrXrVr r�r)rV)rU)rV)rr5�lenr9r��zipr:)rrBrRrSZ
expected_listr�r9rrr�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)Nr[rUrVrXrr r!Zghi�g�h�ic@seZdZdS)z/MockTest.test_side_effect_iterator.<locals>.FooN)rrrrrrrr�
sr�rrrr)	rrr5r\�
StopIterationrrOr~r)rrBr�rrr�test_side_effect_iterators +++!z"MockTest.test_side_effect_iteratorcCs`t�}tdddg�|_|j|�|�|�gdddg�|jt|�|j}|j|ttg���dddg|_|j|�|�|�gdddg�|jt|�|j}|j|ttg���t�}||_|j|�|�|�|�gddd	d
g�|jt|�|j	|j|�dS)NrUrVrXrr r!rrrr)
rrr[r5r\r�r~r�rr�)rrBr[Z	this_iterrrr�!test_side_effect_setting_iterators"	+	+			!z*MockTest.test_side_effect_setting_iteratorcCs�x{ttfD]m}tdtdf}|d|�}|jt|�|j|�d�|jt|�|j|�d�q
WdS)NrXr+r[)rrrbr�r\r5)r�Klass�iterabler�rrr�$test_side_effect_iterator_exceptions.sz-MockTest.test_side_effect_iterator_exceptionscCsJtdd�}tdtg�|_|j|�|�gddg�dS)Nr8rVrU)rrrr[r5)rrBrrr�!test_side_effect_iterator_default8sz*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)NrUrVrrXr�r r+r��	any_orderTr�r.r�r��rXr�)r�rUrV)r�r)rUrV)rr�assert_has_callsr\rw)rrB�kallsZkallZ
kall_listsZ	kall_listrrr�test_assert_has_calls_any_order=s:	




$
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)NrUrVrrXr�r r+r�r.�rXr�)r	)rU)rUrVrX)rr.r,�extendZspamrIr�Zbamr�rWrrr��ranger�rr\rwr��reversed)	rZkalls1Zkalls2rJrBrr��stepZtheserrr�test_assert_has_callsis<%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"rrrr`�sz<MockTest.test_assert_has_calls_with_function_spec.<locals>.frMrUr rVr!rXr�r�r+r"r��
��r�rT)rUrVrX)r�r�r+)rrrr�r�r�r�)rrr�rr\rw)rr`rBZcallsrrr�(test_assert_has_calls_with_function_spec�s0
z1MockTest.test_assert_has_calls_with_function_speccCs�t�}|dd�|dd�|ddd�|jdd�|jdd�|jddd�|jt|j�|jt|jdd�|jt|jdd�dS)NrUrVrrXr r+r�)r�assert_any_callr\rw)rrBrrr�test_assert_any_call�s$	



	zMockTest.test_assert_any_callc
Cs+ddd�}td|�}|ddddd�|d	d
dddd
�|jddd�|jdddddd�|jd	d
dd
�|jdd	dd
dddd
�|jt|jddddd�|jt��}|jdd�WdQRXt|jd�r'|j|jjt�dS)NcSsdS)Nr)rr r!r"rrrr`�sz;MockTest.test_assert_any_call_with_function_spec.<locals>.frMrUr rVr!rXr�r�r+r"r�rryrzr{)	rrr\rwr|r}r~r{r)rr`rBr�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 rrrr`�sz3MockTest.test_mock_calls_create_autospec.<locals>.frUrVrXr�)rr`r
r5rlr)rr`�objZfuncsr�rrr�test_mock_calls_create_autospec�s			


z(MockTest.test_mock_calls_create_autospeccCs2tjt�dd�}|jdt|��dS)NrEZ
sweet_func)rBr
rOrFrG)rr�rrr�test_create_autospec_with_name�sz'MockTest.test_create_autospec_with_namecCsrt�}|jt��|j�WdQRX|jt��|j�WdQRXtdd�}|j�|j�dS)NZunsafeT)rr\r�Zassert_foo_callZassret_foo_call)rr�rrr�test_mock_unsafe�s	
zMockTest.test_mock_unsafec	CsHt�}|jj�|j�|jt��|jj�WdQRXdS)N)r�helloZassert_not_calledr\rw)rr�rrr�test_assert_not_calleds
	

zMockTest.test_assert_not_calledc	Cs_t�}|jt��|jj�WdQRX|j�|jj�|j�|jj�dS)N)rr\rwrZ
assert_called)rr�rrr�test_assert_calleds	


zMockTest.test_assert_calledcCsvt�}|jt��|jj�WdQRX|j�|jj�|j�|jt��|jj�WdQRXdS)N)rr\rwrZassert_called_once)rr�rrr�test_assert_called_onces	


z MockTest.test_assert_called_oncecCsEt�}|jdddd�d}|jt|jj�|�dS)NrErZdaddyZheroz call(daddy='hero', name='hello'))rrr5rGr9)rr��textrrr�test_sorted_call_signature!s	z#MockTest.test_sorted_call_signaturecCsstj�}tjdd�}t�}|j�|jdd�|j|jd|�|j|jd|�dS)N�rrrU)rr��indexrr5r;)rr!r�r�rrr�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>._OnerUN)rrrr�rrrr�_One2sr#c@seZdZdZdS)z)MockTest.test_mock_add_spec.<locals>._TworVN)rrrr�rrrr�_Two4sr$c@seZdZdZZZdS)z-MockTest.test_mock_add_spec.<locals>.AnythingZfourN)rrrr�r��threerrrr�Anything6sr&cs
|d��S)NrMr)�K)r&rrr�=sz-MockTest.test_mock_add_spec.<locals>.<lambda>cs
|d��S)NrNr)r')r&rrr�>srNTr�r�r%)rOrrrr	r�r�r�r�r�r%�
mock_add_specr\r�r��setattr)	rr#r$Zklassesr�rSrBZOneZTwor)r&r�test_mock_add_spec1s> 
	+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)rBrrr�tsz;MockTest.test_mock_add_spec_magic_methods.<locals>.<lambda>)
rr	r�r(rOr\rr�r8r5)rr�r)rBr� test_mock_add_spec_magic_methodsfs	

	
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)NrE)rrrr	r.r5r;rrlr,rI)rr�rBrrr�test_adding_child_mockws 	
	
	
zMockTest.test_adding_child_mockcCs\xUttfD]G}|�}t�|_|��|j|jt�t��g�q
WdS)N)rrr8r5rlr)rr�rBrrr�test_adding_return_value_mock�s
	
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�)rOrrr�r�r��attach_mockr�r�r5rlr)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)Nr8rXg@)
rrr��	__float__r��floatr5rlrr;)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)rBro�readr5)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)NrEZJLVztempfile.NamedTemporaryFilezTest 2 ErrorcSstj�jd�dS)NZasd)�tempfileZNamedTemporaryFile�writerrrr�attempt�sz.MockTest.test_mock_open_write.<locals>.attempt)	rBrorrr8r:�OSErrorr[r\)rZmock_namedtempZmock_filehandleZ
mock_writer;rrr�test_mock_open_write�s		zMockTest.test_mock_open_writecCsitjdd�}dd�|jj_|�j�}|�j�}|jd|�|jd|�dS)Nr3zfoo
barncWsdS)N�abcr)rRrrrr��sz8MockTest.test_mock_open_alter_readline.<locals>.<lambda>r>)rBror8�readliner[r5)rZmopen�first�secondrrr�test_mock_open_alter_readline�s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')
rrrGr8r�r5rjrr rF)rr�r�Z
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)NrEr.r,zname='mock.bar'rU)rrr	rr.r�r,rFrGrIr5rlrr;)r�classesr��Klass2r��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)NrEr.r8z
name='mock()')
rrr	rr.r�rFrGr.r5rlrr�)rrDr�rEr�rFrrr�test_attach_mock_return_values
	
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�r`)rrr	rr7r|r�r3r`r\r�r�)rrBrrr�test_attribute_deletionsz MockTest.test_attribute_deletioncCsQxJt�t�fD]6}|j|t�t|_|j|t�|jqWdS)N)rrr�r�r�r~r.)rrBrrr�test_class_assignables
	zMockTest.test_class_assignablecCs�x�ttttfD]�}|dddd�}|jddd�tj|�}tj|�}|jjddd�|j	|j
�|jt||��|j
|t�|jdt|��|j|jd�qWdS)NrEr.r-rXrUrVz
name="foo")rrr)r	r.�pickle�dumps�loadsr�r3r4r7r
r~r*rFrGr5r-)rr�rBr4�newrrr�test_pickle(szMockTest.test_pickleN)^rrrr1rCrDrKrPr_rardr�Z
skipUnlessr��platformrgrmrnrprtrvrxr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�ZskipIf�sixZPY3r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrrrrrrrr"r*r+r,r-r/r2r8r=rBrCrGrHrIrJZexpectedFailurerOrrrrr/Ds�	)"



!!

7N#
,(!
	5	
	r/�__main__)#r�rKr�r9rQZ	unittest2r�rBrrrrrrrr	r
Z	mock.mockrZmock.tests.supportrr
rZunicoder�r�rOrrr)r*r�r/r�mainrrrr�<module>s2@


������