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__/testpatch.cpython-34.pyo

�
j f���@s[ddlZddlZddlZddlmZddlmZmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZmZdZejeZdeZddd	�ZejaejZGd
d�de�ZdeZ ed
d�Z!Gdd�de�Z"Gdd�dej#�Z$edkrWej%�ndS)�N)�support)�	SomeClass�is_instance)
�NonCallableMock�
CallableMixin�patch�sentinel�	MagicMock�Mock�NonCallableMagicMockr�_patch�DEFAULT�call�_get_targetr�builtinsz%s.PTModuleTcsbG�fdd�dt�}|s[�fdd�}�fdd�}||_||_n|�S)Ncs"eZdZ�fdd�ZdS)z_get_proxy.<locals>.Proxycs
t�|�S)N)�getattr)�self�name)�obj��E/opt/alt/python34/lib64/python3.4/unittest/test/testmock/testpatch.py�__getattr__sz%_get_proxy.<locals>.Proxy.__getattr__N)�__name__�
__module__�__qualname__rr)rrr�Proxysrcst�||�dS)N)�setattr)rr�value)rrr�__setattr__sz_get_proxy.<locals>.__setattr__cst�|�dS)N)�delattr)rr)rrr�__delattr__ sz_get_proxy.<locals>.__delattr__)�objectrr )r�get_onlyrrr r)rr�
_get_proxys	r#c@sPeZdZdd�Zdd�Zdd�ZdZGdd	�d	e�Zd
S)�FoocCsdS)Nr)r�arrr�__init__-szFoo.__init__cCsdS)Nr)rr%rrr�f/szFoo.fcCsdS)Nr)rrrr�g1szFoo.g�barc@seZdZdd�ZdS)zFoo.BarcCsdS)Nr)rrrrr%6sz	Foo.Bar.aN)rrrr%rrrr�Bar5sr*N)	rrrr&r'r(�foor!r*rrrrr$,s
r$z%s.FoocCsdS)Nr)r%�brrr�function<sr-c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�	ContainercCs
i|_dS)N)�values)rrrrr&AszContainer.__init__cCs|j|S)N)r/)rrrrr�__getitem__DszContainer.__getitem__cCs||j|<dS)N)r/)rrrrrr�__setitem__GszContainer.__setitem__cCs|j|=dS)N)r/)rrrrr�__delitem__JszContainer.__delitem__cCs
t|j�S)N)�iterr/)rrrr�__iter__MszContainer.__iter__N)rrrr&r0r1r2r4rrrrr.@s
r.c@s�eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,dVdW�Z-dXdY�Z.dZd[�Z/d\d]�Z0d^d_�Z1d`da�Z2dbdc�Z3ddde�Z4dfdg�Z5dhdi�Z6djdk�Z7dldm�Z8dndo�Z9dpdq�Z:drds�Z;dtdu�Z<dvdw�Z=dxdy�Z>dzd{�Z?d|d}�Z@d~d�ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQeRd�d��d�d���ZSeRd�d��d�d���ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Zad�d��Zbd�S)��	PatchTestTcCsUt}|st}n|jt|�|jt||��|jt|t��dS)N)rr�assertRaises�	TypeError�
assertTruer�assertFalser)rr�magic�	MockClassrrr�assertNotCallableTs	zPatchTest.assertNotCallablecsgGdd�dt��tj�dtj���fdd��}|��j�jtjd�dS)Nc@seZdZejZdS)z4PatchTest.test_single_patchobject.<locals>.SomethingN)rrrr�Original�	attributerrrr�	Something_sr?r>cs�j�jtjd�dS)N�	unpatched)�assertEqualr>r�Patchedr)r?rrr�testbsz/PatchTest.test_single_patchobject.<locals>.testzpatch not restored)r!rrrBrAr>r=)rrCr)r?rr�test_single_patchobject^s
-z!PatchTest.test_single_patchobjectcsdGdd�dt��tj�dd���fdd��}|��j�jtjd�dS)Nc@seZdZejZdS)z7PatchTest.test_patchobject_with_none.<locals>.SomethingN)rrrrr=r>rrrrr?lsr?r>cs�j�jd�dS)Nr@)�assertIsNoner>r)r?rrrrCosz2PatchTest.test_patchobject_with_none.<locals>.testzpatch not restored)r!rrAr>rr=)rrCr)r?rr�test_patchobject_with_noneks
*z$PatchTest.test_patchobject_with_nonecs�Gdd�dt��tj�dtj�tj�dtj���fdd���}|��j�jtjd��j�jtj	d�dS)Nc@s"eZdZejZejZdS)z6PatchTest.test_multiple_patchobject.<locals>.SomethingN)rrrrr=r>�	Original2�next_attributerrrrr?ys	r?r>rHcs6�j�jtjd��j�jtjd�dS)Nr@)rAr>rrBrH�Patched2r)r?rrrrC}sz1PatchTest.test_multiple_patchobject.<locals>.testzpatch not restored)
r!rrrBrIrAr>r=rHrG)rrCr)r?rr�test_multiple_patchobjectxs0z#PatchTest.test_multiple_patchobjectc
Cs]t}tdttj�dd��}z'tja|�|jttj�Wd|aXdS)Nz%s.somethingcSsdS)NrrrrrrC�sz8PatchTest.test_object_lookup_is_quite_lazy.<locals>.test)�	somethingrrr�
Something2Zreplacement_valuerA)r�originalrCrrr� test_object_lookup_is_quite_lazy�s"	z*PatchTest.test_object_lookup_is_quite_lazycsPtdttj��fdd��}|��jtjtjd�tdttj�tdttj��fdd���}�jtjtjd��jtj	tjd�|��jtjtjd��jtj	tjd�t
�}tj|_tdt
|��fdd��}|�|��jt|d�dS)	Nz%s.somethingcs�jtjtjd�dS)Nr@)rA�PTModulerKrrLr)rrrrC�sz"PatchTest.test_patch.<locals>.testzpatch not restoredz%s.something_elsecs6�jtjtjd��jtjtjd�dS)Nr@)rArOrKrrL�something_else�
SomethingElser)rrrrC�sz%s.opencs#�jtdd�tjd�dS)N�filename�rzopen not patched)rA�openr�Handler)rrrrC�s)rrrrLrArOrKr?rQrPr
rU�return_value�builtin_string�assertNotEqualrT)rrC�mockr)rr�
test_patch�s*(+	%zPatchTest.test_patchcsItdttj��fdd��}|��jtjjd�dS)Nz%s.SomeClass.class_attributecs �jtjjtjd�dS)Nr@)rArOr�class_attributer�ClassAttributer)rrrrC�sz2PatchTest.test_patch_class_attribute.<locals>.testzpatch not restored)rrrr\rErOrr[)rrCr)rr�test_patch_class_attribute�s

z$PatchTest.test_patch_class_attributecs�Gdd�dt��tj�d���fdd��}|�tj�d�tj�d�����fdd���}d��|tjtj�\��|tjtj�dS)Nc@s"eZdZejZejZdS)z:PatchTest.test_patchobject_with_default_mock.<locals>.TestN)rrrrr=rKrG�
something2rrrr�Test�s	r_rKcs-�j|�jd��j|td�dS)Nz"Mock not passed into test functionz.patch with two arguments did not create a mock)rArK�assertIsInstancer	)rY)r_rrrrC�sz:PatchTest.test_patchobject_with_default_mock.<locals>.testr^cs��j|tjd��j|tjd��j|�jd��j|�jd��j|td��j|td��j�|d��j�|d�||fS)Nz0Patched function didn't receive initial argumentz/Patched function didn't receive second argumentz"Mock not passed into test functionz)Second Mock not passed into test functionz.patch with two arguments did not create a mockzunexpected value for mock1)	rAr�this1�this2r^rKr`r	rX)rarbZmock1Zmock2)r_�
outerMock1�
outerMock2rrrrC�s)r!rrrarb)rrCr)r_rcrdrr�"test_patchobject_with_default_mock�s'0
z,PatchTest.test_patchobject_with_default_mockcs3tdtdt��fdd��}|�dS)Nz%s.SomeClass�speccsC�jt|��jttjt���jtdd��dS)NcSstjS)N)r�
not_wibblerrrr�<lambda>sz>PatchTest.test_patch_with_spec.<locals>.test.<locals>.<lambda>)rArr8r�wibbler	r6�AttributeError)�
MockSomeClass)rrrrC�sz,PatchTest.test_patch_with_spec.<locals>.test)rrr)rrCr)rr�test_patch_with_spec�s(zPatchTest.test_patch_with_speccs5tjtddt��fdd��}|�dS)Nr[rfcsI�jtj|��jttjjt���jtdd��dS)NcSs
tjjS)N)rr[rgrrrrrh
szDPatchTest.test_patchobject_with_spec.<locals>.test.<locals>.<lambda>)	rArr[r8rrir	r6rj)�
MockAttribute)rrrrCs

	z2PatchTest.test_patchobject_with_spec.<locals>.test)rr!r)rrCr)rr�test_patchobject_with_specs*z$PatchTest.test_patchobject_with_speccs6tdtddg��fdd��}|�dS)Nz%s.SomeClassrfricsC�jt|��jttjt���jtdd��dS)NcSstjS)N)rrgrrrrrhszFPatchTest.test_patch_with_spec_as_list.<locals>.test.<locals>.<lambda>)rArr8rrir	r6rj)rk)rrrrCsz4PatchTest.test_patch_with_spec_as_list.<locals>.test)rr)rrCr)rr�test_patch_with_spec_as_lists+z&PatchTest.test_patch_with_spec_as_listcs8tjtdddg��fdd��}|�dS)Nr[rfricsI�jtj|��jttjjt���jtdd��dS)NcSs
tjjS)N)rr[rgrrrrrh#szLPatchTest.test_patchobject_with_spec_as_list.<locals>.test.<locals>.<lambda>)	rArr[r8rrir	r6rj)rm)rrrrCs

	z:PatchTest.test_patchobject_with_spec_as_list.<locals>.test)rr!r)rrCr)rr�"test_patchobject_with_spec_as_lists-z,PatchTest.test_patchobject_with_spec_as_listcsFtdt�tdtddg��fdd���}|�dS)Nz%s.openz%s.SomeClassrfricsC�jt|��jttjt���jtdd��dS)NcSstjS)N)rrgrrrrrh/szMPatchTest.test_nested_patch_with_spec_as_list.<locals>.test.<locals>.<lambda>)rArr8rrir	r6rj)rkZMockOpen)rrrrC*sz;PatchTest.test_nested_patch_with_spec_as_list.<locals>.test)rrWr)rrCr)rr�#test_nested_patch_with_spec_as_list(s
.z-PatchTest.test_nested_patch_with_spec_as_listcs3tdtdd��fdd��}|�dS)Nz%s.SomeClassrfTcs7�jt���j�jt�fdd��dS)Ncs�jS)N)rgr)rkrrrh:szIPatchTest.test_patch_with_spec_as_boolean.<locals>.test.<locals>.<lambda>)rArrir6rj)rk)r)rkrrC4sz7PatchTest.test_patch_with_spec_as_boolean.<locals>.test)rr)rrCr)rr�test_patch_with_spec_as_boolean3s(z)PatchTest.test_patch_with_spec_as_booleancs5tjtddd��fdd��}|�dS)NrrfTcs7�jt���j�jt�fdd��dS)Ncs�jS)N)rgr)rkrrrhFszPPatchTest.test_patch_object_with_spec_as_boolean.<locals>.test.<locals>.<lambda>)rArrir6rj)rk)r)rkrrC@sz>PatchTest.test_patch_object_with_spec_as_boolean.<locals>.test)rr!rO)rrCr)rr�&test_patch_object_with_spec_as_boolean?s*z0PatchTest.test_patch_object_with_spec_as_booleancs3tdtdd��fdd��}|�dS)Nz%s.SomeClassrfTcsS�jt|t��|���j���j�jt�fdd��dS)Ncs�jS)N)rgr)�instancerrrhTszVPatchTest.test_patch_class_acts_with_spec_is_inherited.<locals>.test.<locals>.<lambda>)r8rr	r<rir6rj)rk)r)rtrrCLs
	
zDPatchTest.test_patch_class_acts_with_spec_is_inherited.<locals>.test)rr)rrCr)rr�,test_patch_class_acts_with_spec_is_inheritedKs(
z6PatchTest.test_patch_class_acts_with_spec_is_inheritedcsOtdttjdd��fdd��}|��jtdd��dS)Nz
%s.frooble�createTcs�jttj�dS)N)rA�froobler�Froobler)rrrrCZszLPatchTest.test_patch_with_create_mocks_non_existent_attributes.<locals>.testcSstS)N)rwrrrrrh_szPPatchTest.test_patch_with_create_mocks_non_existent_attributes.<locals>.<lambda>)rrWrrxr6�	NameError)rrCr)rr�4test_patch_with_create_mocks_non_existent_attributesYs.z>PatchTest.test_patch_with_create_mocks_non_existent_attributescsQtjtdtjdd��fdd��}|��jttd��dS)NrwrvTcs�jtjtj�dS)N)rArrwrrxr)rrrrCcszRPatchTest.test_patchobject_with_create_mocks_non_existent_attributes.<locals>.test)rr!rrrxr9�hasattr)rrCr)rr�:test_patchobject_with_create_mocks_non_existent_attributesbs0zDPatchTest.test_patchobject_with_create_mocks_non_existent_attributescsoy3tdttj��fdd��}|�Wntk
rGYnX�jd��jtdd��dS)Nz
%s.frooblecs�jttj�dS)N)rArwrrxr)rrrrCmsz9PatchTest.test_patch_wont_create_by_default.<locals>.testz,Patching non existent attributes should failcSstS)N)rwrrrrrhwsz=PatchTest.test_patch_wont_create_by_default.<locals>.<lambda>)rrWrrxrj�failr6ry)rrCr)rr�!test_patch_wont_create_by_defaultks(

z+PatchTest.test_patch_wont_create_by_defaultcsqy5tjtdtj��fdd��}|�Wntk
rIYnX�jd��jttd��dS)Nrwcs�jd�dS)Nz,Patching non existent attributes should fail)r}r)rrrrC|sz?PatchTest.test_patchobject_wont_create_by_default.<locals>.testz,Patching non existent attributes should fail)	rr!rrrxrjr}r9r{)rrCr)rr�'test_patchobject_wont_create_by_defaultzs*

z1PatchTest.test_patchobject_wont_create_by_defaultcspGdd�dt��tj�dtdd�����fdd��}|��j�j�tj�dS)Nc@s"eZdZedd��ZdS)z5PatchTest.test_patch_with_static_methods.<locals>.FoocSstjS)N)r�Staticrrrr�woot�sz:PatchTest.test_patch_with_static_methods.<locals>.Foo.wootN)rrr�staticmethodr�rrrrr$�sr$r�cSstjS)N)rrBrrrrrh�sz:PatchTest.test_patch_with_static_methods.<locals>.<lambda>cs�j�j�tj�dS)N)rAr�rrBr)r$rrr�	anonymous�sz;PatchTest.test_patch_with_static_methods.<locals>.anonymous)r!rr�rAr�rr�)rr�r)r$rr�test_patch_with_static_methods�s6z(PatchTest.test_patch_with_static_methodscsNtj}tjtdd��fdd��}|��jtj|�dS)Nr$cs�jtjd�dS)Nr$)rArr$r)rrrr��sz-PatchTest.test_patch_local.<locals>.anonymous)rr$rr!rA)rr+r�r)rr�test_patch_local�s	'zPatchTest.test_patch_localcsvGdd�dt�}|��tj�_tj�dd���fdd��}|��j�jtj�dS)Nc@seZdZdZdS)z'PatchTest.test_patch_slots.<locals>.Foor$N)zFoo)rrr�	__slots__rrrrr$�sr$cs�j�jd�dS)Nr$)rAr$r)r+rrrr��sz-PatchTest.test_patch_slots.<locals>.anonymous)r!rr$rrA)rr$r�r)r+rr�test_patch_slots�s	*zPatchTest.test_patch_slotscs�Gdd�dt��G��fdd�dt�}tj�dtj�|�}|�}|j�|j��j�jtjd�dS)Nc@seZdZejZdS)z=PatchTest.test_patchobject_class_decorator.<locals>.SomethingN)rrrrr=r>rrrrr?�sr?cs:eZdZ��fdd�Z��fdd�ZdS)z7PatchTest.test_patchobject_class_decorator.<locals>.Foocs�j�jtjd�dS)Nr@)rAr>rrB)�
other_self)r?rrr�test_method�szCPatchTest.test_patchobject_class_decorator.<locals>.Foo.test_methodcs�j�jtjd�dS)Nznon-test method patched)rAr>rr=)r�)r?rrr�not_test_method�szGPatchTest.test_patchobject_class_decorator.<locals>.Foo.not_test_methodN)rrrr�r�r)r?rrrr$�sr$r>zpatch not restored)	r!rrrBr�r�rAr>r=)rr$r'r)r?rr� test_patchobject_class_decorator�s	

z*PatchTest.test_patchobject_class_decoratorcs�Gdd�dt�}G�fdd�dt�}tdt�|�}|�}|j�|j��j|jtjd��jt	j
tjd�dS)Nc@seZdZejZdS)z7PatchTest.test_patch_class_decorator.<locals>.SomethingN)rrrrr=r>rrrrr?�sr?cs4eZdZ�fdd�Z�fdd�ZdS)z1PatchTest.test_patch_class_decorator.<locals>.Foocs�jtj|d�dS)Nr@)rArOrK)r�Zmock_something)rrrr��sz=PatchTest.test_patch_class_decorator.<locals>.Foo.test_methodcs�jtjtjd�dS)Nznon-test method patched)rArOrKrr?)r�)rrrr��szAPatchTest.test_patch_class_decorator.<locals>.Foo.not_test_methodN)rrrr�r�r)rrrr$�sr$z%s.somethingzpatch not restored)r!rrr�r�rAr>rr=rOrKr?)rr?r$r'r)rr�test_patch_class_decorator�s	

z$PatchTest.test_patch_class_decoratorcsGdd�dt��tj�dtj�tj�dtj���fdd���}|��j�jtjd�dS)Nc@s"eZdZejZejZdS)z3PatchTest.test_patchobject_twice.<locals>.SomethingN)rrrrr=r>rGrHrrrrr?�s	r?r>cs�j�jtjd�dS)Nr@)rAr>rrBr)r?rrrrC�sz.PatchTest.test_patchobject_twice.<locals>.testzpatch not restored)r!rrrBrAr>r=)rrCr)r?rr�test_patchobject_twice�s0z PatchTest.test_patchobject_twicecs�it�d6dd6��j�}tj���fdd��}|��j�|�tj�idd6���fdd��}|��j�|�tj�d
g���fd	d��}|��j�|�dS)N�initialrK�othercsd�d<�d=d�d<dS)N�r%r�zsomething elser�rr)r+rrrC�s
z'PatchTest.test_patch_dict.<locals>.testr,r%cs.�jt��d��j�dd�dS)Nr�r%r,)rA�lenr)r+rrrrC�scs.�jt��d��j�dd�dS)Nr�r%r,)rAr�r)r+rrrrCs)r%r,)r!�copyr�dictrA)rrMrCr)r+rr�test_patch_dict�s!.*zPatchTest.test_patch_dictcs�t��t��d<d�d<�jj�}tj���fdd��}|��j�j|�tj�idd6���fdd��}|��j�j|�dS)	Nr�rKr�csd�d<�d=d�d<dS)Nr�r%r�zsomething elser�rr)r+rrrCs
z=PatchTest.test_patch_dict_with_container_object.<locals>.testr,r%cs1�jt�j�d��j�dd�dS)Nr�r%r,)rAr�r/r)r+rrrrCs)r.r!r/r�rr�rA)rrMrCr)r+rr�%test_patch_dict_with_container_object
s	

!.z/PatchTest.test_patch_dict_with_container_objectcs�it�d6dd6��j�}tj�dd���fdd��}|��j�|�tj�idd	6dd���fd
d��}|��j�|�tj�dgdd���fdd��}|��j�|�dS)
Nr�rKr��clearTcs(�j�i�d�d<d�d<dS)Nr�r%zsomething elser�)rAr)r+rrrrC,s
z2PatchTest.test_patch_dict_with_clear.<locals>.testr,r%cs�j�idd6�dS)Nr,r%)rAr)r+rrrrC6scs�j�idd6�dS)Nr,r%)rAr)r+rrrrC>s)r%r,)r!r�rr�rA)rrMrCr)r+rr�test_patch_dict_with_clear(s*40z$PatchTest.test_patch_dict_with_clearcs�t��t��d<d�d<�jj�}tj�dd���fdd��}|��j�j|�tj�idd	6dd���fd
d��}|��j�j|�dS)Nr�rKr�r�Tcs+�j�ji�d�d<d�d<dS)Nr�r%zsomething elser�)rAr/r)r+rrrrCNs
zGPatchTest.test_patch_dict_with_container_object_and_clear.<locals>.testr,r%cs�j�jidd6�dS)Nr,r%)rAr/r)r+rrrrCXs)r.r!r/r�rr�rA)rrMrCr)r+rr�/test_patch_dict_with_container_object_and_clearGs	

*4z9PatchTest.test_patch_dict_with_container_object_and_clearcCsi}tdtt��tdtt�dd�tjtt��tj|�dd�����}|j|jd�dS)Nz%s.SomeClass�autospecTcSsdS)Nrrrrr�	some_namedsz0PatchTest.test_name_preserved.<locals>.some_namer�)rrr!rr�rA)rr+r�rrr�test_name_preservedas$zPatchTest.test_name_preservedcCsli}tj|idd6�dd��}y|�Wntk
rJYnX|jd�|j|i�dS)Nr,r%cSstd��dS)NZKonrad)ryrrrrrCqsz1PatchTest.test_patch_with_exception.<locals>.testzNameError not raised by test)rr�ryr}rA)rr+rCrrr�test_patch_with_exceptionns%

z#PatchTest.test_patch_with_exceptioncs6tjdidd6��fdd��}|�dS)Nz
os.environz
some value�
konrad_delongcs�jdtj�dS)Nr�)�assertIn�os�environr)rrrrCsz3PatchTest.test_patch_dict_with_string.<locals>.test)rr�)rrCr)rr�test_patch_dict_with_string~s+z%PatchTest.test_patch_dict_with_stringcs�dSGdd�dt��G���fdd�dt���j�jd�d��j��j�jd�d��j���}�j|jd�d�|j��j|jd�d�|j�)Nc@seZdZdZdS)z0PatchTest.test_patch_descriptor.<locals>.NothingN)rrrr+rrrr�Nothing�sr�cs�eZdZiZej�dd�e��fdd���Zej�dd�edd���Z	ej
e�e��fdd���Zej
e�ed	d
���ZdS)z2PatchTest.test_patch_descriptor.<locals>.Somethingr+�cs�j|��dS)N)�assertIs)�cls)r?rrr�klass�sz8PatchTest.test_patch_descriptor.<locals>.Something.klasscSs|S)Nr)�argrrr�static�sz9PatchTest.test_patch_descriptor.<locals>.Something.staticcs�j|��dS)N)r�)r�)r?rrr�
klass_dict�sz=PatchTest.test_patch_descriptor.<locals>.Something.klass_dictcSs|S)Nr)r�rrr�static_dict�sz>PatchTest.test_patch_descriptor.<locals>.Something.static_dictN)
rrrr+rr!�classmethodr�r�r�r�r�r�r)r�r?rrrr?�sr?Zf00)r!rAr�r�r�r�)rrKr)r�r?rr�test_patch_descriptor�s"

	
zPatchTest.test_patch_descriptorcCs�tdtdtdd�dd��}|jt|�tjtddtdd�dd��}|jt|�tdtdd�d	d��}|jt|�tjtddd�d
d��}|jt|�dS)Nz%s.SomeClassrf�spec_setTcSs
d|_dS)Nr+)�z)r;rrrrC�sz+PatchTest.test_patch_spec_set.<locals>.testrcSs
d|_dS)Nr+)r�)r;rrrrC�scSs
d|_dS)Nr+)r�)r;rrrrC�scSs
d|_dS)Nr+)r�)r;rrrrC�s)rrrr6rjr!r)rrCrrr�test_patch_spec_set�s(*"$zPatchTest.test_patch_spec_setcCs6tdtdd�dd��}|jt|�dS)Nz%s.SomeClassr�TcSs|�}d|_dS)Nr+)r�)r;rtrrrrC�s	z-PatchTest.test_spec_set_inherit.<locals>.test)rrr6rj)rrCrrr�test_spec_set_inherit�s"zPatchTest.test_spec_set_inheritcCsxt}tdt�}|jt|�|j�}z$|j||�|jt|�Wd|j�X|jt|�dS)Nz%s.something)rKrrr��start�assertIsNot�stop)rrM�patcherrYrrr�test_patch_start_stop�szPatchTest.test_patch_start_stopcCs)ttdd�}|jt|j�dS)Nr)r�)r�foo_namer6�RuntimeErrorr�)rr�rrr�test_stop_without_start�sz!PatchTest.test_stop_without_startcCs}t}tjtdd�}|jt|�|j�}z$|j|d�|jt|�Wd|j�X|jt|�dS)NrKr+)rKrr!rOr�r�rAr�)rrMr�Zreplacedrrr�test_patchobject_start_stop�sz%PatchTest.test_patchobject_start_stopcCs�idd6}|j�}tj|dgdd�}|j||�|j�z|j|idd6�Wd|j�X|j||�dS)Nr)r+�spam�eggsr�T)r�r�)r�rr�rAr�r�)r�drMr�rrr�test_patch_dict_start_stop�s

z$PatchTest.test_patch_dict_start_stopcs�|�idd6��j�}G��fdd�dt�}tj�idd6dd�|�}|j�|�|�}|j�|j�|�|j�|j�|�|�}|j�|j�|�|j�|j�|�dS)	Nr�r�cs:eZdZ��fdd�Z��fdd�ZdS)z7PatchTest.test_patch_dict_class_decorator.<locals>.Testcs�j�idd6�dS)Nr)r+)rA)r)r��thisrr�
test_firstszBPatchTest.test_patch_dict_class_decorator.<locals>.Test.test_firstcs�j�idd6�dS)Nr)r+)rA)r)r�r�rr�test_second
szCPatchTest.test_patch_dict_class_decorator.<locals>.Test.test_secondN)rrrr�r�r)r�r�rrr_sr_r)r+r�T)r�r!rr�rAr�r�)rrMr_rCr)r�r�r�test_patch_dict_class_decorators 
%	

	

z)PatchTest.test_patch_dict_class_decoratorcs�Gdd�dt�}Gdd�d�}x�|||�|fD]|}t|��tj�dd���fdd��}|��j�jd��j|jd��jd�j�q?WdS)	Nc@seZdZdZdS)z0PatchTest.test_get_only_proxy.<locals>.Somethingr+N)rrrr+rrrrr?"sr?c@seZdZdZdS)z4PatchTest.test_get_only_proxy.<locals>.SomethingElser+N)rrrr+rrrrrQ$srQr+r)cs�j�jd�dS)Nr))rAr+r)�proxyrrrrC*sz+PatchTest.test_get_only_proxy.<locals>.test)r!r#rrAr+�assertNotIn�__dict__)rr?rQ�thingrCr)r�rr�test_get_only_proxy!s*zPatchTest.test_get_only_proxycs�Gdd�dt�}Gdd�d�}x�|||�|fD]�}t|dd��tj�dd���fd	d
��}|��j�jd��j|jd��jd�j�q?WdS)Nc@seZdZdZdS)z6PatchTest.test_get_set_delete_proxy.<locals>.Somethingr+N)rrrr+rrrrr?4sr?c@seZdZdZdS)z:PatchTest.test_get_set_delete_proxy.<locals>.SomethingElser+N)rrrr+rrrrrQ6srQr"Fr+r)cs�j�jd�dS)Nr))rAr+r)r�rrrrC<sz1PatchTest.test_get_set_delete_proxy.<locals>.test)r!r#rrAr+r�r�)rr?rQr�rCr)r�rr�test_get_set_delete_proxy3s*z#PatchTest.test_get_set_delete_proxycCs�itd6dd6t�d6}tt|�}|j�}|j�|jt|�|j|jj	�d�|j
|jt�dS)N�side_effect�!zfoo.bar.return_valuer+)�KeyErrorr	rr�r�r�r6rAr+r)r`)r�kwargsr�rYrrr�test_patch_keyword_argsEs

z!PatchTest.test_patch_keyword_argscCs�itd6dd6t�d6}tjtd|�}|j�}|j�|jt|�|j|j	j
�d�|j|j	t�dS)Nr�r�zfoo.bar.return_valuer+r')r�r	rr!r$r�r�r6rAr+r)r`)rr�r�rYrrr�test_patch_object_keyword_argsRs

z(PatchTest.test_patch_object_keyword_argscCs�idd6}|j�}tj|dddddd�}|j�z)|j|tdddddd��Wd|j�X|j||�dS)Nr)r+r��Zbaz�)r�rr�r�rAr�)rrMr�r�rrr�test_patch_dict_keyword_args_s
!
)z&PatchTest.test_patch_dict_keyword_argscs�Gdd�dt�}�fdd���fdd�����fdd�}ttd	d
�|�}|�}�jt|�|�tjt}tj|dd	d
�|�}|�}�jt|�|�dS)Nc@sPeZdZdd�Zdd�Zdd�ZdZGdd	�d	e�Zd
S)z$PatchTest.test_autospec.<locals>.BoocSsdS)Nr)rr%rrrr&psz-PatchTest.test_autospec.<locals>.Boo.__init__cSsdS)Nr)rr%rrrr'rsz&PatchTest.test_autospec.<locals>.Boo.fcSsdS)Nr)rrrrr(tsz&PatchTest.test_autospec.<locals>.Boo.gr)c@seZdZdd�ZdS)z(PatchTest.test_autospec.<locals>.Boo.BarcSsdS)Nr)rrrrr%ysz*PatchTest.test_autospec.<locals>.Boo.Bar.aN)rrrr%rrrrr*xsr*N)	rrrr&r'r(r+r!r*rrrr�Booos
r�cs+|d�|jd��jt|�dS)N�)�assert_called_withr6r7)rY)rrr�_test|s

z&PatchTest.test_autospec.<locals>._testcsn|jd�|jjd��jt|j�|j�|jj��jt|jd��jtt|d�|jj�|jjj��jtt|jd�|j	�|j	j�|j	j
�|j	j
j��jt|j	j
d�|j	�j
�|j	�j
j��jt|j	�j
d��jtt|j	d��jtt|j	�d�dS)Nr��hr)r,)r'r�r6r7r(rjrr+�lowerr*r%)rY)rrr�_test2�s(






z'PatchTest.test_autospec.<locals>._test2cs8�|��|��|d���j|t�|S)Nr�)r�r$)rY)r�r�rrrr-�s


z)PatchTest.test_autospec.<locals>.functionr�Tr$)r!rr�r�r$�sys�modulesr)rr�r-rCrY�moduler)r�r�rr�
test_autospecns
	
	zPatchTest.test_autospeccs3tdtdd��fdd��}|�dS)Nz%s.functionr�Tcs^td�tjd�tdd�tjdd��jtt��jtttd�dS)Nr�r�r�r+)r-r�r6r7rjr)rY)rrrrC�s


z.PatchTest.test_autospec_function.<locals>.test)rr)rrCr)rr�test_autospec_function�s(
z PatchTest.test_autospec_functioncCsEtdtdddd�dd��}|�}|j|d�dS)Nz%s.functionr�TrVr�cSs
tdd�S)Nr�r�)r-)Z
mock_functionrrrrC�sz.PatchTest.test_autospec_keywords.<locals>.test)rrrA)rrC�resultrrr�test_autospec_keywords�s	z PatchTest.test_autospec_keywordscCsqtdtdddd�}|jt|j�tjt}tj|ddddd�}|jt|j�dS)Nz%s.function�newr�r�Tr-)rrr6r7r�r�r�r!)rr�r�rrr�test_autospec_with_new�s

z PatchTest.test_autospec_with_newc
CsmGdd�dt�}ttd|�}|j�}z'|j||�|j|jt�Wd|j�XdS)Nc@seZdZgZdS)z0PatchTest.test_autospec_with_object.<locals>.BarN)rrr�extrarrrrr*�sr*r�)r$rr�r�r`r��listr�)rr*r�rYrrr�test_autospec_with_object�sz#PatchTest.test_autospec_with_objectc
Cs`t}ttdd�}|j�}z*|j||�|j|d�|�Wd|j�XdS)Nr�Tr�)r$rr�r�r`r�)rZFooClassr�rYrrr�test_autospec_inherits�sz PatchTest.test_autospec_inheritscCs�ttdd�}|j�}zn|jdt|��|jdt|j��|jdt|d���|jdt|d�j��Wd|j�XdS)Nr�Tz name='Foo'z
 name='Foo.f'z
 name='Foo()'z name='Foo().f')rr�r�r��reprr'r�)rr�rYrrr�test_autospec_name�s#zPatchTest.test_autospec_namec
Cs�tjtdt��dd��}y|�Wntj�}YnXtjddd�}|j||�}|jd|�dS)Nr'cSs
t�dS)N)�AssertionErrorrrrrrC�sz'PatchTest.test_tracebacks.<locals>.testrzraise AssertionError)	rr!r$r��exc_info�unittestZTextTestResultZ_exc_info_to_stringr�)rrC�errr��	tracebackrrr�test_tracebacks�s$zPatchTest.test_tracebackscCsvttdt�}|j�}|j�|j�}|j�|j||�x!||fD]}|j|�q[WdS)N�new_callable)rr�rr�r�r�r<)rr��m1�m2rYrrr�test_new_callable_patch
s

z!PatchTest.test_new_callable_patchcCs|tjtddt�}|j�}|j�|j�}|j�|j||�x!||fD]}|j|�qaWdS)Nr'r�)rr!r$rr�r�r�r<)rr�r�r�rYrrr�test_new_callable_patch_objects

z(PatchTest.test_new_callable_patch_objectc
s�G�fdd�dt��ttd�dddd�}|j�}z<|jt|���|j�jtdddd��Wd|j	�XdS)Ncs(eZdZdZ�fdd�ZdS)z:PatchTest.test_new_callable_keyword_arguments.<locals>.BarNcs
|�_dS)N)r�)rr�)r*rrr&'szCPatchTest.test_new_callable_keyword_arguments.<locals>.Bar.__init__)rrrr�r&r)r*rrr*%sr*r�Zarg1r�Zarg2r�)
r!rr�r�r��typerAr�r�r�)rr��mr)r*r�#test_new_callable_keyword_arguments$s&z-PatchTest.test_new_callable_keyword_argumentscs�G�fdd�dt��ttd�d��}|j�z |j�jtd���Wd|j�Xttd�d��}|j�z |j�jtd���Wd|j�XdS)Ncs(eZdZdZ�fdd�ZdS)z-PatchTest.test_new_callable_spec.<locals>.BarNcs
|�_dS)N)r�)rr�)r*rrr&6sz6PatchTest.test_new_callable_spec.<locals>.Bar.__init__)rrrr�r&r)r*rrr*4sr*r�rfr�)r!rr�r�rAr�r�r�)rr�r)r*r�test_new_callable_spec3s
 
 z PatchTest.test_new_callable_specc
Cs|dt}t|dt�}|jt|j�t|dtdd�}|j�}z|j|dd�Wd|j�XdS)Nz	%s.weeeeer�rvTr:F)r�rrr6rjr�r<r�)rZnon_existent_attr�pr�rrr�test_new_callable_createHs
	z"PatchTest.test_new_callable_createc	CsN|jtttdt�dt�|jttjtddt�dt�dS)Nr�r�r')r6�
ValueErrorrr�r!r	r$)rrrr�'test_new_callable_incompatible_with_newVs
z1PatchTest.test_new_callable_incompatible_with_newc	CsH|jtttdtdd�|jttjtddtdd�dS)Nr�r�Tr')r6r�rr�r	r!r$)rrrr�,test_new_callable_incompatible_with_autospec`sz6PatchTest.test_new_callable_incompatible_with_autospecc	
Cs�Gdd�dt�}tttt|f}x~|D]v}xmdD]e}id|6}ttd||�}|j�}z#|j}|jt	t
|d�Wd|j�Xq?Wq2WdS)	Nc@seZdZdS)z>PatchTest.test_new_callable_inherit_for_mocks.<locals>.MockSubN)rrrrrrr�MockSublsr�rfr�Tr��x)zspeczspec_set)r
rrr	rr�r�rVr6rjrr�)	rr�ZMockClassesZKlassr�r�r�r�rtrrr�#test_new_callable_inherit_for_mocksks


	z-PatchTest.test_new_callable_inherit_for_mockscCs�Gdd�dt�}ttd|dd�}|j�}z0|jt||��|jtt|d�Wd|j	�X|j
|jt�dS)Nc@seZdZdd�ZdS)z>PatchTest.test_new_callable_inherit_non_mock.<locals>.NotAMockcSs
||_dS)N)rf)rrfrrrr&�szGPatchTest.test_new_callable_inherit_non_mock.<locals>.NotAMock.__init__N)rrrr&rrrr�NotAMocksr�r�rfTrV)
r!rr�r�r8rr6rjrr�rArfr$)rr�r�r�rrr�"test_new_callable_inherit_non_mock~sz,PatchTest.test_new_callable_inherit_non_mockcsq|�t�G��fdd�dt�}ttdt�|�}|�j�|�j�|jt��dS)Ncs=eZdZ��fdd�Zdd�Zdd�ZdS)z>PatchTest.test_new_callable_class_decorating.<locals>.SomeTestcs4�jt���jt|��jtt�dS)N)r�r$r�r`r)r�mock_foo)rMrCrrr��szDPatchTest.test_new_callable_class_decorating.<locals>.SomeTest._testcSs|j|�dS)N)r�)rrrrr�test_two�szGPatchTest.test_new_callable_class_decorating.<locals>.SomeTest.test_twocSs|j|�dS)N)r�)rrrrr�test_one�szGPatchTest.test_new_callable_class_decorating.<locals>.SomeTest.test_oneN)rrrr�rrr)rMrCrr�SomeTest�srr�)r$r!rr�rrrr�)rrr)rMrCr�"test_new_callable_class_decorating�s

z,PatchTest.test_new_callable_class_decoratingcs(t�tj}tj}tjtdddd�}tjtdddd�}x�||fD]�}|j�z:�jt���jtjd��jtjd�Wd|j	�X�jt���jtj|��jtj|�q[Wtjtdddd���fdd��}|�dS)	Nr'r�r(r�r�r�cs:�jt���jtjd��jtjd�dS)Nr�r�)r�r$rAr'r(r)�original_foorrrrC�sz+PatchTest.test_patch_multiple.<locals>.test)
r$r'r(r�multipler�r�r�rAr�)r�
original_f�
original_gZpatcher1Zpatcher2r�rCr)rrr�test_patch_multiple�s"		
0zPatchTest.test_patch_multiplecCs0|jttjt�|jttjt�dS)N)r6r�rrr�r$)rrrr�test_patch_multiple_no_kwargs�sz'PatchTest.test_patch_multiple_no_kwargscst�tj}tj}tjtdtdddt���fdd��}|��jtj|��jtj|�dS)Nr'r(r�r+csy�jt���jtj|��jtjd��jtj|��jt|t���jt|t��dS)Nr�)	r�r$r'rAr(r+r8rr	)r'r+)rrrrrC�sz8PatchTest.test_patch_multiple_create_mocks.<locals>.test)r$r'r(rrr�r
rA)rrrrCr)rrr� test_patch_multiple_create_mocks�s		6	z*PatchTest.test_patch_multiple_create_mockscs�tj}tj}tjtdd�}d|_tjtdt�}d|_|g|_|�fdd��}|��jtj|��jtj|�dS)Nr'r�r(cs*�jtj|��jtjd�dS)Nr�)r�r$r(rAr')r()rrrrC�szHPatchTest.test_patch_multiple_create_mocks_different_order.<locals>.test)	r$r'r(rr!�attribute_namer
�additional_patchersrA)rrrr�r�rCr)rr�0test_patch_multiple_create_mocks_different_order�s				z:PatchTest.test_patch_multiple_create_mocks_different_ordercsPt�tj}tj}tjtdt�tjtdt�ttd��fdd����}tjtdt�ttd�tjtdt��fdd����}ttd�tjtdt�tjtdt��fdd	����}��fd
d��|�|�|��jtj|��jtj|�dS)Nr'r+z.gcs�||�dS)Nr)r(r�)r�rr�test1�sz?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test1cs�||�dS)Nr)r(r�)r�rr�test2�sz?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test2cs�||�dS)Nr)r(r�)r�rr�test3sz?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test3cs�|jd�}|jd�}�j|��jt���jtj|��jtj|��jtj|��jt|t	���jt|t	���jt|t	��dS)Nr'r+)
�popr9r�r$r'r(r+r8rr	)r(r�r'r+)rrrrr�s
z?PatchTest.test_patch_multiple_stacked_decorators.<locals>._test)r$r'r(rrr�r
rA)rrrrrrr)r�rrr�&test_patch_multiple_stacked_decorators�s$		(
-
-
z0PatchTest.test_patch_multiple_stacked_decoratorscCst}tj}tj}tjtdtdddt�}|j�}z�|d}|d}|jt	|�t	ddg��|j
t|�|j
tj|�|j
tj|�|jt
|t��|jt
|t��Wd|j�X|jtj|�|jtj|�dS)Nr'r(r�r+)r$r'r(rrr�r
r�rA�setr�r+r8rr	r�)rrrrr�r�r'r+rrr�(test_patch_multiple_create_mocks_patchers"		!

"z2PatchTest.test_patch_multiple_create_mocks_patchercs�|�t�tj}tj}G��fdd�dt�}tjtdtdddt�|�}|�}|j�|j	�|j
tj|�|j
tj|�dS)Ncs=eZdZ��fdd�Zdd�Zdd�ZdS)z@PatchTest.test_patch_multiple_decorating_class.<locals>.SomeTestcsy�jt���jtj|��jtjd��jtj|��jt|t���jt|t��dS)Nr�)	r�r$r'rAr(r+r8rr	)rr'r+)rrCrrr�<szFPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest._testcSs|j||�dS)N)r�)rr'r+rrrrDszIPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest.test_twocSs|j||�dS)N)r�)rr'r+rrrrFszIPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest.test_oneN)rrrr�rrr)rrCrrr:srr'r(r�r+)r$r'r(r!rrr�r
rrrA)rrrrr�r)rrCr�$test_patch_multiple_decorating_class4s				

z.PatchTest.test_patch_multiple_decorating_classcCs�tjtdd�}|jt|j�tjtdddd�}|j�z|jtjd�Wd|j�X|j	t
td��dS)N�blamrvT)rrr$r6rjr�rArr�r9r{)rr�rrr�test_patch_multiple_createUs
z$PatchTest.test_patch_multiple_createcCs�tjtdtdddg�}|j�}z}|jtj|d�tjjd�tjjd�tjjj	d�tjjj	d�|j
tttjdd�Wd|j
�XdS)Nr+r�r%r,r�r��c)rrr$r
r�rAr+r%r,r�r6rjrr�)rr�r�rrr�test_patch_multiple_spec_setcs! z&PatchTest.test_patch_multiple_spec_setc
Cs�Gdd�dt�}tjtdtdtd|�}|j�}zn|jtj|d�|jtj|d�|j	tj|�|j	tj|�|j
tjtj�Wd|j�XdS)Nc@seZdZdS)z9PatchTest.test_patch_multiple_new_callable.<locals>.ThingN)rrrrrrr�Thingtsrr'r(r�)r!rrr$r
r�r�r'r(r`r�r�)rrr�r�rrr� test_patch_multiple_new_callablessz*PatchTest.test_patch_multiple_new_callablecCsGtj}tj}tjtdd�tjtdd�tjtdd�dd����}tjtdd�tjtdd�tjtdd�dd����}tjtdd�tjtdd�tjtdd�d	d
����}xM|||fD]<}|jt|�|jtj|�|jtj|�qWdS)Nr(r��missingr'cSsdS)Nrrrrr�thing1�sz3PatchTest.test_nested_patch_failure.<locals>.thing1cSsdS)Nrrrrr�thing2�sz3PatchTest.test_nested_patch_failure.<locals>.thing2cSsdS)Nrrrrr�thing3�sz3PatchTest.test_nested_patch_failure.<locals>.thing3)r$r'r(rr!r6rjrA)rrrrrr �funcrrr�test_nested_patch_failure�s		'''z#PatchTest.test_nested_patch_failurec	Csxtj}tj}tj}dd�}tjtdd�tjtdd|�tjtdd�dd	����}tjtdd|�tjtdd�tjtdd�d
d����}tjtdd�tjtdd�tjtdd|�dd
����}x`|||fD]O}|jt|�|jtj|�|jtj|�|jtj|�q!WdS)NcSstd��dS)N�crasher)ryrrrrr#�sz4PatchTest.test_new_callable_failure.<locals>.crasherr(r�r+r�r'cSsdS)Nrrrrrr�sz3PatchTest.test_new_callable_failure.<locals>.thing1cSsdS)Nrrrrrr�sz3PatchTest.test_new_callable_failure.<locals>.thing2cSsdS)Nrrrrrr �sz3PatchTest.test_new_callable_failure.<locals>.thing3)	r$r'r(r+rr!r6ryrA)	rrrrr#rrr r!rrr�test_new_callable_failure�s$			''*z#PatchTest.test_new_callable_failurecCs�tj}tj}tjtdd�}d|_tjtdd�}d|_tjtdd�}d|_xq||g||gfD]W}||_|dd��}|jt|�|j	tj|�|j	tj|�q�WdS)Nr'r�r(rcSsdS)Nrrrrrr!�sz3PatchTest.test_patch_multiple_failure.<locals>.func)
r$r'r(rr!rr
r6rjrA)rrrr��good�bad�additionalsr!rrr�test_patch_multiple_failure�s						z%PatchTest.test_patch_multiple_failurec
Cstj}tj}tj}dd�}tjtdd�}d|_tjtdd�}d|_tjtdd|�}d|_x�||g||gfD]j}||_|dd	��}	|jt	|	�|j
tj|�|j
tj|�|j
tj|�q�WdS)
NcSstd��dS)Nr#)ryrrrrr#�szCPatchTest.test_patch_multiple_new_callable_failure.<locals>.crasherr'r�r(r+r�cSsdS)Nrrrrrr!�sz@PatchTest.test_patch_multiple_new_callable_failure.<locals>.func)r$r'r(r+rr!rr
r6ryrA)
rrrrr#r�r%r&r'r!rrr�(test_patch_multiple_new_callable_failure�s"							z2PatchTest.test_patch_multiple_new_callable_failurecsmtdtfidd6�}|��tj�dd���fdd��}|��j�jd�dS)Nr$Ztasty�fishznearly gonecs�j�jd�dS)Nznearly gone)rAr*r)r+rrrrC�sz=PatchTest.test_patch_multiple_string_subclasses.<locals>.test)r��strrrrAr*)rr$rCr)r+rr�%test_patch_multiple_string_subclasses�s
	*z/PatchTest.test_patch_multiple_string_subclasseszunittest.mock.patch.TEST_PREFIXr+cCs�Gdd�dt�}tj|dd�|�}|�}|j|j�d�|j|j�d�|j|j�d�|j|j�d�dS)Nc@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)z-PatchTest.test_patch_test_prefix.<locals>.FoorMcSs|jS)N)r�)rrrr�foo_one	sz5PatchTest.test_patch_test_prefix.<locals>.Foo.foo_onecSs|jS)N)r�)rrrr�foo_twosz5PatchTest.test_patch_test_prefix.<locals>.Foo.foo_twocSs|jS)N)r�)rrrrr
sz6PatchTest.test_patch_test_prefix.<locals>.Foo.test_onecSs|jS)N)r�)rrrrrsz6PatchTest.test_patch_test_prefix.<locals>.Foo.test_twoN)rrrr�r-r.rrrrrrr$s
r$r��changedrM)r!rrAr-r.rr)rr$r+rrr�test_patch_test_prefixs	z PatchTest.test_patch_test_prefixr)cs�G�fdd�dt�}idd6�tj�dd�|�}|�}|j|j�idd6�|j|j�idd6�|j|j�idd6�|j|j�idd6�dS)NcsXeZdZ�fdd�Z�fdd�Z�fdd�Z�fdd�Zd	S)
z2PatchTest.test_patch_dict_test_prefix.<locals>.Foocs
t��S)N)r�)r)�the_dictrr�bar_onesz:PatchTest.test_patch_dict_test_prefix.<locals>.Foo.bar_onecs
t��S)N)r�)r)r1rr�bar_two sz:PatchTest.test_patch_dict_test_prefix.<locals>.Foo.bar_twocs
t��S)N)r�)r)r1rrr"sz;PatchTest.test_patch_dict_test_prefix.<locals>.Foo.test_onecs
t��S)N)r�)r)r1rrr$sz;PatchTest.test_patch_dict_test_prefix.<locals>.Foo.test_twoN)rrrr2r3rrr)r1rrr$sr$rM�keyr/)r!rr�rAr2r3rr)rr$r+r)r1r�test_patch_dict_test_prefixs

	z%PatchTest.test_patch_dict_test_prefixcCs�x�d
D]�}tdtid|6�}|j�}zh|jdt|��|jdt|j��|jdt|���|jd	t|�j��Wd|j�XqWdS)Nrfr�r�z%s.SomeClassTz name='SomeClass'z! name='SomeClass.class_attribute'z name='SomeClass()'z# name='SomeClass().class_attribute')zspeczautospeczspec_set)rrr�r�r�r[r�)rr�r�r�rrr�test_patch_with_spec_mock_repr1s
		z(PatchTest.test_patch_with_spec_mock_reprcCs`tddd��H}|jdt|jj���|jdt|j�j���WdQXdS)Nzunittest.test.testmock.supportr�Tz" name='support.SomeClass.wibble()'z$ name='support.SomeClass().wibble()')rr�r�rri)rr�rrr�test_patch_nested_autospec_repr@s
		z)PatchTest.test_patch_nested_autospec_reprcCs[xTdD]L}tdtid|6�}|j�}z|j�tj�g}|j|j|�|j|j|�|j|jjt�g�|�}|jt��|j|j|�|j�|jt�j��|j|j|�|j|jtj�g�|j|jjt�g�|j|jtj�g�Wd|j	�XqWdS)Nrfr�r�z%s.SomeClassT)zspeczautospeczspec_set)
rrr�rirrAZ
mock_callsZmethod_calls�appendr�)rr�r�r�Zkallsr�rrr�test_mock_calls_with_patchIs&

	
 z$PatchTest.test_mock_calls_with_patchcCs�tjjdd�td�}|jt|j�t�}d|_|tjd<td�}d|_|j�|j	�|j
|jd�dS)N�squizzz
squizz.squozz�r�)r�r�rrr6�ImportErrorr�r
Zsquozzr�rA)rZp1r:rrr�test_patch_imports_lazilyds		
	

z#PatchTest.test_patch_imports_lazilycs�Gdd�d��G�fdd�dt���fdd�}|d�dd	��}|jt|�|j�jd
t�|j�jdd�|j�jd
d�dS)Nc@seZdZdZdS)z<PatchTest.test_patch_propogrates_exc_on_exit.<locals>.holderN)NNN)rrrr�rrrr�holderusr>cs1eZdZddd�fdd�ZeZdS)zBPatchTest.test_patch_propogrates_exc_on_exit.<locals>.custom_patchNcs,tj||||�|||f�_dS)N)r�__exit__r�)r�etype�val�tb)r>rrr?yszKPatchTest.test_patch_propogrates_exc_on_exit.<locals>.custom_patch.__exit__)rrrr?r�r)r>rr�custom_patchxsrCc
s4t|�\}}�||tdddddi�	S)NF)rr
)�target�getterr>)rCrr�with_custom_patch~szGPatchTest.test_patch_propogrates_exc_on_exit.<locals>.with_custom_patchz
squizz.squozzcSs
t�dS)N)r�)rYrrrrC�sz:PatchTest.test_patch_propogrates_exc_on_exit.<locals>.testrr�zexception value not propgatedr�z!exception traceback not propgated)rr6r�r�r�ZassertIsNotNone)rrFrCr)rCr>r�"test_patch_propogrates_exc_on_exittsz,PatchTest.test_patch_propogrates_exc_on_exitcCs�x�d	D]}tdtddid|6�}|jt|j�|jtdd��ttddid|6�}|j�|j�qWdS)
Nrfr�r�z%s.doesnotexistrvTcSstS)N)�doesnotexistrrrrrh�sz1PatchTest.test_create_and_specs.<locals>.<lambda>)zspeczspec_setzautospec)rrr6r7r�ry�MODNAMEr�)r�kwargr�rrr�test_create_and_specs�s

zPatchTest.test_create_and_specscCs�t}xMdD]E}ttddid|6�}|jt|j�|jt|�q
WxMdD]E}ttddid|6�}|jt|j�|jt|�q]WxMdD]E}ttddid|6�}|jt|j�|jt|�q�WdS)Nrfr�r�r)�spec�spec_set)rLr�)rMr�)rOrrIr6r7r�r�)rrMrJr�rrr�test_multiple_specs�s


zPatchTest.test_multiple_specsc
CsPttdddddd�}|j�}z|jd|_Wd|j�XdS)NrfFr�r�r�)rrIr�Zdoes_not_existr�)rr�rYrrr� test_specs_false_instead_of_none�s
z*PatchTest.test_specs_false_instead_of_nonecCs_xXdD]P}ttid|6�}|j�}z|jtt|d�Wd|j�XqWdS)Nrfr�r�rZdoesnotexit)zspeczautospeczspec_set)rrIr�r6rjrr�)rrJr�r�rrr�test_falsey_spec�s
zPatchTest.test_falsey_specc
Cs~xwdD]o}ttddid|6�}|j�}z3|jtt|dd�|jtt|d�Wd|j�XqWdS)Nrfr�r�TrHrK)zspeczautospec)rrIr�r6rjrrr�)rrJr�r�rrr�test_spec_set_true�s

zPatchTest.test_spec_set_truec
CsMd}ttd|�}|j�}z|jt|��Wd|j�XdS)N�__call__rf)z__call__)rrIr�r8�callabler�)rrfr�r�rrr�test_callable_spec_as_list�sz$PatchTest.test_callable_spec_as_listc
CsMd}ttd|�}|j�}z|jt|��Wd|j�XdS)Nr+r)rf)zfoozbar)rrIr�r9rSr�)rrfr�r�rrr�test_not_callable_spec_as_list�sz(PatchTest.test_not_callable_spec_as_listcs�tj�tj�tj}tdt�j�tdt�j�td����fdd��}|��jtj|�dS)Nz	os.unlinkzos.chdirzos.pathcsGtj��jtj|��jtj���jtj��dS)N)r�stopallr�r��path�unlink�chdir)Z	mock_path)rYrrXrr�patched�s
z-PatchTest.test_patch_stopall.<locals>.patched)	r�rXrYrWrrKr�rPr�)rrWrZr)rYrrXr�test_patch_stopall�s			$zPatchTest.test_patch_stopallcsog�Gdd�dt����fdd���fdd�d
D�tj�|j�d	ddg�dS)Nc@seZdZdZZZdS)z*PatchTest.test_stopall_lifo.<locals>.thingN)rrr�one�two�threerrrrr��sr�c
sPG���fdd�dt����fdd��ddddddi�	S)Ncs+eZdZ����fdd�Z�S)z?PatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.mypatchcs �j��t�|�j�S)N)r8�superr�)r)�	__class__r>�mypatch�stoppedrrr��s
zDPatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.mypatch.stop)rrrr�r)r>rarb)r`rra�sracs�S)Nrr)r�rrrhsz@PatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.<lambda>F)r)r>)rbr�)r>rar�	get_patch�s"z.PatchTest.test_stopall_lifo.<locals>.get_patchcs"g|]}�|�j��qSr)r�)�.0rA)rcrr�
<listcomp>s	z/PatchTest.test_stopall_lifo.<locals>.<listcomp>r\r]r^)zoneztwozthree)r!rrVrA)rr)rcrbr�r�test_stopall_lifo�s
zPatchTest.test_stopall_lifoN)crrrr<rDrFrJrNrZr]rerlrnrorprqrrrsrurzr|r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr	r
rrrrrrrrr"r$r(r)r,rr0r5r6r7r9r=rGrKrNrOrPrQrTrUr[rfrrrrr5Rs�


+*

		
!
+	



G	




+!!	



r5�__main__)&r�r�r�Zunittest.test.testmockrZunittest.test.testmock.supportrrZ
unittest.mockrrrrr	r
rrr
rrrWr�rrOrIr#r?rKrQrPr!r$r�r-r.ZTestCaser5�mainrrrr�<module>s0X

		
�������