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



0V&@snddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZddlmZddlmZmZmZyeWnek
reZYnXGdddeZGdddeZGd	d
d
eZGdddeZGd
ddejZ e!dkrjej"dS)N)	callDEFAULTpatchsentinel	MagicMockMockNonCallableMockNonCallableMagicMockcreate_autospec)	_CallList)callableis_instancenextc@s:eZdZddZddZddZeZdS)ItercCstddddg|_dS)Nthisisaniter)rthing)selfr/testmock.py__init__!sz
Iter.__init__cCs|S)Nr)rrrr__iter__$sz
Iter.__iter__cCs
t|jS)N)rr)rrrrr'sz	Iter.nextN)__name__
__module____qualname__rrr__next__rrrrr src@sIeZdZdddZedddZedddZdS)	SomethingNcCsdS)Nr)rabcdrrrmeth.szSomething.methcCsdS)Nr)clsrr r!r"rrrcmeth1szSomething.cmethcCsdS)Nr)rr r!r"rrrsmeth5szSomething.smeth)rrrr#classmethodr%staticmethodr&rrrrr-s
rc@seZdZdS)SubclassN)rrrrrrrr):sr)c@seZdZdZdZdS)ThingbarN)rrr	attributefoorrrrr*>sr*c@sBeZdZddZddZddZddZd	d
ZddZd
dZ	ddZ
ejde
jkdddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Z d7d8Z!d9d:Z"d;d<Z#d=d>Z$d?d@Z%dAdBZ&dCdDZ'dEdFZ(dGdHZ)dIdJZ*dKdLZ+ej,e-j.dMdNdOZ/ej,e-j.dMdPdQZ0dRdSZ1dTdUZ2dVdWZ3dXdYZ4dZd[Z5d\d]Z6d^d_Z7d`daZ8dbdcZ9dddeZ:dfdgZ;dhdiZ<djdkZ=dldmZ>dndoZ?dpdqZ@drdsZAdtduZBdvdwZCdxdyZDdzd{ZEd|d}ZFd~dZGddZHddZIddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWddZXddZYddZZddZ[ej\ddZ]dS)MockTestcCstddS)Nzfrom mock import *)exec)rrrrtest_allFszMockTest.test_allcCst}|j|jd|j|jdd|jt|jtd|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)rassertFalsecalledassertEqual
call_count
assertTruer
return_value	call_argscall_args_listmethod_callsassertNotIn__dict__assertIsNone_mock_parent
_mock_methods_mock_children)rmockrrrtest_constructorMs(	zMockTest.test_constructorcCs&tdd}|j|jddS)Nr7z(return value in constructor not honoured)rr=r7)rrArrr test_return_value_in_constructorisz)MockTest.test_return_value_in_constructorcCsPtdd}|jdt||jdt|t|tdftdddfg}x|D]\}}|jd|t|j|jd|t|j|jd|t|jj|jd	|t||jd
|t||jd|t|jjjjqpWdS)Nnamer.z'%s'rAr,z%s.barz%s.foo()z
%s.foo().bingz%s()z%s()()z%s()().foo.bar.baz().bing)rassertInrepridr,r.Zbingbaz)rrAmocksrDrrr	test_repros $ # 
zMockTest.test_reprcCsaGdddt}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)rrrrrrrXsrKspecz
 spec='X' spec_setz spec_set='X' rDr.z name='foo' )objectrrErFr;)rrKrArrrtest_repr_with_specs$	zMockTest.test_repr_with_speccst}dd}||_|jt|dddd|jdddddddgfdd}||_|j|||gdddgdtd	tj}|j|jtjd
dd}td	|d
tj}|j|tjdS)Nc_stddS)NZkablooie)SystemError)argskwargsrrreffectsz)MockTest.test_side_effect.<locals>.effectfishcs
jS)N)popr)resultsrrrSszside effect not used correctlyside_effectz#side effect in constructor not usedcSstS)N)rrrrrrZsz.MockTest.test_side_effect.<locals>.side_effectr7)	rrZassertRaisesrPassert_called_withr4r
SideEffectZRETURN)rrArSrZr)rYrtest_side_effects 			'zMockTest.test_side_effectcsdddgfdd}dd}t|}dddg|_|j|||gdddgddddgt|}||_|j|||gdddgd	dS)
NrTrUrWcs
jS)N)rXr)rYrrrSsz2MockTest.test_autospec_side_effect.<locals>.effectcSsdS)Nrrrrrfsz-MockTest.test_autospec_side_effect.<locals>.fz1side effect not used correctly in create_autospecz'callable side effect not used correctly)r
rZr4)rrSr_rAr)rYrtest_autospec_side_effects'	'z"MockTest.test_autospec_side_effectcCs>dd}t|}td|_|jtd|dS)NcSsdS)Nrrrrrr_sz7MockTest.test_autospec_side_effect_exception.<locals>.fzBazinga!)r

ValueErrorrZassertRaisesRegex)rr_rArrr#test_autospec_side_effect_exceptionsz,MockTest.test_autospec_side_effect_exceptionjavaz This test only applies to Jythonc
Csddl}td|jjd}y|ddddWn|jjk
rXYnX|jd|jdddddS)	NrrZzBoom!rTrUrVrWzjava exception not raised)rdrZlangZRuntimeExceptionfailr\)rrdrArrrtest_java_exception_side_effects
z(MockTest.test_java_exception_side_effectcCst}dg}tddd|d|}|tjdtj|j}|jtj|_|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
|jjddS)N	somethingrDZchildparentrLzname 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
SomethingElsergr]rZr7
reset_mockr4
_mock_namer>r?r2r3r5r8r9r:
mock_callsr@)rrhrLrArgr7rrrtest_reset_mocksD			
	
zMockTest.test_reset_mockcCs t}||_|jdS)N)rr7ri)rrArrrtest_reset_mock_recursion
s		z"MockTest.test_reset_mock_recursioncCstj}|jdS)N)rA	mock_openri)rrrrr(test_reset_mock_on_mock_open_issue_18622sz1MockTest.test_reset_mock_on_mock_open_issue_18622cCst}|jt|jtd|}|j||d|j|tj}|j|jd|j|j	dd|j|j
tjfifd|j|jtjfifgdtj|_|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 setrTzcall_count incoreectzcall_args not setz(call_args_list not initialised correctlykeyzincorrect return valuerUzcall_count incorrectzcall_args_list not set)rr6r
r7r4rirArgr3r5r8r9ZReturnValueZKeyArg)rrAresultZret_valrrr	test_calls4		
zMockTest.test_callcCst}||tj|dtj|tjdtj|j|jftjffdtjiftjfdtjifg|j|jtjfdtjif|j|jdkdS)Nkwza long sequence)rrrqZKwargr4r9r8r2)rrArrrtest_call_args_comparison:s	
z"MockTest.test_call_args_comparisoncCst}||j|jt|jd|j|jt|j|ddddddd|jddddddddS)NrTrUrWrrVr Znothing)rr\r[AssertionErrorri)rrArrrtest_assert_called_withMs	

z MockTest.test_assert_called_withc
Csddd}td|}|ddddd|jddd|jd	ddddd|jt|jddddd|jt}|jd
dWdQRXt|jdr|j|jjtdS)
NcSsdS)Nr)rr r!r"rrrr_]sz9MockTest.test_assert_called_with_function_spec.<locals>.frLrTr rUr!rWre	__cause__)	rr\r[rvhasattr	exceptionassertIsInstancerz	TypeError)rr_rAcmrrr%test_assert_called_with_function_spec\sz.MockTest.test_assert_called_with_function_speccsfdd}tdtj}||tdtj}||tdtj}||tdtj}||tdtj}||dS)Ncsk|ddddd|jddd|jddddddjt|jddddddS)NrTr rUr!rWr)r\r[rv)rA)rrr_checkos
z<MockTest.test_assert_called_with_method_spec.<locals>._checkrL)rrr#r%r&)rrrAr)rr#test_assert_called_with_method_specns



z,MockTest.test_assert_called_with_method_speccstj|jtjj|jtjddddjddddjdddd|jtfdddS)Nr.r,rHrUcsjddddS)NZbobr,rHrU)assert_called_once_withr)rArr<lambda>sz7MockTest.test_assert_called_once_with.<locals>.<lambda>)rrr[rvri)rr)rArtest_assert_called_once_withs	


z%MockTest.test_assert_called_once_withc
Cs"ddd}td|}|ddddd|jddd|jd	ddddd|jt|jddddd|jt}|jd
dWdQRXt|jdr|j|jjt|d
dd|jt|jddd|jt|jd
dddS)NcSsdS)Nr)rr r!r"rrrr_sz>MockTest.test_assert_called_once_with_function_spec.<locals>.frLrTr rUr!rWrrxryrzr+)	rrr[rvr{r|r}rzr~)rr_rArrrr*test_assert_called_once_with_function_specs 
z3MockTest.test_assert_called_once_with_function_speccCst}|j}|jt|td|j|j|dt}d|j_|j|jdd|j|jjddS)Nzattribute isn't a mockz+different attributes returned for same namerWzmethod returned wrong valuez!method didn't record being called)rrgr6r
r4r7r3)rrArgrrr#test_attribute_access_returns_mockss			z,MockTest.test_attribute_access_returns_mockscCsBt}|j}|j|jdd|j|j|ddS)Nrgz attribute name not set correctlyz"attribute parent not set correctly)rrgr4rjr>)rrArgrrr(test_attributes_have_name_and_parent_sets		z1MockTest.test_attributes_have_name_and_parent_setcCst}|jddd|jjddtj|j|jjdddtjifgd|j|jdd	ddifdd
dtjifgddS)NrWrVr+Zcakergz#method calls not recorded correctlyzsomething_else.something)r+)rW)r+)rrgsomething_elserZCaker4r:)rrArrrtest_method_calls_recordeds	z#MockTest.test_method_calls_recordedcCs8t}|j|j|jdg|j|jdfifgt}|jd|j|jd	g|j|jdd
ifgt}|jdd|j|jdddifg|j|jdfddifgt}|jddd|j|jddddifgdS)Nrg	differentxrTZsomeZmore)	somethingr)rr)r)r)rrgr4r:)rrArrr test_method_calls_compare_easilys"	
	
	"%	z)MockTest.test_method_calls_compare_easilycCsaxZdgdfD]I}x@dD]8}t||i}|j|jtdt|dqWqWdS)NrgrLrMz-Mock object has no attribute 'something_else'r)z	something)zspeczspec_set)rrgrbAttributeErrorgetattr)rrLargrArrrtest_only_allowed_methods_exists
z(MockTest.test_only_allowed_methods_existcsUGdddt}fdd}|td||td|dS)Nc@s(eZdZdZdZddZdS)z*MockTest.test_from_spec.<locals>.SomethingrWNcSsdS)Nr)rrrrysz,MockTest.test_from_spec.<locals>.Something.y)rrrr
__something__rrrrrrsrcsK|j|j|jjtdt|djtdt|ddS)Nz Mock object has no attribute 'z'zz)Mock object has no attribute '__foobar__'Z
__foobar__)rrrrbrr)rA)rrrtest_attributess
z0MockTest.test_from_spec.<locals>.test_attributesrL)rNr)rrrr)rrtest_from_specszMockTest.test_from_speccCset}td|}|j|||j|dddd|jdddddS)NwrapsrTrUrVrW)rr4rir\)rrealrArrrtest_wraps_callss	
zMockTest.test_wraps_callscCsHt}td|}d|_|j|d|j|jdS)NrrW)rr7r4r2r3)rrrArrr,test_wraps_call_with_nondefault_return_value(s
		z5MockTest.test_wraps_call_with_nondefault_return_valuecsGdddt}|}td||jj|j|jtfdd|jj|jjjdddd	}|jjjdddd	|j||jjdS)
Nc@seZdZeZdS)z,MockTest.test_wraps_attributes.<locals>.RealN)rrrrr-rrrrReal3srrcsjS)N)rVr)rArrr:sz0MockTest.test_wraps_attributes.<locals>.<lambda>rTrUrVrW)	rNrr4r-r[rZassertNotEqualZfrogr\)rrrrrr)rArtest_wraps_attributes2s	zMockTest.test_wraps_attributescCsHtdt}|jt|tdtd}|jt|dS)NrZr.)rrr[)rrArrrtest_exceptional_side_effectBsz%MockTest.test_exceptional_side_effectcCsHtdt}|jt|tdtd}|jt|dS)NrZr.)rKeyboardInterruptr[)rrArrr test_baseexceptional_side_effectJsz)MockTest.test_baseexceptional_side_effectcCs#t}|jtd|jdS)Nz
Not called)rrbrvr\)rrArrrtest_assert_called_with_messageRs	z(MockTest.test_assert_called_with_messagecCs)tdd}|jtd|jdS)NrDZgeoffreyz'Expected 'geoffrey' to be called once\.)rrbrvr)rrArrr$test_assert_called_once_with_messageXs	z-MockTest.test_assert_called_once_with_messagecsEt|jtfddd_|jjddS)NcsjS)N)rr)rArrrasz'MockTest.test__name__.<locals>.<lambda>r.)rr[rrr4)rr)rArtest__name___s		zMockTest.test__name__cCseGdddt}td|dg}|jd|jjd|jtt|ddS)Nc@seZdZdS)z-MockTest.test_spec_list_subclass.<locals>.SubN)rrrrrrrSubhsrrLr.rW)listrappendr\r[rr)rrrArrrtest_spec_list_subclassgs

z MockTest.test_spec_list_subclasscCsGdddt}td|}|j||td|}|j|||j|j||jtjjdtd|}|j||td|}|j||dS)Nc@seZdZdS)z#MockTest.test_spec_class.<locals>.XN)rrrrrrrrKrsrKrLrrM)rNrr}assertIs	__class__r4r)rrKrArrrtest_spec_classqszMockTest.test_spec_classcslGdddt}td|d_td|fdd}d_|jt|dS)Nc@seZdZdZdS)z8MockTest.test_setting_attribute_with_spec_set.<locals>.XrWN)rrrrrrrrrKsrKrLr.rMcs
d_dS)Nr.)rr)rArrset_attrsz?MockTest.test_setting_attribute_with_spec_set.<locals>.set_attr)rNrrrr[r)rrKrr)rAr$test_setting_attribute_with_spec_sets		z-MockTest.test_setting_attribute_with_spec_setcCsFtj}|jtj|tjtdtjtdS)NgeA)sysgetrecursionlimit
addCleanupsetrecursionlimitintcopyr)rcurrentrrr	test_copyszMockTest.test_copyz no old style classes in Python 3csGddd}td|d_|jtfddtd|d_|jtfdddS)Nc@seZdZdZdS)z1MockTest.test_spec_old_style_classes.<locals>.FooN)rrrr,rrrrFoosrrLr+csjS)N)r.r)rArrrsz6MockTest.test_spec_old_style_classes.<locals>.<lambda>csjS)N)r.r)rArrrs)rr,r[r)rrr)rArtest_spec_old_style_classess		z$MockTest.test_spec_old_style_classescsGddd}td|d_|jtfddfdd}|jt|td|d_|jtfd	dfd
d}|jt|dS)Nc@seZdZdZdS)z5MockTest.test_spec_set_old_style_classes.<locals>.FoorN)rrrr,rrrrrsrrMr+csjS)N)r.r)rArrrsz:MockTest.test_spec_set_old_style_classes.<locals>.<lambda>cs
d_dS)NrW)r.r)rArr_setsz6MockTest.test_spec_set_old_style_classes.<locals>._setcsjS)N)r.r)rArrrscs
d_dS)NrW)r.r)rArrrs)rr,r[r)rrrr)rArtest_spec_set_old_style_classess		z(MockTest.test_spec_set_old_style_classescsGdddt}|d||jjdfdd}|jt|fdd}|jt|dS)Nc@s7eZdZddZddZeeeZdS)z8MockTest.test_subclass_with_properties.<locals>.SubClasscSsdS)NrWr)rrrr_getsz=MockTest.test_subclass_with_properties.<locals>.SubClass._getcSstddS)Nz
strange error)	NameError)rvaluerrrrsz=MockTest.test_subclass_with_properties.<locals>.SubClass._setN)rrrrrpropertysome_attributerrrrSubClasssrrMrWcs
d_dS)NrW)rr)srrtestsz4MockTest.test_subclass_with_properties.<locals>.testcs
d_dS)Nr,)r.r)rrrrs)rr4rr[rr)rrrr)rrtest_subclass_with_propertiessz&MockTest.test_subclass_with_propertiescCsUt}dd}|t|_|d|jd|jt|dddS)NcSs
|j|S)N)Z
_mock_call)rrrrr__call__sz,MockTest.test_setting_call.<locals>.__call__onetwo)rtyperr\r[r~)rrArrrrtest_setting_calls	

zMockTest.test_setting_callcCst}tt|}tddttD}|jt|||j|jf|jdt||jdt|d|_|_|jdt||jdt|dd|_	|jd	t|dS)
NcSs%g|]}|jds|qS)_)
startswith).0mrrr
<listcomp>s	z%MockTest.test_dir.<locals>.<listcomp>rr r!r"cSs
tgS)N)r)rrrrrsz#MockTest.test_dir.<locals>.<lambda>r)
rsetdirr4rr rEr!r"r)rrAattrs
type_attrsrrrtest_dirs	zMockTest.test_dircCs|tdtj}tttj}tt|}|jt||d|_|jt|jdddS)NrLrWversionrT)runittestTestCaserrr4rcount)rrAZtestcase_attrsrrrrtest_dir_from_specs	zMockTest.test_dir_from_specc
Csstjtdd}|jzBttt}ttt}|jt||Wd|jXdS)NZ
FILTER_DIRF)	rrNrAstartrrrr4stop)rZpatcherrrrrrtest_filter_dirs
zMockTest.test_filter_dircCstdd}|j|jdtdd}|j|jddtdddti}t|}|jt||j|jjd|j|jtt}|j||jt||j|jjd|j|jtdS)Nr.r,rZzfoo.bar.return_value!)	rr4r.rKeyErrorr[r,r}Zconfigure_mock)rrArRrrrtest_configure_mocks	
zMockTest.test_configure_mockc	Ospy|||Wn(tjd}|j||YnX|jd|ft|}|j||dS)NrTzException %r not raised)rexc_infor}restrr4)rr|messagefuncrQrRinstancemsgrrrassertRaisesWithMsg(szMockTest.assertRaisesWithMsgc
Cst}d}d}|jt||f|jddddd|jddddd|jj|jjg}xL|D]D}d}d	}d
}|jt|||f|dddddqyWxC|D];}d}d}d
}|jt|||f|ddqWxF|D]>}d}d}d
}|jt|||f|dd
dqWx=|D]5}d}d}d
}|jt|||f|qWWdS)Nzmock(1, '2', 3, bar='foo')zExpected call: %s
Not calledrT2rWr,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)rUzfoo())rrrvr\r.r)rrAexpectedrZ	assertersr#actualrrr'test_assert_called_with_failure_message6sF	




z0MockTest.test_assert_called_with_failure_messagec	Cst}|j|jgkdt}|dfifg}|j|j||j|jtj|j|j||j|jjdfifgt}|jddddddd	dfifd
dtdddd	fg}|j|j||j|jjjddtdddd	fg|j|jjddtdddd	fgt}|jj	j
dfifdfifd
fifg}|j|j||j|jtjj	j
jxttddfD]}t|}t|jdfifg}|j|j|t|}|j
dfifdfifg}|j|j||j|j
jtgt|}|ddd|j|jtdddj|j|jtddj|j|jtdjt|}|dddj
jjd|j|jtdddj
jjdj|j|jtddj
jjdj|j|jtdj
jjdjt|}t|jj	j
dfif}|j|jd||j|jtjj	j
jj|j|jj	jtj
jj|j|jj	j
jtjjqWdS)NTrTrUrWrrr rz().foor.z
().foo.barz().foo.bar().bazrDr,zfoo.__int__za()z().foo.bar().baz().__int__)rTrUrW)rTrUrW)rTrUrW)rrrkr4r.rrdictr7r,rH	call_listrrr r!__int__)rrArrRZ	last_callrrrtest_mock_callsmst		
"	"-""	

+(%%.(""zMockTest.test_mock_callscCsGdddt}|}|j|j||j||Gdddt}|}|j|j||j||dS)Nc@seZdZdS)z+MockTest.test_subclassing.<locals>.SubclassN)rrrrrrrr)sr)c@seZdZddZdS)z+MockTest.test_subclassing.<locals>.Subclassc[s
t|S)N)r)rrRrrr_get_child_mocksz;MockTest.test_subclassing.<locals>.Subclass._get_child_mockN)rrrrrrrrr)s)rr}r.assertNotIsInstance)rr)rArrrtest_subclassings		zMockTest.test_subclassingcsttttg}fdd}x|D]}||t|r||dd|dd|j|||j|jjddd|jdjjd|j||q7WdS)NcsZd}xM|D]E}t||}j|tj|tj|gq
WdS)Nr9r:rk)zcall_args_listzmethod_callsz
mock_calls)rr}rrr4)rAnamesrDattr)rrrassert_attrss
z-MockTest.test_arg_lists.<locals>.assert_attrsrTrUrrW)	rrrr	rrir.r,rH)rrIrrAr)rrtest_arg_listss$







zMockTest.test_arg_listscCst}|ddd|ddd|jt|jd|j\}}|j|d|j|tddd	tddfd
tddfg}xft||jD]R\}}|jt|d|j|d|d|j|d|dqWdS)NrTrrWrUr rr)rU)rT)rU)rr4lenr8rzipr9)rrArQrRZ
expected_listrr8rrrtest_call_args_two_tuples	*z!MockTest.test_call_args_two_tuplecCstdtdddg}|j|||gdddg|jt|tddddg}|j|||gdddg|jt|tdd}|j|||gd	d
dg|jt|Gdd
d
t}td|}|j||tdt}|j||||gddddg|jt|dS)NrZrTrUrWrr r!Zghighic@seZdZdS)z/MockTest.test_side_effect_iterator.<locals>.FooN)rrrrrrrr
srrrrr)	rrr4r[
StopIterationrrNr}r)rrArrrrtest_side_effect_iterators +++!z"MockTest.test_side_effect_iteratorcCs`t}tdddg|_|j|||gdddg|jt||j}|j|ttgdddg|_|j|||gdddg|jt||j}|j|ttgt}||_|j||||gddd	d
g|jt||j	|j|dS)NrTrUrWrr r!rrrr)
rrrZr4r[rr}rrr)rrArZZ	this_iterrrr!test_side_effect_setting_iterators"	+	+			!z*MockTest.test_side_effect_setting_iteratorcCsx{ttfD]m}tdtdf}|d|}|jt||j|d|jt||j|dq
WdS)NrWr+rZ)rrrarr[r4)rKlassiterablerrrr$test_side_effect_iterator_exceptions.sz-MockTest.test_side_effect_iterator_exceptionscCsJtdd}tdtg|_|j||gddgdS)Nr7rUrT)rrrrZr4)rrArrr!test_side_effect_iterator_default8sz*MockTest.test_side_effect_iterator_defaultcCst}|dd|dd|dd|dd|ddtddddifdfddifddddifddifdfddifg}x$|D]}|j|gd	d
qWxTtddtddtdddfD]%}|jt|j|gd	d
qWtddtddgtddtddgtddtddgg}x!|D]}|j|d	d
qWtddtddtddgtddtddgtddtddtd
dgtddtddtddtddtddgg}x*|D]"}|jt|j|d	d
qXWdS)NrTrUrrWrr r+r	any_orderTrr.rrrWr)rrTrU)rr)rTrU)rrassert_has_callsr[rv)rrAkallsZkallZ
kall_listsZ	kall_listrrrtest_assert_has_calls_any_order=s:	




$
4	!
''E
	z(MockTest.test_assert_has_calls_any_orderc		Cs3tddddifdtddddddifg}tjtjdg}|jtjjddj|jtjtd	ij	dgjg}xqt
tfD]]}|dd|dd|dd|dd|ddd|j||fqWt
}|j|jd|jjdd|jtd	ij	dg|j||fx|D]\}}xt
t|D]l}xcd
D][}||||}|j|t|dkr|jt|jtt|qWqWqWdS)NrTrUrrWrr r+rr.rWr)r)rT)rTrUrW)rr.r,extendZspamrHrZbamrrVrrrrangerrr[rvrreversed)	rZkalls1Zkalls2rIrAr	rstepZtheserrrtest_assert_has_callsis<%1



	

"

zMockTest.test_assert_has_callscCsddd}td|}|ddddd|d	d
dddd
|ddddddifdddd
ifdifg}|j||j|dd|j|dd|j|dddd|j|dd|j|ddddtt|}|jt|j|WdQRX|j|dd|jt|j|ddWdQRX|j|dddd|jt|j|ddWdQRX|j|dddddS)NcSsdS)Nr)rr r!r"rrrr_sz<MockTest.test_assert_has_calls_with_function_spec.<locals>.frLrTr rUr!rWrrr+r"r
rrT)rTrUrW)rrr+)rrrrrrr)rrrrr[rv)rr_rAZcallsrrr(test_assert_has_calls_with_function_specs0
z1MockTest.test_assert_has_calls_with_function_speccCst}|dd|dd|ddd|jdd|jdd|jddd|jt|j|jt|jdd|jt|jdddS)NrTrUrrWr r+r)rassert_any_callr[rv)rrArrrtest_assert_any_calls$	



	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}|jddWdQRXt|jdr'|j|jjtdS)NcSsdS)Nr)rr r!r"rrrr_sz;MockTest.test_assert_any_call_with_function_spec.<locals>.frLrTr rUr!rWrrr+r"rrrxryrz)	rrr[rvr{r|r}rzr~)rr_rArrrr'test_assert_any_call_with_function_specs"z0MockTest.test_assert_any_call_with_function_speccCsdd}t}||_t|t|jg}xS|D]K}|dd|dd|j|jtddtddgq@WdS)NcSsdS)Nr)rr rrrr_sz3MockTest.test_mock_calls_create_autospec.<locals>.frTrUrWr)rr_r
r4rkr)rr_objZfuncsrrrrtest_mock_calls_create_autospecs			


z(MockTest.test_mock_calls_create_autospeccCs2tjtdd}|jdt|dS)NrDZ
sweet_func)rAr
rNrErF)rrrrrtest_create_autospec_with_namesz'MockTest.test_create_autospec_with_namecCsrt}|jt|jWdQRX|jt|jWdQRXtdd}|j|jdS)NZunsafeT)rr[rZassert_foo_callZassret_foo_call)rrrrrtest_mock_unsafes	
zMockTest.test_mock_unsafec	CsHt}|jj|j|jt|jjWdQRXdS)N)rhelloZassert_not_calledr[rv)rrrrrtest_assert_not_calleds
	

zMockTest.test_assert_not_calledc	Cs_t}|jt|jjWdQRX|j|jj|j|jjdS)N)rr[rvrZ
assert_called)rrrrrtest_assert_calleds	


zMockTest.test_assert_calledcCsvt}|jt|jjWdQRX|j|jj|j|jt|jjWdQRXdS)N)rr[rvrZassert_called_once)rrrrrtest_assert_called_onces	


z MockTest.test_assert_called_oncecCsEt}|jddddd}|jt|jj|dS)NrDrZdaddyZheroz call(daddy='hero', name='hello'))rrr4rFr8)rrtextrrrtest_sorted_call_signature!s	z#MockTest.test_sorted_call_signaturecCsstj}tjdd}t}|j|jdd|j|jd||j|jd|dS)NrrrT)rrindexrr4r:)rr!rrrrrtest_override_tuple_methods(s	
z$MockTest.test_override_tuple_methodsc	
sGdddt}Gdddt}Gdddtttttg}xLt|D]>}|j|fdd|j|fd	dqaWxr|D]j}xattd
dfD]G}|}|j|j	|j
fx||fdgd
gfgD]\}}xttd
dfD]}|j|||j|jt
t|d
|jt
t|dd
|kr|jt
t|dd|j|||jt
t|d|j	|jt
t|dd
|kr2|jt
t|ddq2Wq
WqWqWdS)Nc@seZdZdZdS)z)MockTest.test_mock_add_spec.<locals>._OnerTN)rrrrrrrr_One2sr%c@seZdZdZdS)z)MockTest.test_mock_add_spec.<locals>._TworUN)rrrrrrrr_Two4sr&c@seZdZdZZZdS)z-MockTest.test_mock_add_spec.<locals>.AnythingZfourN)rrrrrthreerrrrAnything6sr(cs
|dS)NrLr)K)r(rrr=sz-MockTest.test_mock_add_spec.<locals>.<lambda>cs
|dS)NrMr)r))r(rrr>srMTrrr')rNrrrr	rrrrrr'
mock_add_specr[rrsetattr)	rr%r&ZklassesrrRrAZOneZTwor)r(rtest_mock_add_spec1s> 
	+zMockTest.test_mock_add_speccsxttfD]}|tjt|jtt|ddj_jt|j	td|jtfddq
WdS)Nr.rcsdS)Nr.rr)rArrrtsz;MockTest.test_mock_add_spec_magic_methods.<locals>.<lambda>)
rr	rr*rNr[r~rr7r4)rrr)rAr test_mock_add_spec_magic_methodsfs	

	
z)MockTest.test_mock_add_spec_magic_methodscCsxttttfD]}|}t|_|j|j|jtjg|j|jtjg|}tdd|_	|j	|j|jg|j|jg|}t|_
|j
|j|jg|j|jgqWdS)NrD)rrrr	r.r4r:rrkr,rH)rrrArrrtest_adding_child_mockws 	
	
	
zMockTest.test_adding_child_mockcCs\xUttfD]G}|}t|_||j|jttgq
WdS)N)rrr7r4rkr)rrrArrrtest_adding_return_value_mocks
	
z&MockTest.test_adding_return_value_mockcCsGdddt}t}tj|d}tj|d}|j}|j|j|j}|j|j|j|d|j|d|j|j|j	|j
tjtjgdS)Nc@seZdZdZdZdS)z'MockTest.test_manager_mock.<locals>.FoorrN)rrrrrrrrrrsrrr)rNrrrrrattach_mockrrr4rkr)rrmanagerZp1Zp2Zmock_oneZmock_tworrrtest_manager_mocks	

zMockTest.test_manager_mockcCsxttfD]}|}tdd|_tdd|_t|t||j|jtjtjg|j|j	gq
WdS)Nr7rWg@)
rrr	__float__rfloatr4rkrr:)rrrrrrtest_magic_methods_mock_callss	

%z&MockTest.test_magic_methods_mock_callscCsVtjdd}|d}|j}|d}|j}|j||dS)N	read_datadataza-namezanother-name)rArnreadr4)rZmocked_openf1Zf1_dataf2Zf2_datarrr test_mock_open_reuse_issue_21750sz)MockTest.test_mock_open_reuse_issue_21750c
Csvtjtjdd}tjd|B|j}|j}td|_dd}|jt|WdQRXdS)NrDZJLVztempfile.NamedTemporaryFilezTest 2 ErrorcSstjjddS)NZasd)tempfileNamedTemporaryFilewriterrrrattemptsz.MockTest.test_mock_open_write.<locals>.attempt)	rArnrrr7r>OSErrorrZr[)rZmock_namedtempZmock_filehandleZ
mock_writer?rrrtest_mock_open_writes		zMockTest.test_mock_open_writecCsitjdd}dd|jj_|j}|j}|jd||jd|dS)Nr6zfoo
barncWsdS)Nabcr)rQrrrrsz8MockTest.test_mock_open_alter_readline.<locals>.<lambda>rB)rArnr7readlinerZr4)rZmopenfirstsecondrrrtest_mock_open_alter_readlines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')
rrrFr7rr4rirr rE)rrrZ
original_reprrrrtest_mock_parentss,		
	
	zMockTest.test_mock_parentscCsttttf}x|D]}x|D]}|}|dd}|j|d|j|j||jdt||jj	d|j
|jtjj	dg|j
|j
tjj	dgq&WqWdS)NrDr.r,zname='mock.bar'rT)rrr	rr0rr,rErFrHr4rkrr:)rclassesrKlass2rm2rrrtest_attach_mocks

	"zMockTest.test_attach_mockcCsttttf}xttfD]}x|D]}|}|dd}|j|d|j|||jdt||j|j	|j
tjjq,WqWdS)NrDr.r7z
name='mock()')
rrr	rr0rrErFr.r4rkrr)rrHrrIrrJrrrtest_attach_mock_return_values
	
z&MockTest.test_attach_mock_return_valuecCsxttttfD]j}|jt|d|`|jt|d|`|jt|d|j	t
t|dqWdS)Nrr_)rrr	rr6r{rr2r_r[rr)rrArrrtest_attribute_deletionsz MockTest.test_attribute_deletioncCsQxJttfD]6}|j|tt|_|j|t|jqWdS)N)rrrrrr}r.)rrArrrtest_class_assignables
	zMockTest.test_class_assignablecCsxttttfD]}|dddd}|jdddtj|}tj|}|jjddd|j	|j
|jt|||j
|t|jdt||j|jdqWdS)NrDr.r-rWrTrUz
name="foo")rrr)r	r.pickledumpsloadsrr2r3r6r
r}r*rErFr4r-)rrrAr7newrrrtest_pickle(szMockTest.test_pickleN)^rrrr1rBrCrJrOr^r`rcrZ
skipUnlessrplatformrfrlrmrorsrurwrrrrrrrrrrrrrrrrrrrrrrZskipIfsixZPY3rrrrrrrrrrrrrrrrrrr
rrrrrrrrrrr!r$r,r-r.r/r2r5r;rArFrGrKrLrMrNZexpectedFailurerSrrrrr/Ds	)"



!!

7N#
,(!
	5	
	r/__main__)#rrOrr<rUZ	unittest2rrArrrrrrrr	r
Z	mock.mockrZmock.tests.supportrr
runicoderrrNrrr)r*rr/rmainrrrr<module>s2@



Back to Directory File Manager