[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@13.59.183.77: ~ $


�/�V��@s�ddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
ddlmZm
Z
mZmZmZmZmZmZmZmZddlmZmZdZejr�dZeZejeZdeZd	d
d�Z ej!a"ej#Z$Gdd
�d
e%�Z&deZ'e&dd�Z(Gdd�de%�Z)Gdd�dej*�Z+edkrej,�dS)�N)�support)�	SomeClass�is_instance�callable)
�NonCallableMock�
CallableMixin�patch�sentinel�	MagicMock�Mock�NonCallableMagicMockr�DEFAULT�call)�_patch�_get_target�__builtin__�builtinsz%s.PTModuleTcs_G�fdd�dt�}|sX�fdd�}�fdd�}||_||_|�S)Ncs"eZdZ�fdd�ZdS)z_get_proxy.<locals>.Proxycs
t�|�S)N)�getattr)�self�name)�obj��
/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__)�objectr r")r�get_onlyrr r"r)rr�
_get_proxys		r%c@sPeZdZdd�Zdd�Zdd�ZdZGdd	�d	e�Zd
S)�FoocCsdS)Nr)r�arrr�__init__2szFoo.__init__cCsdS)Nr)rr'rrr�f4szFoo.fcCsdS)Nr)rrrr�g6szFoo.g�barc@seZdZdd�ZdS)zFoo.BarcCsdS)Nr)rrrrr';sz	Foo.Bar.aN)rrrr'rrrr�Bar:sr,N)	rrrr(r)r*�foor#r,rrrrr&1s
r&z%s.FoocCsdS)Nr)r'�brrr�functionAsr/c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�	ContainercCs
i|_dS)N)�values)rrrrr(FszContainer.__init__cCs|j|S)N)r1)rrrrr�__getitem__IszContainer.__getitem__cCs||j|<dS)N)r1)rrrrrr�__setitem__LszContainer.__setitem__cCs|j|=dS)N)r1)rrrrr�__delitem__OszContainer.__delitem__cCs
t|j�S)N)�iterr1)rrrr�__iter__RszContainer.__iter__N)rrrr(r2r3r4r6rrrrr0Es
r0c@seZdZddd�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$e%j&dFdG��Z'dHdI�Z(dJdK�Z)dLdM�Z*dNdO�Z+dPdQ�Z,dRdS�Z-dTdU�Z.dVdW�Z/dXdY�Z0dZd[�Z1d\d]�Z2d^d_�Z3d`da�Z4dbdc�Z5ddde�Z6dfdg�Z7dhdi�Z8djdk�Z9dldm�Z:dndo�Z;dpdq�Z<drds�Z=dtdu�Z>dvdw�Z?dxdy�Z@dzd{�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��ZQd�d��ZRd�d��ZSd�d��ZTeUd�d��d�d���ZVeUd�d��d�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�d��Zcd�d��Zdd�d��Zed�d��Zfd�d��Zgd�d��Zhd�d��Zid�d��Zjd�d��Zkd�S)��	PatchTestTcCsRt}|st}|jt|�|jt||��|jt|t��dS)N)rr�assertRaises�	TypeError�
assertTruer�assertFalser)rr�magic�	MockClassrrr�assertNotCallableYszPatchTest.assertNotCallablecsgGdd�dt��tj�dtj���fdd��}|��j�jtjd�dS)Nc@seZdZejZdS)z4PatchTest.test_single_patchobject.<locals>.SomethingN)rrrr	�Original�	attributerrrr�	SomethingdsrAr@cs�j�jtjd�dS)N�	unpatched)�assertEqualr@r	�Patchedr)rArrr�testgsz/PatchTest.test_single_patchobject.<locals>.testzpatch not restored)r#rr	rDrCr@r?)rrEr)rArr�test_single_patchobjectcs
-z!PatchTest.test_single_patchobjectcsdGdd�dt��tj�dd���fdd��}|��j�jtjd�dS)Nc@seZdZejZdS)z7PatchTest.test_patchobject_with_none.<locals>.SomethingN)rrrr	r?r@rrrrrAqsrAr@cs�j�jd�dS)NrB)�assertIsNoner@r)rArrrrEtsz2PatchTest.test_patchobject_with_none.<locals>.testzpatch not restored)r#rrCr@r	r?)rrEr)rArr�test_patchobject_with_noneps
*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)rrrr	r?r@�	Original2�next_attributerrrrrA~s	rAr@rJcs6�j�jtjd��j�jtjd�dS)NrB)rCr@r	rDrJ�Patched2r)rArrrrE�sz1PatchTest.test_multiple_patchobject.<locals>.testzpatch not restored)
r#rr	rDrKrCr@r?rJrI)rrEr)rArr�test_multiple_patchobject}s0z#PatchTest.test_multiple_patchobjectc
Cs]t}tdttj�dd��}z'tja|�|jttj�Wd|aXdS)Nz%s.somethingcSsdS)NrrrrrrE�sz8PatchTest.test_object_lookup_is_quite_lazy.<locals>.test)�	somethingrrr	�
Something2Zreplacement_valuerC)r�originalrErrr� 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)NrB)rC�PTModulerMr	rNr)rrrrE�sz"PatchTest.test_patch.<locals>.testzpatch not restoredz%s.something_elsecs6�jtjtjd��jtjtjd�dS)NrB)rCrQrMr	rN�something_else�
SomethingElser)rrrrE�sz%s.opencs#�jtdd�tjd�dS)N�filename�rzopen not patched)rC�openr	�Handler)rrrrE�s)rrr	rNrCrQrMrArSrRrrW�return_value�builtin_string�assertNotEqualrV)rrE�mockr)rr�
test_patch�s*(+	%zPatchTest.test_patchcsItdttj��fdd��}|��jtjjd�dS)Nz%s.SomeClass.class_attributecs �jtjjtjd�dS)NrB)rCrQr�class_attributer	�ClassAttributer)rrrrE�sz2PatchTest.test_patch_class_attribute.<locals>.testzpatch not restored)rrr	r^rGrQrr])rrEr)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)rrrr	r?rMrI�
something2rrrr�Test�s	rarMcs-�j|�jd��j|td�dS)Nz"Mock not passed into test functionz.patch with two arguments did not create a mock)rCrM�assertIsInstancer
)r[)rarrrrE�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)	rCr	�this1�this2r`rMrbr
rZ)rcrdZmock1Zmock2)ra�
outerMock1�
outerMock2rrrrE�s)r#rr	rcrd)rrEr)rarerfrr�"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>)rCrr:r�wibbler
r8�AttributeError)�
MockSomeClass)rrrrEsz,PatchTest.test_patch_with_spec.<locals>.test)rrr)rrEr)rr�test_patch_with_specs(zPatchTest.test_patch_with_speccs5tjtddt��fdd��}|�dS)Nr]rhcsI�jtj|��jttjjt���jtdd��dS)NcSs
tjjS)N)rr]rirrrrrjszDPatchTest.test_patchobject_with_spec.<locals>.test.<locals>.<lambda>)	rCrr]r:rrkr
r8rl)�
MockAttribute)rrrrEs

	z2PatchTest.test_patchobject_with_spec.<locals>.test)rr#r)rrEr)rr�test_patchobject_with_specs*z$PatchTest.test_patchobject_with_speccs6tdtddg��fdd��}|�dS)Nz%s.SomeClassrhrkcsC�jt|��jttjt���jtdd��dS)NcSstjS)N)rrirrrrrjszFPatchTest.test_patch_with_spec_as_list.<locals>.test.<locals>.<lambda>)rCrr:rrkr
r8rl)rm)rrrrEsz4PatchTest.test_patch_with_spec_as_list.<locals>.test)rr)rrEr)rr�test_patch_with_spec_as_lists+z&PatchTest.test_patch_with_spec_as_listcs8tjtdddg��fdd��}|�dS)Nr]rhrkcsI�jtj|��jttjjt���jtdd��dS)NcSs
tjjS)N)rr]rirrrrrj(szLPatchTest.test_patchobject_with_spec_as_list.<locals>.test.<locals>.<lambda>)	rCrr]r:rrkr
r8rl)ro)rrrrE"s

	z:PatchTest.test_patchobject_with_spec_as_list.<locals>.test)rr#r)rrEr)rr�"test_patchobject_with_spec_as_list!s-z,PatchTest.test_patchobject_with_spec_as_listcsFtdt�tdtddg��fdd���}|�dS)Nz%s.openz%s.SomeClassrhrkcsC�jt|��jttjt���jtdd��dS)NcSstjS)N)rrirrrrrj4szMPatchTest.test_nested_patch_with_spec_as_list.<locals>.test.<locals>.<lambda>)rCrr:rrkr
r8rl)rmZMockOpen)rrrrE/sz;PatchTest.test_nested_patch_with_spec_as_list.<locals>.test)rrYr)rrEr)rr�#test_nested_patch_with_spec_as_list-s
.z-PatchTest.test_nested_patch_with_spec_as_listcs3tdtdd��fdd��}|�dS)Nz%s.SomeClassrhTcs7�jt���j�jt�fdd��dS)Ncs�jS)N)rir)rmrrrj?szIPatchTest.test_patch_with_spec_as_boolean.<locals>.test.<locals>.<lambda>)rCrrkr8rl)rm)r)rmrrE9sz7PatchTest.test_patch_with_spec_as_boolean.<locals>.test)rr)rrEr)rr�test_patch_with_spec_as_boolean8s(z)PatchTest.test_patch_with_spec_as_booleancs5tjtddd��fdd��}|�dS)NrrhTcs7�jt���j�jt�fdd��dS)Ncs�jS)N)rir)rmrrrjKszPPatchTest.test_patch_object_with_spec_as_boolean.<locals>.test.<locals>.<lambda>)rCrrkr8rl)rm)r)rmrrEEsz>PatchTest.test_patch_object_with_spec_as_boolean.<locals>.test)rr#rQ)rrEr)rr�&test_patch_object_with_spec_as_booleanDs*z0PatchTest.test_patch_object_with_spec_as_booleancs3tdtdd��fdd��}|�dS)Nz%s.SomeClassrhTcsS�jt|t��|���j���j�jt�fdd��dS)Ncs�jS)N)rir)�instancerrrjYszVPatchTest.test_patch_class_acts_with_spec_is_inherited.<locals>.test.<locals>.<lambda>)r:rr
r>rkr8rl)rm)r)rvrrEQs
	
zDPatchTest.test_patch_class_acts_with_spec_is_inherited.<locals>.test)rr)rrEr)rr�,test_patch_class_acts_with_spec_is_inheritedPs(
z6PatchTest.test_patch_class_acts_with_spec_is_inheritedcsOtdttjdd��fdd��}|��jtdd��dS)Nz
%s.frooble�createTcs�jttj�dS)N)rC�froobler	�Froobler)rrrrE_szLPatchTest.test_patch_with_create_mocks_non_existent_attributes.<locals>.testcSstS)N)ryrrrrrjdszPPatchTest.test_patch_with_create_mocks_non_existent_attributes.<locals>.<lambda>)rrYr	rzr8�	NameError)rrEr)rr�4test_patch_with_create_mocks_non_existent_attributes^s.z>PatchTest.test_patch_with_create_mocks_non_existent_attributescsQtjtdtjdd��fdd��}|��jttd��dS)NryrxTcs�jtjtj�dS)N)rCrryr	rzr)rrrrEhszRPatchTest.test_patchobject_with_create_mocks_non_existent_attributes.<locals>.test)rr#rr	rzr;�hasattr)rrEr)rr�:test_patchobject_with_create_mocks_non_existent_attributesgs0zDPatchTest.test_patchobject_with_create_mocks_non_existent_attributescsoy3tdttj��fdd��}|�Wntk
rGYnX�jd��jtdd��dS)Nz
%s.frooblecs�jttj�dS)N)rCryr	rzr)rrrrErsz9PatchTest.test_patch_wont_create_by_default.<locals>.testz,Patching non existent attributes should failcSstS)N)ryrrrrrj|sz=PatchTest.test_patch_wont_create_by_default.<locals>.<lambda>)rrYr	rzrl�failr8r{)rrEr)rr�!test_patch_wont_create_by_defaultps(

z+PatchTest.test_patch_wont_create_by_defaultcsqy5tjtdtj��fdd��}|�Wntk
rIYnX�jd��jttd��dS)N�ordcs�jd�dS)Nz,Patching non existent attributes should fail)rr)rrrrE�sz?PatchTest.test_patchobject_wont_create_by_default.<locals>.testz,Patching non existent attributes should fail)	rr#rr	rzrlrr;r})rrEr)rr�'test_patchobject_wont_create_by_defaults*

z1PatchTest.test_patchobject_wont_create_by_defaultcCsbttd�dd��}ttd�dd��}|j|�d�|j|�d�dS)	Nz.ordcSsd|_td�S)N�e�c)rXr�)Zmock_ordrrr�test_ord�s	z>PatchTest.test_patch_builtins_without_create.<locals>.test_ordz.opencSs;|j}d|j_td�}|j�}|j�|S)N�abcdzdoesnotexists.txt)rX�readrV�close)Z	mock_open�mZfobj�datarrr�	test_open�s	
z?PatchTest.test_patch_builtins_without_create.<locals>.test_openr�r�)rrrC)rr�r�rrr�"test_patch_builtins_without_create�s
z,PatchTest.test_patch_builtins_without_createcspGdd�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)r	rDrrrrrj�sz:PatchTest.test_patch_with_static_methods.<locals>.<lambda>cs�j�j�tj�dS)N)rCr�r	rDr)r&rrr�	anonymous�sz;PatchTest.test_patch_with_static_methods.<locals>.anonymous)r#rr�rCr�r	r�)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&)rCr	r&r)rrrr��sz-PatchTest.test_patch_local.<locals>.anonymous)r	r&rr#rC)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&)rCr&r)r-rrrr��sz-PatchTest.test_patch_slots.<locals>.anonymous)r#r	r&rrC)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)rrrr	r?r@rrrrrA�srAcs:eZdZ��fdd�Z��fdd�ZdS)z7PatchTest.test_patchobject_class_decorator.<locals>.Foocs�j�jtjd�dS)NrB)rCr@r	rD)�
other_self)rArrr�test_method�szCPatchTest.test_patchobject_class_decorator.<locals>.Foo.test_methodcs�j�jtjd�dS)Nznon-test method patched)rCr@r	r?)r�)rArrr�not_test_method�szGPatchTest.test_patchobject_class_decorator.<locals>.Foo.not_test_methodN)rrrr�r�r)rArrrr&�sr&r@zpatch not restored)	r#rr	rDr�r�rCr@r?)rr&r)r)rArr� 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)rrrr	r?r@rrrrrA�srAcs4eZdZ�fdd�Z�fdd�ZdS)z1PatchTest.test_patch_class_decorator.<locals>.Foocs�jtj|d�dS)NrB)rCrQrM)r�Zmock_something)rrrr��sz=PatchTest.test_patch_class_decorator.<locals>.Foo.test_methodcs�jtjtjd�dS)Nznon-test method patched)rCrQrMr	rA)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�rCr@r	r?rQrMrA)rrAr&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)rrrr	r?r@rIrJrrrrrA�s	rAr@cs�j�jtjd�dS)NrB)rCr@r	rDr)rArrrrE�sz.PatchTest.test_patchobject_twice.<locals>.testzpatch not restored)r#rr	rDrCr@r?)rrEr)rArr�test_patchobject_twice�s0z PatchTest.test_patchobject_twicecs�dt�ddi��j�}tj���fdd��}|��j�|�tj�ddi���fdd��}|��j�|�tj�d
g���fd	d��}|��j�|�dS)N�initial�otherrMcsd�d<�d=d�d<dS)N�r'r�zsomething elser�rr)r-rrrE	s
z'PatchTest.test_patch_dict.<locals>.testr'r.cs.�jt��d��j�dd�dS)Nr�r'r.)rC�lenr)r-rrrrEscs.�jt��d��j�dd�dS)Nr�r'r.)rCr�r)r-rrrrEs)r'r.)r#�copyr�dictrC)rrOrEr)r-rr�test_patch_dicts!-*zPatchTest.test_patch_dictcs�t��t��d<d�d<�jj�}tj���fdd��}|��j�j|�tj�ddi���fdd��}|��j�j|�dS)	Nr�rMr�csd�d<�d=d�d<dS)Nr�r'r�zsomething elser�rr)r-rrrE-s
z=PatchTest.test_patch_dict_with_container_object.<locals>.testr'r.cs1�jt�j�d��j�dd�dS)Nr�r'r.)rCr�r1r)r-rrrrE7s)r0r#r1r�rr�rC)rrOrEr)r-rr�%test_patch_dict_with_container_object&s	

!-z/PatchTest.test_patch_dict_with_container_objectcs�dt�ddi��j�}tj�dd���fdd��}|��j�|�tj�dd	idd���fd
d��}|��j�|�tj�dgdd���fdd��}|��j�|�dS)
Nr�r�rM�clearTcs(�j�i�d�d<d�d<dS)Nr�r'zsomething elser�)rCr)r-rrrrEEs
z2PatchTest.test_patch_dict_with_clear.<locals>.testr'r.cs�j�ddi�dS)Nr'r.)rCr)r-rrrrEOscs�j�ddi�dS)Nr'r.)rCr)r-rrrrEWs)r'r.)r#r�rr�rC)rrOrEr)r-rr�test_patch_dict_with_clearAs*30z$PatchTest.test_patch_dict_with_clearcs�t��t��d<d�d<�jj�}tj�dd���fdd��}|��j�j|�tj�dd	idd���fd
d��}|��j�j|�dS)Nr�rMr�r�Tcs+�j�ji�d�d<d�d<dS)Nr�r'zsomething elser�)rCr1r)r-rrrrEgs
zGPatchTest.test_patch_dict_with_container_object_and_clear.<locals>.testr'r.cs�j�jddi�dS)Nr'r.)rCr1r)r-rrrrEqs)r0r#r1r�rr�rC)rrOrEr)r-rr�/test_patch_dict_with_container_object_and_clear`s	

*3z9PatchTest.test_patch_dict_with_container_object_and_clearcCsi}tdtt��tdtt�dd�tjtt��tj|�dd�����}|j|jd�dS)Nz%s.SomeClass�autospecTcSsdS)Nrrrrr�	some_name}sz0PatchTest.test_name_preserved.<locals>.some_namer�)rrr#rr�rC)rr-r�rrr�test_name_preservedzs$zPatchTest.test_name_preservedcCski}tj|ddi�dd��}y|�Wntk
rIYnX|jd�|j|i�dS)Nr'r.cSstd��dS)NZKonrad)r{rrrrrE�sz1PatchTest.test_patch_with_exception.<locals>.testzNameError not raised by test)rr�r{rrC)rr-rErrr�test_patch_with_exception�s$

z#PatchTest.test_patch_with_exceptioncs5tjdddi��fdd��}|�dS)Nz
os.environ�
konrad_delongz
some valuecs�jdtj�dS)Nr�)�assertIn�os�environr)rrrrE�sz3PatchTest.test_patch_dict_with_string.<locals>.test)rr�)rrEr)rr�test_patch_dict_with_string�s*z%PatchTest.test_patch_dict_with_stringcs�Gdd�dt��G���fdd�dt���j�jd�d��j��j�jd�d��j���}�j|jd�d�|j��j|jd�d�|j�dS)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)rArrr�klass�sz8PatchTest.test_patch_descriptor.<locals>.Something.klasscSs|S)Nr)�argrrr�static�sz9PatchTest.test_patch_descriptor.<locals>.Something.staticcs�j|��dS)N)r�)r�)rArrr�
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�rArrrrA�srAZf00)r#rCr�r�r�r�)rrMr)r�rArr�test_patch_descriptor�s"

	
zPatchTest.test_patch_descriptorcCs�tdtdt�dd��}|jt|�tjtddt�dd��}|jt|�tdtdd�dd��}|jt|�tjtddd�d	d��}|jt|�dS)
Nz%s.SomeClass�spec_setcSs
d|_dS)Nr-)�z)r=rrrrE�sz+PatchTest.test_patch_spec_set.<locals>.testrcSs
d|_dS)Nr-)r�)r=rrrrE�sTcSs
d|_dS)Nr-)r�)r=rrrrE�scSs
d|_dS)Nr-)r�)r=rrrrE�s)rrrr8rlr#r)rrErrr�test_patch_spec_set�s"$"$zPatchTest.test_patch_spec_setcCs6tdtdd�dd��}|jt|�dS)Nz%s.SomeClassr�TcSs|�}d|_dS)Nr-)r�)r=rvrrrrE�s	z-PatchTest.test_spec_set_inherit.<locals>.test)rrr8rl)rrErrr�test_spec_set_inherit�s"zPatchTest.test_spec_set_inheritcCsxt}tdt�}|jt|�|j�}z$|j||�|jt|�Wd|j�X|jt|�dS)Nz%s.something)rMrrr��start�assertIsNot�stop)rrO�patcherr[rrr�test_patch_start_stop�szPatchTest.test_patch_start_stopcCs)ttdd�}|jt|j�dS)Nr+r�)r�foo_namer8�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)NrMr-)rMrr#rQr�r�rCr�)rrOr�Zreplacedrrr�test_patchobject_start_stopsz%PatchTest.test_patchobject_start_stopcCs�ddi}|j�}tj|dgdd�}|j||�|j�z|j|ddi�Wd|j�X|j||�dS)Nr-r+�spam�eggsr�T)r�r�)r�rr�rCr�r�)r�drOr�rrr�test_patch_dict_start_stop
s
z$PatchTest.test_patch_dict_start_stopcs�|�ddi��j�}G��fdd�dt�}tj�ddidd�|�}|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�ddi�dS)Nr-r+)rC)r)r��thisrr�
test_first!szBPatchTest.test_patch_dict_class_decorator.<locals>.Test.test_firstcs�j�ddi�dS)Nr-r+)rC)r)r�r�rr�test_second#szCPatchTest.test_patch_dict_class_decorator.<locals>.Test.test_secondN)rrrr�r�r)r�r�rrra srar-r+r�T)r�r#rr�rCr�r�)rrOrarEr)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-rrrrrA;srAc@seZdZdZdS)z4PatchTest.test_get_only_proxy.<locals>.SomethingElser-N)rrrr-rrrrrS=srSr-r+cs�j�jd�dS)Nr+)rCr-r)�proxyrrrrECsz+PatchTest.test_get_only_proxy.<locals>.test)r#r%rrCr-�assertNotIn�__dict__)rrArS�thingrEr)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-rrrrrAMsrAc@seZdZdZdS)z:PatchTest.test_get_set_delete_proxy.<locals>.SomethingElser-N)rrrr-rrrrrSOsrSr$Fr-r+cs�j�jd�dS)Nr+)rCr-r)r�rrrrEUsz1PatchTest.test_get_set_delete_proxy.<locals>.test)r#r%rrCr-r�r�)rrArSr�rEr)r�rr�test_get_set_delete_proxyLs*z#PatchTest.test_get_set_delete_proxycCs�dtdddt�i}tt|�}|j�}|j�|jt|�|j|jj	�d�|j
|jt�dS)N�side_effectzfoo.bar.return_value�!r-)�KeyErrorr
rr�r�r�r8rCr-r+rb)r�kwargsr�r[rrr�test_patch_keyword_args^s
z!PatchTest.test_patch_keyword_argscCs�dtdddt�i}tjtd|�}|j�}|j�|jt|�|j|j	j
�d�|j|j	t�dS)Nr�zfoo.bar.return_valuer�r-r))r�r
rr#r&r�r�r8rCr-r+rb)rr�r�r[rrr�test_patch_object_keyword_argsks
z(PatchTest.test_patch_object_keyword_argscCs�ddi}|j�}tj|dddddd�}|j�z)|j|tdddddd��Wd|j�X|j||�dS)Nr-r+r��Zbaz�)r�rr�r�rCr�)rrOr�r�rrr�test_patch_dict_keyword_argsxs!
)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(�sz-PatchTest.test_autospec.<locals>.Boo.__init__cSsdS)Nr)rr'rrrr)�sz&PatchTest.test_autospec.<locals>.Boo.fcSsdS)Nr)rrrrr*�sz&PatchTest.test_autospec.<locals>.Boo.gr+c@seZdZdd�ZdS)z(PatchTest.test_autospec.<locals>.Boo.BarcSsdS)Nr)rrrrr'�sz*PatchTest.test_autospec.<locals>.Boo.Bar.aN)rrrr'rrrrr,�sr,N)	rrrr(r)r*r-r#r,rrrr�Boo�s
r�cs+|d�|jd��jt|�dS)N�)�assert_called_withr8r9)r[)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�r8r9r*rlrr-�lowerr,r')r[)rrr�_test2�s(






z'PatchTest.test_autospec.<locals>._test2cs8�|��|��|d���j|t�|S)Nr�)r�r&)r[)r�r�rrrr/�s


z)PatchTest.test_autospec.<locals>.functionr�Tr&)r#rr�r�r&�sys�modulesr)rr�r/rEr[�moduler)r�r�rr�
test_autospec�s
	
	zPatchTest.test_autospeccs3tdtdd��fdd��}|�dS)Nz%s.functionr�Tcs^td�tjd�tdd�tjdd��jtt��jtttd�dS)Nr�r�r�r-)r/r�r8r9rlr)r[)rrrrE�s


z.PatchTest.test_autospec_function.<locals>.test)rr)rrEr)rr�test_autospec_function�s(
z PatchTest.test_autospec_functioncCsEtdtdddd�dd��}|�}|j|d�dS)Nz%s.functionr�TrXr�cSs
tdd�S)Nr�r�)r/)Z
mock_functionrrrrE�sz.PatchTest.test_autospec_keywords.<locals>.test)rrrC)rrE�resultrrr�test_autospec_keywords�s	z PatchTest.test_autospec_keywordscCsqtdtdddd�}|jt|j�tjt}tj|ddddd�}|jt|j�dS)Nz%s.function�newr�r�Tr/)rrr8r9r�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�rbr��listr�)rr,r�r[rrr�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�rbr�)rZFooClassr�r[rrr�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�r[rrr�test_autospec_names#zPatchTest.test_autospec_namec
Cs�tjtdt��dd��}y|�Wntj�}YnXtjddd�}|j||�}|jd|�dS)Nr)cSs
t�dS)N)�AssertionErrorrrrrrEsz'PatchTest.test_tracebacks.<locals>.testrzraise AssertionError)	rr#r&r��exc_info�unittestZTextTestResultZ_exc_info_to_stringr�)rrE�errr��	tracebackrrr�test_tracebackss$zPatchTest.test_tracebackscCsvttdt�}|j�}|j�|j�}|j�|j||�x!||fD]}|j|�q[WdS)N�new_callable)rr�rr�r�r�r>)rr��m1�m2r[rrr�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&rr�r�r�r>)rr�r�r�r[rrr�test_new_callable_patch_object0s

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��typerCr�r�r�)rr�r�r)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(Osz6PatchTest.test_new_callable_spec.<locals>.Bar.__init__)rrrr�r(r)r,rrr,Msr,r�rhr�)r#rr�r�rCr�r�r�)rr�r)r,r�test_new_callable_specLs
 
 z PatchTest.test_new_callable_specc
Cs|dt}t|dt�}|jt|j�t|dtdd�}|j�}z|j|dd�Wd|j�XdS)Nz	%s.weeeeer�rxTr<F)r�rrr8rlr�r>r�)rZnon_existent_attr�pr�rrr�test_new_callable_createas
	z"PatchTest.test_new_callable_createc	CsN|jtttdt�dt�|jttjtddt�dt�dS)Nr�r�r))r8�
ValueErrorrr�r#r
r&)rrrr�'test_new_callable_incompatible_with_newos
z1PatchTest.test_new_callable_incompatible_with_newc	CsH|jtttdtdd�|jttjtddtdd�dS)Nr�r�Tr))r8rrr�r
r#r&)rrrr�,test_new_callable_incompatible_with_autospecysz6PatchTest.test_new_callable_incompatible_with_autospecc	
Cs�Gdd�dt�}tttt|f}x}|D]u}xldD]d}|di}ttd||�}|j�}z#|j}|jt	t
|d�Wd|j�Xq?Wq2WdS)	Nc@seZdZdS)z>PatchTest.test_new_callable_inherit_for_mocks.<locals>.MockSubN)rrrrrrr�MockSub�srrhr�Tr��x)zspeczspec_set)rrrr
rr�r�rXr8rlrr�)	rrZMockClassesZKlassr�r�rr�rvrrr�#test_new_callable_inherit_for_mocks�s

	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)rh)rrhrrrr(�szGPatchTest.test_new_callable_inherit_non_mock.<locals>.NotAMock.__init__N)rrrr(rrrr�NotAMock�sr
r�rhTrX)
r#rr�r�r:rr8rlrr�rCrhr&)rr
rr�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�rbr)r�mock_foo)rOrErrr��szDPatchTest.test_new_callable_class_decorating.<locals>.SomeTest._testcSs|j|�dS)N)r�)rrrrr�test_two�szGPatchTest.test_new_callable_class_decorating.<locals>.SomeTest.test_twocSs|j|�dS)N)r�)rrrrr�test_one�szGPatchTest.test_new_callable_class_decorating.<locals>.SomeTest.test_oneN)rrrr�r
rr)rOrErr�SomeTest�srr�)r&r#rr�rrr
r�)rrr)rOrEr�"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&rCr)r*r)�original_foorrrrE�sz+PatchTest.test_patch_multiple.<locals>.test)
r&r)r*r�multipler�r�r�rCr�)r�
original_f�
original_gZpatcher1Zpatcher2r�rEr)rrr�test_patch_multiple�s"		
0zPatchTest.test_patch_multiplecCs0|jttjt�|jttjt�dS)N)r8rrrr�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)rCr*r-r:rr
)r)r-)rrrrrE�sz8PatchTest.test_patch_multiple_create_mocks.<locals>.test)r&r)r*rrr�r
rC)rrrrEr)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*rCr))r*)rrrrE�szHPatchTest.test_patch_multiple_create_mocks_different_order.<locals>.test)	r&r)r*rr#�attribute_namer
�additional_patchersrC)rrrr�r�rEr)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�test1sz?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test1cs�||�dS)Nr)r*r�)r�rr�test2sz?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-)
�popr;r�r&r)r*r-r:rr
)r*r�r)r-)rrrrr� s
z?PatchTest.test_patch_multiple_stacked_decorators.<locals>._test)r&r)r*rrr�r
rC)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�rC�setr�r-r:rr
r�)rrrrr�r�r)r-rrr�(test_patch_multiple_create_mocks_patcher4s"		!

"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)rCr*r-r:rr
)rr)r-)rrErrr�UszFPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest._testcSs|j||�dS)N)r�)rr)r-rrrr
]szIPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest.test_twocSs|j||�dS)N)r�)rr)r-rrrr_szIPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest.test_oneN)rrrr�r
rr)rrErrrSsrr)r*r�r-)r&r)r*r#rrr�r
rr
rC)rrrrr�r)rrEr�$test_patch_multiple_decorating_classMs				

z.PatchTest.test_patch_multiple_decorating_classcCs�tjtdd�}|jt|j�tjtdddd�}|j�z|jtjd�Wd|j�X|j	t
td��dS)N�blamrxT)rrr&r8rlr�rCr#r�r;r})rr�rrr�test_patch_multiple_createns
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�r�)rrr&r
r�rCr-r'r.r�r8rlrr�)rr�r�rrr�test_patch_multiple_spec_set|s! 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�Thing�sr&r)r*r�)r#rrr&r
r�r�r)r*rbr�r�)rr&r�r�rrr� test_patch_multiple_new_callable�s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#r8rlrC)rrrr)r*r+�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)r{rrrrr.�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#r8r{rC)	rrrrr.r)r*r+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*r(cSsdS)Nrrrrrr,�sz3PatchTest.test_patch_multiple_failure.<locals>.func)
r&r)r*rr#rrr8rlrC)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.)r{rrrrr.�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#rrr8r{rC)
rrrrr.r�r0r1r2r,rrr�(test_patch_multiple_new_callable_failure�s"							z2PatchTest.test_patch_multiple_new_callable_failurecs�x|ttfD]n}td|fddi�}|��tj�dd���fdd��}|��j�jd�q
WdS)Nr&�fishZtastyznearly gonecs�j�jd�dS)Nznearly gone)rCr5r)r-rrrrEsz=PatchTest.test_patch_multiple_string_subclasses.<locals>.test)�str�unicoder�rrrCr5)r�baser&rEr)r-rr�%test_patch_multiple_string_subclassess	*z/PatchTest.test_patch_multiple_string_subclasseszmock.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>.FoorOcSs|jS)N)r�)rrrr�foo_one#sz5PatchTest.test_patch_test_prefix.<locals>.Foo.foo_onecSs|jS)N)r�)rrrr�foo_two%sz5PatchTest.test_patch_test_prefix.<locals>.Foo.foo_twocSs|jS)N)r�)rrrrr'sz6PatchTest.test_patch_test_prefix.<locals>.Foo.test_onecSs|jS)N)r�)rrrrr
)sz6PatchTest.test_patch_test_prefix.<locals>.Foo.test_twoN)rrrr�r:r;rr
rrrrr& s
r&r��changedrO)r#rrCr:r;rr
)rr&r-rrr�test_patch_test_prefixs	z PatchTest.test_patch_test_prefixr+cs�G�fdd�dt�}ddi�tj�dd�|�}|�}|j|j�ddi�|j|j�ddi�|j|j�ddi�|j|j�ddi�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_one8sz:PatchTest.test_patch_dict_test_prefix.<locals>.Foo.bar_onecs
t��S)N)r�)r)r>rr�bar_two:sz:PatchTest.test_patch_dict_test_prefix.<locals>.Foo.bar_twocs
t��S)N)r�)r)r>rrr<sz;PatchTest.test_patch_dict_test_prefix.<locals>.Foo.test_onecs
t��S)N)r�)r)r>rrr
>sz;PatchTest.test_patch_dict_test_prefix.<locals>.Foo.test_twoN)rrrr?r@rr
r)r>rrr&7sr&�keyrOr<)r#rr�rCr?r@rr
)rr&r-r)r>r�test_patch_dict_test_prefix5s
	z%PatchTest.test_patch_dict_test_prefixcCs�x�d
D]�}tdt|di�}|j�}zh|jdt|��|jdt|j��|jdt|���|jd	t|�j��Wd|j�XqWdS)Nrhr�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�rr�rrr�test_patch_with_spec_mock_reprKs
		z(PatchTest.test_patch_with_spec_mock_reprc
Csutddd�}|j�}zE|jdt|jj���|jdt|j�j���Wd|j�XdS)Nzmock.tests.supportr�Tz" name='support.SomeClass.wibble()'z$ name='support.SomeClass().wibble()')rr�r�r�rrkr�)rrr�rrr�test_patch_nested_autospec_reprZs		z)PatchTest.test_patch_nested_autospec_reprcCsZxSdD]K}tdt|di�}|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)Nrhr�r�z%s.SomeClassT)zspeczautospeczspec_set)
rrr�rkrrCZ
mock_callsZmethod_calls�appendr�)rr�rr�Zkallsr�rrr�test_mock_calls_with_patchfs&

	
 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�rrr8�ImportErrorr�rZsquozzr�rC)rZp1rGrrr�test_patch_imports_lazily�s		
	

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�holder�srKcs1eZdZddd�fdd�ZeZdS)zBPatchTest.test_patch_propogrates_exc_on_exit.<locals>.custom_patchNcs,tj||||�|||f�_dS)N)r�__exit__r�)r�etype�val�tb)rKrrrL�szKPatchTest.test_patch_propogrates_exc_on_exit.<locals>.custom_patch.__exit__)rrrrLr�r)rKrr�custom_patch�srPc
s4t|�\}}�||tdddddi�	S)NF)rr
)�target�getterr@)rPrr�with_custom_patch�szGPatchTest.test_patch_propogrates_exc_on_exit.<locals>.with_custom_patchz
squizz.squozzcSs
t�dS)N)r�)r[rrrrE�sz:PatchTest.test_patch_propogrates_exc_on_exit.<locals>.testrr�zexception value not propgatedr�z!exception traceback not propgated)rr8r�r�r�ZassertIsNotNone)rrSrEr)rPrKr�"test_patch_propogrates_exc_on_exit�sz,PatchTest.test_patch_propogrates_exc_on_exitcCs�x�d	D]}}tdtdd|di�}|jt|j�|jtdd��ttdd|di�}|j�|j�qWdS)
Nrhr�r�z%s.doesnotexistrxTcSstS)N)�doesnotexistrrrrrj�sz1PatchTest.test_create_and_specs.<locals>.<lambda>)zspeczspec_setzautospec)rrr8r9r�r{�MODNAMEr�)r�kwargrrrr�test_create_and_specs�s

zPatchTest.test_create_and_specscCs�t}xLdD]D}ttdd|di�}|jt|j�|jt|�q
WxLdD]D}ttdd|di�}|jt|j�|jt|�q\WxLdD]D}ttdd|di�}|jt|j�|jt|�q�WdS)Nrhr�r�r)�spec�spec_set)rYr�)rZr�)rQrrVr8r9r�r�)rrOrWrrrr�test_multiple_specs�s


zPatchTest.test_multiple_specsc
CsPttdddddd�}|j�}z|jd|_Wd|j�XdS)NrhFr�r�r�)rrVr�Zdoes_not_existr�)rrr[rrr� test_specs_false_instead_of_none�s
z*PatchTest.test_specs_false_instead_of_nonecCs^xWdD]O}tt|di�}|j�}z|jtt|d�Wd|j�XqWdS)Nrhr�r�rZdoesnotexit)zspeczautospeczspec_set)rrVr�r8rlrr�)rrWrr�rrr�test_falsey_spec�s
zPatchTest.test_falsey_specc
Cs}xvdD]n}ttdd|di�}|j�}z3|jtt|dd�|jtt|d�Wd|j�XqWdS)Nrhr�r�TrUrM)zspeczautospec)rrVr�r8rlrrr�)rrWrr�rrr�test_spec_set_true�s

zPatchTest.test_spec_set_truec
CsMd}ttd|�}|j�}z|jt|��Wd|j�XdS)N�__call__rh)z__call__)rrVr�r:rr�)rrhrr�rrr�test_callable_spec_as_list�sz$PatchTest.test_callable_spec_as_listc
CsMd}ttd|�}|j�}z|jt|��Wd|j�XdS)Nr-r+rh)zfoozbar)rrVr�r;rr�)rrhrr�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)rerrdrr�patched	s
z-PatchTest.test_patch_stopall.<locals>.patched)	r�rdrercrrMr�rRr�)rrcrfr)rerrdr�test_patch_stopalls			$zPatchTest.test_patch_stopallcCs)td�t�}|j|jt�dS)Nzsys.modules)rr/r��__wrapped__)r�	decoratedrrr�test_wrapped_patchszPatchTest.test_wrapped_patchcCs;td�t�}td�|�}|j|jt�dS)Nzsys.modules)rr/r�rh)rrirrr� test_wrapped_several_times_patchsz*PatchTest.test_wrapped_several_times_patchcCs/tjtd�t�}|j|jt�dS)Nr�)rr#r�r/r�rh)rrirrr�test_wrapped_patch_objectsz#PatchTest.test_wrapped_patch_objectcCs,tjd�t�}|j|jt�dS)Nzsys.modules)rr�r/r�rh)rrirrr�test_wrapped_patch_dict$sz!PatchTest.test_wrapped_patch_dictcCs2tjddi�t�}|j|jt�dS)Nr�r�)rrr/r�rh)rrirrr�test_wrapped_patch_multiple)sz%PatchTest.test_wrapped_patch_multiplecsog�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)rE�superr�)r)�	__class__r@�mypatch�stoppedrrr�4s
zDPatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.mypatch.stop)rrrr�r)r@rtru)rsrrt3srtcs�S)Nrr)r�rrrj7sz@PatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.<lambda>F)r)r@)rur�)r@rtr�	get_patch2s"z.PatchTest.test_stopall_lifo.<locals>.get_patchcs"g|]}�|�j��qSr)r�)�.0rN)rvrr�
<listcomp>9s	z/PatchTest.test_stopall_lifo.<locals>.<listcomp>rorprq)zoneztwozthree)r#rrbrC)rr)rvrur�r�test_stopall_lifo-s
zPatchTest.test_stopall_lifoc&Cs�ddd�}tj|dd��|j|�d�WdQRX|j|�d�tj|dd��|j|jd�WdQRX|j|jd�tj|d	d
��|j|jd
�WdQRX|j|jt�t|jd�rBtj|dtdg���!|j|j	tdg��WdQRX|j|j	t��t|jd
�r�t
d�}tj|d
tdg���|j|�d�WdQRX|j|�d�dS)NrcSs|S)�TESTr)rrrrr-@sz)PatchTest.test_special_attrs.<locals>.foo�__defaults__r��__doc__ZFUNrzrZ
testpatch2�__annotations__�s�__kwdefaults__zlambda *a, x=0: xr)r�)r~r�)r~r�)rr�)rr#rCr|rrr}�test_special_attrsr�r}�eval)rr-rrrr�?s&#zPatchTest.test_special_attrsN)lrrrr>rFrHrLrPr\r_rgrnrprqrrrsrtrurwr|r~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�ZexpectedFailurer�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr	rrrrrrrr!r"r$r%r'r-r/r3r4r9rr=rBrCrDrFrJrTrXr[r\r]r^r`rargrjrkrlrmrnryr�rrrrr7Ws�


+*

		
!
+	



G	




+!!



r7�__main__)-r�r�ZsixZ	unittest2r�Z
mock.testsrZmock.tests.supportrrrr[rrrr	r
rrr
rZ	mock.mockrrrYZPY3r6r7r�rrQrVr%rArMrSrRr#r&r�r/r0ZTestCaser7�mainrrrr�<module>s<F	

		
�������


Filemanager

Name Type Size Permission Actions
__init__.cpython-35.opt-1.pyc File 95 B 0644
__init__.cpython-35.pyc File 95 B 0644
__main__.cpython-35.opt-1.pyc File 569 B 0644
__main__.cpython-35.pyc File 569 B 0644
support.cpython-35.opt-1.pyc File 1.17 KB 0644
support.cpython-35.pyc File 1.17 KB 0644
testcallable.cpython-35.opt-1.pyc File 5.98 KB 0644
testcallable.cpython-35.pyc File 5.98 KB 0644
testhelpers.cpython-35.opt-1.pyc File 36.11 KB 0644
testhelpers.cpython-35.pyc File 36.11 KB 0644
testmagicmethods.cpython-35.opt-1.pyc File 22.61 KB 0644
testmagicmethods.cpython-35.pyc File 22.61 KB 0644
testmock.cpython-35.opt-1.pyc File 49.25 KB 0644
testmock.cpython-35.pyc File 49.25 KB 0644
testpatch.cpython-35.opt-1.pyc File 71.85 KB 0644
testpatch.cpython-35.pyc File 71.85 KB 0644
testsentinel.cpython-35.opt-1.pyc File 1.38 KB 0644
testsentinel.cpython-35.pyc File 1.38 KB 0644
testwith.cpython-35.opt-1.pyc File 10.14 KB 0644
testwith.cpython-35.pyc File 10.14 KB 0644