HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/unittest/test/testmock/__pycache__/testpatch.cpython-37.pyc
B

"��g���@s�ddlZddlZddlZddlmZddlmZmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZmZmZmZdZejeZdeZdd	d
�Ze
jae
jZGdd�de �Z!d
eZ"e!fdd�Z#Gdd�de �Z$Gdd�dej%�Z&edkr�e�'�dS)�N)�support)�	SomeClass�is_instance)�uncache)�NonCallableMock�
CallableMixin�sentinel�	MagicMock�Mock�NonCallableMagicMock�patch�_patch�DEFAULT�call�_get_target�builtinsz%s.PTModuleTcsBG�fdd�dt�}|s<�fdd�}�fdd�}||_||_|�S)NcseZdZ�fdd�ZdS)z_get_proxy.<locals>.Proxycs
t�|�S)N)�getattr)�self�name)�obj��</usr/local/lib/python3.7/unittest/test/testmock/testpatch.py�__getattr__sz%_get_proxy.<locals>.Proxy.__getattr__N)�__name__�
__module__�__qualname__rr)rrr�Proxysrcst�||�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�ZdZedd	��Ze	d
d��Z
Gdd
�d
e�ZdS)�FoocCsdS)Nr)r�arrr�__init__.szFoo.__init__cCsdS)Nr)rr&rrr�f0szFoo.fcCsdS)Nr)rrrr�g2szFoo.g�barcCsdS)N�rrrrr�
static_method6szFoo.static_methodcCsdS)N�*r)�clsrrr�class_method:szFoo.class_methodc@seZdZdd�ZdS)zFoo.BarcCsdS)Nr)rrrrr&?sz	Foo.Bar.aN)rrrr&rrrr�Bar>sr0N)
rrrr'r(r)�foo�staticmethodr,�classmethodr/r"r0rrrrr%-sr%z%s.FoocCsdS)Nr)r&�brrr�functionEsr5c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�	ContainercCs
i|_dS)N)�values)rrrrr'JszContainer.__init__cCs
|j|S)N)r7)rrrrr�__getitem__MszContainer.__getitem__cCs||j|<dS)N)r7)rrrrrr�__setitem__PszContainer.__setitem__cCs|j|=dS)N)r7)rrrrr�__delitem__SszContainer.__delitem__cCs
t|j�S)N)�iterr7)rrrr�__iter__VszContainer.__iter__N)rrrr'r8r9r:r<rrrrr6Is
r6c@sJeZdZd�dd�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��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVeWd�d��d�d���ZXeWd�d��d�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�S)��	PatchTestTcCs<t}|st}|�t|�|�t||��|�t|t��dS)N)rr�assertRaises�	TypeError�
assertTruer�assertFalser)rr�magic�	MockClassrrr�assertNotCallable]szPatchTest.assertNotCallablecsJGdd�dt��t��dtj���fdd��}|����jtjd�dS)Nc@seZdZejZdS)z4PatchTest.test_single_patchobject.<locals>.SomethingN)rrrr�Original�	attributerrrr�	SomethinghsrGrFcs���jtjd�dS)N�	unpatched)�assertEqualrFr�Patchedr)rGrrr�testksz/PatchTest.test_single_patchobject.<locals>.testzpatch not restored)r"rrrJrIrFrE)rrKr)rGrr�test_single_patchobjectgs
z!PatchTest.test_single_patchobjectc	Cs,d}|�t|��t�dd�WdQRXdS)Nz>'Something' must be the actual object to be patched, not a strrGZdo_something)ZassertRaisesRegexr?rr")r�msgrrr�&test_patchobject_with_string_as_targetssz0PatchTest.test_patchobject_with_string_as_targetcsHGdd�dt��t��dd���fdd��}|����jtjd�dS)Nc@seZdZejZdS)z7PatchTest.test_patchobject_with_none.<locals>.SomethingN)rrrrrErFrrrrrGysrGrFcs���jd�dS)NrH)�assertIsNonerFr)rGrrrrK|sz2PatchTest.test_patchobject_with_none.<locals>.testzpatch not restored)r"rrIrFrrE)rrKr)rGrr�test_patchobject_with_nonexs
z$PatchTest.test_patchobject_with_nonecslGdd�dt��t��dtj�t��dtj���fdd���}|����jtjd����jtj	d�dS)Nc@seZdZejZejZdS)z6PatchTest.test_multiple_patchobject.<locals>.SomethingN)rrrrrErF�	Original2�next_attributerrrrrG�srGrFrRcs(���jtjd����jtjd�dS)NrH)rIrFrrJrR�Patched2r)rGrrrrK�sz1PatchTest.test_multiple_patchobject.<locals>.testzpatch not restored)
r"rrrJrSrIrFrErRrQ)rrKr)rGrr�test_multiple_patchobject�s z#PatchTest.test_multiple_patchobjectcCsFt}tdttj�dd��}ztja|�|�ttj�Wd|aXdS)Nz%s.somethingcSsdS)NrrrrrrK�sz8PatchTest.test_object_lookup_is_quite_lazy.<locals>.test)�	somethingrrr�
Something2Zreplacement_valuerI)r�originalrKrrr� test_object_lookup_is_quite_lazy�sz*PatchTest.test_object_lookup_is_quite_lazycs�tdttj��fdd��}|���tjtjd�tdttj�tdttj��fdd���}��tjtjd���tj	tjd�|���tjtjd���tj	tjd�t
�}tj|_tdt
|��fdd��}|�|���t|d�dS)	Nz%s.somethingcs��tjtjd�dS)NrH)rI�PTModulerUrrVr)rrrrK�sz"PatchTest.test_patch.<locals>.testzpatch not restoredz%s.something_elsecs(��tjtjd���tjtjd�dS)NrH)rIrYrUrrV�something_else�
SomethingElser)rrrrK�sz%s.opencs��tdd�tjd�dS)N�filename�rzopen not patched)rI�openr�Handler)rrrrK�s)rrrrVrIrYrUrGr[rZr
r_�return_value�builtin_string�assertNotEqualr^)rrK�mockr)rr�
test_patch�s*zPatchTest.test_patchcs6tdttj��fdd��}|���tjjd�dS)Nz%s.SomeClass.class_attributecs��tjjtjd�dS)NrH)rIrYr�class_attributer�ClassAttributer)rrrrK�s
z2PatchTest.test_patch_class_attribute.<locals>.testzpatch not restored)rrrrfrOrYrre)rrKr)rr�test_patch_class_attribute�s

z$PatchTest.test_patch_class_attributecs�Gdd�dt��t��d���fdd��}|�t��d�t��d�����fdd���}d��|tjtj�\��|tjtj�dS)Nc@seZdZejZejZdS)z:PatchTest.test_patchobject_with_default_mock.<locals>.TestN)rrrrrErUrQ�
something2rrrr�Test�srirUcs"��|�jd���|td�dS)Nz"Mock not passed into test functionz.patch with two arguments did not create a mock)rIrU�assertIsInstancer	)rc)rirrrrK�s
z:PatchTest.test_patchobject_with_default_mock.<locals>.testrhcs���|tjd���|tjd���|�jd���|�jd���|td���|td����|d����|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)	rIr�this1�this2rhrUrjr	rb)rkrlZmock1Zmock2)ri�
outerMock1�
outerMock2rrrrK�s



)r"rrrkrl)rrKr)rirmrnrr�"test_patchobject_with_default_mock�s
 z,PatchTest.test_patchobject_with_default_mockcs&tdttd��fdd��}|�dS)Nz%s.SomeClass)�speccs2��t|���ttjt����tdd��dS)NcSstjS)N)r�
not_wibblerrrr�<lambda>�z>PatchTest.test_patch_with_spec.<locals>.test.<locals>.<lambda>)rIrr@r�wibbler	r>�AttributeError)�
MockSomeClass)rrrrK
sz,PatchTest.test_patch_with_spec.<locals>.test)rrr)rrKr)rr�test_patch_with_spec	szPatchTest.test_patch_with_speccs&tjtdtd��fdd��}|�dS)Nre)rpcs6��tj|���ttjjt����tdd��dS)NcSstjjS)N)rrerqrrrrrrrszDPatchTest.test_patchobject_with_spec.<locals>.test.<locals>.<lambda>)	rIrrer@rrtr	r>ru)�
MockAttribute)rrrrKs
z2PatchTest.test_patchobject_with_spec.<locals>.test)rr"r)rrKr)rr�test_patchobject_with_specsz$PatchTest.test_patchobject_with_speccs(tdtdgd��fdd��}|�dS)Nz%s.SomeClassrt)rpcs2��t|���ttjt����tdd��dS)NcSstjS)N)rrqrrrrrr$rszFPatchTest.test_patch_with_spec_as_list.<locals>.test.<locals>.<lambda>)rIrr@rrtr	r>ru)rv)rrrrK sz4PatchTest.test_patch_with_spec_as_list.<locals>.test)rr)rrKr)rr�test_patch_with_spec_as_listsz&PatchTest.test_patch_with_spec_as_listcs(tjtddgd��fdd��}|�dS)Nrert)rpcs6��tj|���ttjjt����tdd��dS)NcSstjjS)N)rrerqrrrrrr0rszLPatchTest.test_patchobject_with_spec_as_list.<locals>.test.<locals>.<lambda>)	rIrrer@rrtr	r>ru)rx)rrrrK*s
z:PatchTest.test_patchobject_with_spec_as_list.<locals>.test)rr"r)rrKr)rr�"test_patchobject_with_spec_as_list)sz,PatchTest.test_patchobject_with_spec_as_listcs4tdt�tdtdgd��fdd���}|�dS)Nz%s.openz%s.SomeClassrt)rpcs2��t|���ttjt����tdd��dS)NcSstjS)N)rrqrrrrrr<rszMPatchTest.test_nested_patch_with_spec_as_list.<locals>.test.<locals>.<lambda>)rIrr@rrtr	r>ru)rvZMockOpen)rrrrK7sz;PatchTest.test_nested_patch_with_spec_as_list.<locals>.test)rrar)rrKr)rr�#test_nested_patch_with_spec_as_list5s
 z-PatchTest.test_nested_patch_with_spec_as_listcs&tdtdd��fdd��}|�dS)Nz%s.SomeClassT)rpcs*��t���j��t�fdd��dS)Ncs�jS)N)rqr)rvrrrrGrszIPatchTest.test_patch_with_spec_as_boolean.<locals>.test.<locals>.<lambda>)rIrrtr>ru)rv)r)rvrrKAsz7PatchTest.test_patch_with_spec_as_boolean.<locals>.test)rr)rrKr)rr�test_patch_with_spec_as_boolean@sz)PatchTest.test_patch_with_spec_as_booleancs&tjtddd��fdd��}|�dS)NrT)rpcs*��t���j��t�fdd��dS)Ncs�jS)N)rqr)rvrrrrSrszPPatchTest.test_patch_object_with_spec_as_boolean.<locals>.test.<locals>.<lambda>)rIrrtr>ru)rv)r)rvrrKMsz>PatchTest.test_patch_object_with_spec_as_boolean.<locals>.test)rr"rY)rrKr)rr�&test_patch_object_with_spec_as_booleanLsz0PatchTest.test_patch_object_with_spec_as_booleancs&tdtdd��fdd��}|�dS)Nz%s.SomeClassT)rpcs>��t|t��|�������j��t�fdd��dS)Ncs�jS)N)rqr)�instancerrrrarszVPatchTest.test_patch_class_acts_with_spec_is_inherited.<locals>.test.<locals>.<lambda>)r@rr	rDrtr>ru)rv)r)rrrKYs

zDPatchTest.test_patch_class_acts_with_spec_is_inherited.<locals>.test)rr)rrKr)rr�,test_patch_class_acts_with_spec_is_inheritedXs
z6PatchTest.test_patch_class_acts_with_spec_is_inheritedcs:tdttjdd��fdd��}|���tdd��dS)Nz
%s.froobleT)�createcs��ttj�dS)N)rI�froobler�Froobler)rrrrKgszLPatchTest.test_patch_with_create_mocks_non_existent_attributes.<locals>.testcSstS)N)r�rrrrrrlrszPPatchTest.test_patch_with_create_mocks_non_existent_attributes.<locals>.<lambda>)rrarr�r>�	NameError)rrKr)rr�4test_patch_with_create_mocks_non_existent_attributesfs z>PatchTest.test_patch_with_create_mocks_non_existent_attributescs:tjtdtjdd��fdd��}|���ttd��dS)Nr�T)r�cs��tjtj�dS)N)rIrr�rr�r)rrrrKpszRPatchTest.test_patchobject_with_create_mocks_non_existent_attributes.<locals>.test)rr"rrr�rA�hasattr)rrKr)rr�:test_patchobject_with_create_mocks_non_existent_attributesos zDPatchTest.test_patchobject_with_create_mocks_non_existent_attributescsZy&tdttj��fdd��}|�Wntk
r:YnX��d���tdd��dS)Nz
%s.frooblecs��ttj�dS)N)rIr�rr�r)rrrrKzsz9PatchTest.test_patch_wont_create_by_default.<locals>.testz,Patching non existent attributes should failcSstS)N)r�rrrrrr�rsz=PatchTest.test_patch_wont_create_by_default.<locals>.<lambda>)rrarr�ru�failr>r�)rrKr)rr�!test_patch_wont_create_by_defaultxs

z+PatchTest.test_patch_wont_create_by_defaultcsZy&t�tdtj��fdd��}|�Wntk
r:YnX��d���ttd��dS)N�ordcs��d�dS)Nz,Patching non existent attributes should fail)r�r)rrrrK�sz?PatchTest.test_patchobject_wont_create_by_default.<locals>.testz,Patching non existent attributes should fail)	rr"rrr�rur�rAr�)rrKr)rr�'test_patchobject_wont_create_by_default�s

z1PatchTest.test_patchobject_wont_create_by_defaultcCsHttd�dd��}ttd�dd��}|�|�d�|�|�d�dS)	Nz.ordcSsd|_td�S)N�e�c)r`r�)Zmock_ordrrr�test_ord�sz>PatchTest.test_patch_builtins_without_create.<locals>.test_ordz.opencSs*|j}d|j_td�}|��}|��|S)N�abcdzdoesnotexists.txt)r`�readr^�close)Z	mock_open�mZfobj�datarrr�	test_open�sz?PatchTest.test_patch_builtins_without_create.<locals>.test_openr�r�)rrrI)rr�r�rrr�"test_patch_builtins_without_create�s
z,PatchTest.test_patch_builtins_without_createcsPGdd�dt��t��dtdd�����fdd��}|������tj�dS)Nc@seZdZedd��ZdS)z5PatchTest.test_patch_with_static_methods.<locals>.FoocSstjS)N)r�Staticrrrr�woot�sz:PatchTest.test_patch_with_static_methods.<locals>.Foo.wootN)rrrr2r�rrrrr%�sr%r�cSstjS)N)rrJrrrrrr�rsz:PatchTest.test_patch_with_static_methods.<locals>.<lambda>cs�����tj�dS)N)rIr�rrJr)r%rrr�	anonymous�sz;PatchTest.test_patch_with_static_methods.<locals>.anonymous)r"rr2rIr�rr�)rr�r)r%rr�test_patch_with_static_methods�s$z(PatchTest.test_patch_with_static_methodscs8tj}t�tdd��fdd��}|���tj|�dS)Nr%cs��tjd�dS)Nr%)rIrr%r)rrrr��sz-PatchTest.test_patch_local.<locals>.anonymous)rr%rr"rI)rr1r�r)rr�test_patch_local�szPatchTest.test_patch_localcsTGdd�dt�}|��tj�_t��dd���fdd��}|����jtj�dS)Nc@seZdZdZdS)z'PatchTest.test_patch_slots.<locals>.Foo)r%N)rrr�	__slots__rrrrr%�sr%cs���jd�dS)Nr%)rIr%r)r1rrrr��sz-PatchTest.test_patch_slots.<locals>.anonymous)r"rr%rrI)rr%r�r)r1rr�test_patch_slots�szPatchTest.test_patch_slotscsfGdd�dt��G��fdd�dt�}t��dtj�|�}|�}|��|�����jtjd�dS)Nc@seZdZejZdS)z=PatchTest.test_patchobject_class_decorator.<locals>.SomethingN)rrrrrErFrrrrrG�srGcs(eZdZ��fdd�Z��fdd�ZdS)z7PatchTest.test_patchobject_class_decorator.<locals>.Foocs���jtjd�dS)NrH)rIrFrrJ)�
other_self)rGrrr�test_method�szCPatchTest.test_patchobject_class_decorator.<locals>.Foo.test_methodcs���jtjd�dS)Nznon-test method patched)rIrFrrE)r�)rGrrr�not_test_method�szGPatchTest.test_patchobject_class_decorator.<locals>.Foo.not_test_methodN)rrrr�r�r)rGrrrr%�sr%rFzpatch not restored)	r"rrrJr�r�rIrFrE)rr%r(r)rGrr� test_patchobject_class_decorator�sz*PatchTest.test_patchobject_class_decoratorcsrGdd�dt�}G�fdd�dt�}tdt�|�}|�}|��|����|jtjd���t	j
tjd�dS)Nc@seZdZejZdS)z7PatchTest.test_patch_class_decorator.<locals>.SomethingN)rrrrrErFrrrrrG�srGcs$eZdZ�fdd�Z�fdd�ZdS)z1PatchTest.test_patch_class_decorator.<locals>.Foocs��tj|d�dS)NrH)rIrYrU)r�Zmock_something)rrrr��s
z=PatchTest.test_patch_class_decorator.<locals>.Foo.test_methodcs��tjtjd�dS)Nznon-test method patched)rIrYrUrrG)r�)rrrr��szAPatchTest.test_patch_class_decorator.<locals>.Foo.not_test_methodN)rrrr�r�r)rrrr%�sr%z%s.somethingzpatch not restored)r"rrr�r�rIrFrrErYrUrG)rrGr%r(r)rr�test_patch_class_decorator�sz$PatchTest.test_patch_class_decoratorcsZGdd�dt��t��dtj�t��dtj���fdd���}|����jtjd�dS)Nc@seZdZejZejZdS)z3PatchTest.test_patchobject_twice.<locals>.SomethingN)rrrrrErFrQrRrrrrrG�srGrFcs���jtjd�dS)NrH)rIrFrrJr)rGrrrrKsz.PatchTest.test_patchobject_twice.<locals>.testzpatch not restored)r"rrrJrIrFrE)rrKr)rGrr�test_patchobject_twice�s z PatchTest.test_patchobject_twicecs�t�dd�����}t����fdd��}|����|�t��ddi���fdd��}|����|�t��dg���fd	d��}|����|�dS)
NrU)�initial�othercsd�d<�d=d�d<dS)N�r&r�zsomething elser�rr)r1rrrKsz'PatchTest.test_patch_dict.<locals>.testr&r4cs$��t��d����dd�dS)Nr�r&r4)rI�lenr)r1rrrrKs)r&r4cs$��t��d����dd�dS)Nr�r&r4)rIr�r)r1rrrrK$s)r"�copyr�dictrI)rrWrKr)r1rr�test_patch_dict
szPatchTest.test_patch_dictcs�t��t��d<d�d<�j��}t����fdd��}|����j|�t��ddi���fdd��}|����j|�dS)	Nr�rUr�csd�d<�d=d�d<dS)Nr�r&r�zsomething elser�rr)r1rrrK5sz=PatchTest.test_patch_dict_with_container_object.<locals>.testr&r4cs&��t�j�d����dd�dS)Nr�r&r4)rIr�r7r)r1rrrrK?s)r6r"r7r�rr�rI)rrWrKr)r1rr�%test_patch_dict_with_container_object.s

z/PatchTest.test_patch_dict_with_container_objectcs�t�dd�����}tj�dd���fdd��}|����|�tj�ddidd���fd	d��}|����|�tj�d
gdd���fdd��}|����|�dS)NrU)r�r�T)�clearcs ���i�d�d<d�d<dS)Nr�r&zsomething elser�)rIr)r1rrrrKMsz2PatchTest.test_patch_dict_with_clear.<locals>.testr&r4cs���ddi�dS)Nr&r4)rIr)r1rrrrKWs)r&r4cs���ddi�dS)Nr&r4)rIr)r1rrrrK_s)r"r�rr�rI)rrWrKr)r1rr�test_patch_dict_with_clearIs" z$PatchTest.test_patch_dict_with_clearcs�t��t��d<d�d<�j��}tj�dd���fdd��}|����j|�tj�dd	idd���fd
d��}|����j|�dS)Nr�rUr�T)r�cs"���ji�d�d<d�d<dS)Nr�r&zsomething elser�)rIr7r)r1rrrrKoszGPatchTest.test_patch_dict_with_container_object_and_clear.<locals>.testr&r4cs���jddi�dS)Nr&r4)rIr7r)r1rrrrKys)r6r"r7r�rr�rI)rrWrKr)r1rr�/test_patch_dict_with_container_object_and_clearhs

"z9PatchTest.test_patch_dict_with_container_object_and_clearcCsZi}tdtt��tdtt�dd�t�tt��t�|�dd�����}|�|jd�dS)Nz%s.SomeClassT)�autospeccSsdS)Nrrrrr�	some_name�sz0PatchTest.test_name_preserved.<locals>.some_namer�)rrr"rr�rI)rr1r�rrr�test_name_preserved�szPatchTest.test_name_preservedcCsVi}t�|ddi�dd��}y
|�Wntk
r:YnX|�d�|�|i�dS)Nr&r4cSstd��dS)NZKonrad)r�rrrrrK�sz1PatchTest.test_patch_with_exception.<locals>.testzNameError not raised by test)rr�r�r�rI)rr1rKrrr�test_patch_with_exception�s

z#PatchTest.test_patch_with_exceptioncs&t�dddi��fdd��}|�dS)Nz
os.environ�
konrad_delongz
some valuecs��dtj�dS)Nr�)�assertIn�os�environr)rrrrK�sz3PatchTest.test_patch_dict_with_string.<locals>.test)rr�)rrKr)rr�test_patch_dict_with_string�sz%PatchTest.test_patch_dict_with_stringcsZtj��}t�dddi��fdd��}z&ddit_|���tjddi�Wd|t_XdS)Nz%unittest.test.testmock.support.targetr*�BARcs��tjddd��dS)N�BAZr�)r1r*)rIr�targetr)rrrrK�sz<PatchTest.test_patch_dict_decorator_resolution.<locals>.testr1r�)rr�r�rr�rI)rrWrKr)rr�$test_patch_dict_decorator_resolution�s

z.PatchTest.test_patch_dict_decorator_resolutioncsdS)Nc@seZdZdZdS)z0PatchTest.test_patch_descriptor.<locals>.NothingN)rrrr1rrrr�Nothing�sr�cs|eZdZiZe��dd�e��fdd���Ze��dd�edd���Z	e�
e�e��fdd���Ze�
e�ed	d
���ZdS)z2PatchTest.test_patch_descriptor.<locals>.Somethingr1�cs��|��dS)N)�assertIs)r.)rGrrr�klass�sz8PatchTest.test_patch_descriptor.<locals>.Something.klasscSs|S)Nr)�argrrr�static�sz9PatchTest.test_patch_descriptor.<locals>.Something.staticcs��|��dS)N)r�)r.)rGrrr�
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)
rrrr1rr"r3r�r2r�r�r�r�r)r�rGrrrrG�srGZf00)r"rIr�r�r�r�)rrUr)r�rGrr�test_patch_descriptor�szPatchTest.test_patch_descriptorcCs�tdttdd�dd��}|�t|�tjtdtdd�dd��}|�t|�tdtdd�d	d��}|�t|�tjtddd�d
d��}|�t|�dS)Nz%s.SomeClassT)rp�spec_setcSs
d|_dS)Nr1)�z)rCrrrrK�sz+PatchTest.test_patch_spec_set.<locals>.testrcSs
d|_dS)Nr1)r�)rCrrrrK�s)r�cSs
d|_dS)Nr1)r�)rCrrrrK�scSs
d|_dS)Nr1)r�)rCrrrrK�s)rrrr>rur"r)rrKrrr�test_patch_spec_set�szPatchTest.test_patch_spec_setcCs(tdtdd�dd��}|�t|�dS)Nz%s.SomeClassT)r�cSs|�}d|_dS)Nr1)r�)rCrrrrrK�sz-PatchTest.test_spec_set_inherit.<locals>.test)rrr>ru)rrKrrr�test_spec_set_inherit�szPatchTest.test_spec_set_inheritcCs\t}tdt�}|�t|�|��}z|�||�|�t|�Wd|��X|�t|�dS)Nz%s.something)rUrrr��start�assertIsNot�stop)rrW�patcherrcrrr�test_patch_start_stops
zPatchTest.test_patch_start_stopcCsttdd�}|�t|j�dS)Nr*r�)r�foo_namer>�RuntimeErrorr�)rr�rrr�test_stop_without_startsz!PatchTest.test_stop_without_startcCs^t}t�tdd�}|�t|�|��}z|�|d�|�t|�Wd|��X|�t|�dS)NrUr1)rUrr"rYr�r�rIr�)rrWr�Zreplacedrrr�test_patchobject_start_stops
z%PatchTest.test_patchobject_start_stopcCsfddi}|��}tj|dgdd�}|�||�|��z|�|ddi�Wd|��X|�||�dS)Nr1r*)�spam�eggsT)r�r�r�)r�rr�rIr�r�)r�drWr�rrr�test_patch_dict_start_stop&s
z$PatchTest.test_patch_dict_start_stopcs�|�ddi����}G��fdd�dt�}tj�ddidd�|�}|��|�|�}|��|��|�|��|��|�|�}|��|��|�|��|��|�dS)	Nr�r�cs(eZdZ��fdd�Z��fdd�ZdS)z7PatchTest.test_patch_dict_class_decorator.<locals>.Testcs���ddi�dS)Nr1r*)rI)r)r��thisrr�
test_first:szBPatchTest.test_patch_dict_class_decorator.<locals>.Test.test_firstcs���ddi�dS)Nr1r*)rI)r)r�r�rr�test_second<szCPatchTest.test_patch_dict_class_decorator.<locals>.Test.test_secondN)rrrr�r�r)r�r�rrri9srir1r*T)r�)r�r"rr�rIr�r�)rrWrirKr)r�r�r�test_patch_dict_class_decorator4s z)PatchTest.test_patch_dict_class_decoratorcs�Gdd�dt�}Gdd�d�}xj|||�|fD]X}t|��t��dd���fdd��}|����jd���|jd���d�j�q.WdS)	Nc@seZdZdZdS)z0PatchTest.test_get_only_proxy.<locals>.Somethingr1N)rrrr1rrrrrGTsrGc@seZdZdZdS)z4PatchTest.test_get_only_proxy.<locals>.SomethingElser1N)rrrr1rrrrr[Vsr[r1r*cs���jd�dS)Nr*)rIr1r)�proxyrrrrK\sz+PatchTest.test_get_only_proxy.<locals>.test)r"r$rrIr1�assertNotIn�__dict__)rrGr[�thingrKr)r�rr�test_get_only_proxySszPatchTest.test_get_only_proxycs�Gdd�dt�}Gdd�d�}xn|||�|fD]\}t|dd��t��dd���fd	d
��}|����jd���|jd���d�j�q.WdS)Nc@seZdZdZdS)z6PatchTest.test_get_set_delete_proxy.<locals>.Somethingr1N)rrrr1rrrrrGfsrGc@seZdZdZdS)z:PatchTest.test_get_set_delete_proxy.<locals>.SomethingElser1N)rrrr1rrrrr[hsr[F)r#r1r*cs���jd�dS)Nr*)rIr1r)r�rrrrKnsz1PatchTest.test_get_set_delete_proxy.<locals>.test)r"r$rrIr1r�r�)rrGr[r�rKr)r�rr�test_get_set_delete_proxyesz#PatchTest.test_get_set_delete_proxycCsZtdt�d�}ttf|�}|��}|��|�t|�|�|j�	�d�|�
|jt�dS)N�!)�side_effectzfoo.bar.return_valuer1)�KeyErrorr	rr�r�r�r>rIr1r*rj)r�kwargsr�rcrrr�test_patch_keyword_argsws
z!PatchTest.test_patch_keyword_argscCs^tdt�d�}tjtdf|�}|��}|��|�t|�|�|j	�
�d�|�|j	t�dS)Nr�)r�zfoo.bar.return_valuer1r()r�r	rr"r%r�r�r>rIr1r*rj)rr�r�rcrrr�test_patch_object_keyword_args�s
z(PatchTest.test_patch_object_keyword_argscCs`ddi}|��}tj|dddd�}|��z|�|tdddd��Wd|��X|�||�dS)Nr1r*r���)r1r*Zbaz)r�rr�r�rIr�)rrWr�r�rrr�test_patch_dict_keyword_args�s
z&PatchTest.test_patch_dict_keyword_argscs�Gdd�dt�}�fdd���fdd�����fdd�}ttd	d
�|�}|�}��t|�|�tjt}tj|dd	d
�|�}|�}��t|�|�dS)Nc@s8eZdZdd�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&rrrrr0�sr0N)	rrrr'r(r)r1r"r0rrrr�Boo�s
r�cs"|d�|�d���t|�dS)N�)�assert_called_withr>r?)rc)rrr�_test�s
z&PatchTest.test_autospec.<locals>._testcs|�d�|j�d���t|j�|��|j����t|jd���tt|d�|j��|jj����tt|jd�|�	�|j	��|j	�
�|j	j
����t|j	j
d�|�	��
�|�	�j
����t|�	�j
d���tt|j	d���tt|�	�d�dS)Nr��hr*r4)r(r�r>r?r)rurr1�lowerr0r&)rc)rrr�_test2�s(




z'PatchTest.test_autospec.<locals>._test2cs,�|��|��|d����|t�|S)Nr�)r�r%)rc)r�r�rrrr5�s
z)PatchTest.test_autospec.<locals>.functionT)r�r%)r"rr�r�r%�sys�modulesr)rr�r5rKrc�moduler)r�r�rr�
test_autospec�s

zPatchTest.test_autospeccs&tdtdd��fdd��}|�dS)Nz%s.functionT)r�cs�t����ttj���ttj�td���ttj�t�d�t��t��tdd�t�dd���tt���tt	td�dS)Nr�r�r�r1)
r5Zassert_not_calledr>�AssertionErrorZ
assert_calledZassert_called_oncer�r?rur)rc)rrrrK�s

z.PatchTest.test_autospec_function.<locals>.test)rr)rrKr)rr�test_autospec_function�sz PatchTest.test_autospec_functioncCs0tdtddd�dd��}|�}|�|d�dS)Nz%s.functionTr�)r�r`cSs
tdd�S)Nr�r�)r5)Z
mock_functionrrrrK�sz.PatchTest.test_autospec_keywords.<locals>.test)rrrI)rrK�resultrrr�test_autospec_keywords�s
z PatchTest.test_autospec_keywordsc	Cs0tdtdd��}t��|��WdQRXdS)Nz%s.Foo.static_methodT)r�)rrr%r,�assert_called_once_with)r�methodrrr�test_autospec_staticmethodsz$PatchTest.test_autospec_staticmethodc	Cs0tdtdd��}t��|��WdQRXdS)Nz%s.Foo.class_methodT)r�)rrr%r/r�)rr�rrr�test_autospec_classmethodsz#PatchTest.test_autospec_classmethodcCsNtdtddd�}|�t|j�tjt}tj|dddd�}|�t|j�dS)Nz%s.functionr�T)�newr�r5)rrr>r?r�r�r�r")rr�r�rrr�test_autospec_with_news

z PatchTest.test_autospec_with_newcCsRGdd�dt�}tt|d�}|��}z|�||�|�|jt�Wd|��XdS)Nc@seZdZgZdS)z0PatchTest.test_autospec_with_object.<locals>.BarN)rrr�extrarrrrr0sr0)r�)r%rr�r�rjr��listr�)rr0r�rcrrr�test_autospec_with_objectsz#PatchTest.test_autospec_with_objectcCsHt}ttdd�}|��}z |�||�|�|d�|�Wd|��XdS)NT)r�r�)r%rr�r�rjr�)rZFooClassr�rcrrr�test_autospec_inherits(sz PatchTest.test_autospec_inheritscCstttdd�}|��}zP|�dt|��|�dt|j��|�dt|d���|�dt|d�j��Wd|��XdS)NT)r�z name='Foo'z
 name='Foo.f'z
 name='Foo()'z name='Foo().f')rr�r�r��reprr(r�)rr�rcrrr�test_autospec_name3szPatchTest.test_autospec_namecCsbt�tdt��dd��}y
|�Wnt��}YnXt�ddd�}|�||�}|�d|�dS)Nr(cSst�dS)N)r�rrrrrKAsz'PatchTest.test_tracebacks.<locals>.testrzraise AssertionError)	rr"r%r��exc_info�unittestZTextTestResultZ_exc_info_to_stringr�)rrK�errr��	tracebackrrr�test_tracebacks@s
zPatchTest.test_tracebackscCsXtttd�}|��}|��|��}|��|�||�x||fD]}|�|�qBWdS)N)�new_callable)rr�rr�r�r�rD)rr��m1�m2rcrrr�test_new_callable_patchNsz!PatchTest.test_new_callable_patchcCs\tjtdtd�}|��}|��|��}|��|�||�x||fD]}|�|�qFWdS)Nr()r)rr"r%rr�r�r�rD)rr�r	r
rcrrr�test_new_callable_patch_object[sz(PatchTest.test_new_callable_patch_objectcsfG�fdd�dt��tt�ddd�}|��}z*|�t|���|��jtddd��Wd|�	�XdS)NcseZdZdZ�fdd�ZdS)z:PatchTest.test_new_callable_keyword_arguments.<locals>.BarNcs
|�_dS)N)r�)rr�)r0rrr'kszCPatchTest.test_new_callable_keyword_arguments.<locals>.Bar.__init__)rrrr�r'r)r0rrr0isr0r�r�)r�arg1�arg2)r
r)
r"rr�r�r��typerIr�r�r�)rr�r�r)r0r�#test_new_callable_keyword_argumentshsz-PatchTest.test_new_callable_keyword_argumentscs�G�fdd�dt��tt��d�}|��z|��jt�d��Wd|��Xtt��d�}|��z|��jt�d��Wd|��XdS)NcseZdZdZ�fdd�ZdS)z-PatchTest.test_new_callable_spec.<locals>.BarNcs
|�_dS)N)r�)rr�)r0rrr'zsz6PatchTest.test_new_callable_spec.<locals>.Bar.__init__)rrrr�r'r)r0rrr0xsr0)rrp)rp)rr�)r�)r"rr�r�rIr�r�r�)rr�r)r0r�test_new_callable_specws
z PatchTest.test_new_callable_speccCsZdt}t|td�}|�t|j�t|tdd�}|��}z|j|dd�Wd|��XdS)Nz	%s.weeeee)rT)rr�F)rB)r�rrr>rur�rDr�)rZnon_existent_attr�pr�rrr�test_new_callable_create�sz"PatchTest.test_new_callable_createcCs4|jtttt�td�|jttjtdt�td�dS)N)r�rr()r>�
ValueErrorrr�r"r	r%)rrrr�'test_new_callable_incompatible_with_new�s
z1PatchTest.test_new_callable_incompatible_with_newcCs0|jttttdd�|jttjtdtdd�dS)NT)rr�r()r>rrr�r	r"r%)rrrr�,test_new_callable_incompatible_with_autospec�sz6PatchTest.test_new_callable_incompatible_with_autospecc	
Cs�Gdd�dt�}tttt|f}xd|D]\}xVdD]N}|di}ttfd|i|��}|��}z|j}|�t	t
|d�Wd|��Xq.Wq$WdS)Nc@seZdZdS)z>PatchTest.test_new_callable_inherit_for_mocks.<locals>.MockSubN)rrrrrrr�MockSub�sr)rpr�Tr�x)r
rrr	rr�r�r`r>rurr�)	rrZMockClassesZKlassr�r�rr�rrrr�#test_new_callable_inherit_for_mocks�s

z-PatchTest.test_new_callable_inherit_for_mockscCshGdd�dt�}tt|dd�}|��}z$|�t||��|�tt|d�Wd|�	�X|�
|jt�dS)Nc@seZdZdd�ZdS)z>PatchTest.test_new_callable_inherit_non_mock.<locals>.NotAMockcSs
||_dS)N)rp)rrprrrr'�szGPatchTest.test_new_callable_inherit_non_mock.<locals>.NotAMock.__init__N)rrrr'rrrr�NotAMock�srT)rrpr`)
r"rr�r�r@rr>rurr�rIrpr%)rrrr�rrr�"test_new_callable_inherit_non_mock�s
z,PatchTest.test_new_callable_inherit_non_mockcsR|�t�G��fdd�dt�}tttd�|�}|���|���|�t��dS)Ncs*eZdZ��fdd�Zdd�Zdd�ZdS)z>PatchTest.test_new_callable_class_decorating.<locals>.SomeTestcs(��t����t|���tt�dS)N)r�r%r�rjr)r�mock_foo)rWrKrrr��szDPatchTest.test_new_callable_class_decorating.<locals>.SomeTest._testcSs|�|�dS)N)r�)rrrrr�test_two�szGPatchTest.test_new_callable_class_decorating.<locals>.SomeTest.test_twocSs|�|�dS)N)r�)rrrrr�test_one�szGPatchTest.test_new_callable_class_decorating.<locals>.SomeTest.test_oneN)rrrr�rrr)rWrKrr�SomeTest�sr)r)r%r"rr�rrrr�)rrr)rWrKr�"test_new_callable_class_decorating�s

z,PatchTest.test_new_callable_class_decoratingc	s�t�tj}tj}tjtddd�}tjtddd�}xx||fD]l}|��z,��t����tjd���tjd�Wd|�	�X��t����tj|���tj|�q:Wtjtddd���fdd��}|�dS)Nr�r�)r(r)r�r�cs,��t����tjd���tjd�dS)Nr�r�)r�r%rIr(r)r)�original_foorrrrK�sz+PatchTest.test_patch_multiple.<locals>.test)
r%r(r)r�multipler�r�r�rIr�)r�
original_f�
original_gZpatcher1Zpatcher2r�rKr)r!rr�test_patch_multiple�s"
zPatchTest.test_patch_multiplecCs$|�ttjt�|�ttjt�dS)N)r>rrr"r�r%)rrrr�test_patch_multiple_no_kwargssz'PatchTest.test_patch_multiple_no_kwargscsVt�tj}tj}tjttdtd���fdd��}|���tj|���tj|�dS)Nr�)r(r)r1csZ��t����tj|���tjd���tj|���t|t����t|t��dS)Nr�)	r�r%r(rIr)r1r@rr	)r(r1)r!rrrrKsz8PatchTest.test_patch_multiple_create_mocks.<locals>.test)r%r(r)rr"r�rrI)rr#r$rKr)r!rr� test_patch_multiple_create_mockss 	z*PatchTest.test_patch_multiple_create_mockscsrtj}tj}t�tdd�}d|_t�tdt�}d|_|g|_|�fdd��}|���tj|���tj|�dS)Nr(r�r)cs ��tj|���tjd�dS)Nr�)r�r%r)rIr()r))rrrrK*szHPatchTest.test_patch_multiple_create_mocks_different_order.<locals>.test)	r%r(r)rr"�attribute_namer�additional_patchersrI)rr#r$r�r�rKr)rr�0test_patch_multiple_create_mocks_different_ordersz:PatchTest.test_patch_multiple_create_mocks_different_ordercs�t�tj}tj}tjttd�tjttd�ttd��fdd����}tjttd�ttd�tjttd��fdd����}ttd�tjttd�tjttd��fdd	����}��fd
d��|�|�|���tj|���tj|�dS)N)r()r1z.gcs�|f|�dS)Nr)r)r�)r�rr�test19sz?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test1cs�|f|�dS)Nr)r)r�)r�rr�test2?sz?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test2cs�|f|�dS)Nr)r)r�)r�rr�test3Esz?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test3cs�|�d�}|�d�}��|���t����tj|���tj|���tj|���t|t	����t|t	����t|t	��dS)Nr(r1)
�poprAr�r%r(r)r1r@rr	)r)r�r(r1)r!rrrr�Ks


z?PatchTest.test_patch_multiple_stacked_decorators.<locals>._test)r%r(r)rr"r�rrI)rr#r$r+r,r-r)r�r!rr�&test_patch_multiple_stacked_decorators4s$


z0PatchTest.test_patch_multiple_stacked_decoratorscCs�t}tj}tj}tjttdtd�}|��}zt|d}|d}|�t	|�t	ddg��|�
t|�|�
tj|�|�
tj|�|�t
|t��|�t
|t��Wd|��X|�tj|�|�tj|�dS)Nr�)r(r)r1r(r1)r%r(r)rr"r�rr�rI�setr�r1r@rr	r�)rr!r#r$r�r�r(r1rrr�(test_patch_multiple_create_mocks_patcher_s"
z2PatchTest.test_patch_multiple_create_mocks_patchercsv|�t�tj}tj}G��fdd�dt�}tjttdtd�|�}|�}|��|�	�|�
tj|�|�
tj|�dS)Ncs*eZdZ��fdd�Zdd�Zdd�ZdS)z@PatchTest.test_patch_multiple_decorating_class.<locals>.SomeTestcsZ��t����tj|���tjd���tj|���t|t����t|t��dS)Nr�)	r�r%r(rIr)r1r@rr	)rr(r1)r!rKrrr��szFPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest._testcSs|�||�dS)N)r�)rr(r1rrrr�szIPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest.test_twocSs|�||�dS)N)r�)rr(r1rrrr�szIPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest.test_oneN)rrrr�rrr)r!rKrrr~srr�)r(r)r1)r%r(r)r"rr"r�rrrrI)rr#r$rr�r)r!rKr�$test_patch_multiple_decorating_classxsz.PatchTest.test_patch_multiple_decorating_classcCsftjtdd�}|�t|j�tjtddd�}|��z|�tjd�Wd|��X|�	t
td��dS)N�blam)r3T)r3r�)rr"r%r>rur�rIr3r�rAr�)rr�rrr�test_patch_multiple_create�s
z$PatchTest.test_patch_multiple_createcCs�tjttddgd�}|��}z^|�tj|d�tj�d�tj�d�tjj�	d�tjj�	d�|�
tttjdd�Wd|�
�XdS)Nr&r4)r1r�r1r�r�r�)rr"r%rr�rIr1r&r4r�r>rurr�)rr�r�rrr�test_patch_multiple_spec_set�sz&PatchTest.test_patch_multiple_spec_setcCs�Gdd�dt�}tjttt|d�}|��}zT|�tj|d�|�tj|d�|�	tj|�|�	tj|�|�
tjtj�Wd|��XdS)Nc@seZdZdS)z9PatchTest.test_patch_multiple_new_callable.<locals>.ThingN)rrrrrrr�Thing�sr6)r(r)rr(r))r"rr"r%rr�r�r(r)rjr�r�)rr6r�r�rrr� test_patch_multiple_new_callable�sz*PatchTest.test_patch_multiple_new_callablecCs�tj}tj}t�tdd�t�tdd�t�tdd�dd����}t�tdd�t�tdd�t�tdd�dd����}t�tdd�t�tdd�t�tdd�d	d
����}x:|||fD],}|�t|�|�tj|�|�tj|�q�WdS)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)rr"r>rurI)rr#r$r9r:r;�funcrrr�test_nested_patch_failure�sz#PatchTest.test_nested_patch_failurec	Cstj}tj}tj}dd�}t�tdd�tjtd|d�t�tdd�dd	����}tjtd|d�t�tdd�t�tdd�d
d����}t�tdd�t�tdd�tjtd|d�dd
����}xH|||fD]:}|�t|�|�tj|�|�tj|�|�tj|�q�WdS)NcSstd��dS)N�crasher)r�rrrrr>�sz4PatchTest.test_new_callable_failure.<locals>.crasherr)r�r1)rr(cSsdS)Nrrrrrr9�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)r1rr"r>r�rI)	rr#r$r!r>r9r:r;r<rrr�test_new_callable_failure�s$z#PatchTest.test_new_callable_failurecCs�tj}tj}t�tdd�}d|_t�tdd�}d|_t�tdd�}d|_xR||g||gfD]>}||_|dd��}|�t|�|�	tj|�|�	tj|�qZWdS)Nr(r�r)r8cSsdS)Nrrrrrr<sz3PatchTest.test_patch_multiple_failure.<locals>.func)
r%r(r)rr"r(r)r>rurI)rr#r$r��good�bad�additionalsr<rrr�test_patch_multiple_failuresz%PatchTest.test_patch_multiple_failurec
Cs�tj}tj}tj}dd�}t�tdd�}d|_t�tdd�}d|_tjtd|d�}d|_x`||g||gfD]L}||_|dd	��}	|�t	|	�|�
tj|�|�
tj|�|�
tj|�qjWdS)
NcSstd��dS)Nr>)r�rrrrr>$szCPatchTest.test_patch_multiple_new_callable_failure.<locals>.crasherr(r�r)r1)rcSsdS)Nrrrrrr<3sz@PatchTest.test_patch_multiple_new_callable_failure.<locals>.func)r%r(r)r1rr"r(r)r>r�rI)
rr#r$r!r>r�r@rArBr<rrr�(test_patch_multiple_new_callable_failures"z2PatchTest.test_patch_multiple_new_callable_failurecsLtdtfddi�}|��tj�dd���fdd��}|����jd�dS)Nr%�fishZtastyznearly gone)rEcs���jd�dS)Nznearly gone)rIrEr)r1rrrrK@sz=PatchTest.test_patch_multiple_string_subclasses.<locals>.test)r�strrr"rIrE)rr%rKr)r1rr�%test_patch_multiple_string_subclasses=s
z/PatchTest.test_patch_multiple_string_subclasseszunittest.mock.patch.TEST_PREFIXr1cCslGdd�dt�}t�|dd�|�}|�}|�|��d�|�|��d�|�|��d�|�|��d�dS)Nc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)z-PatchTest.test_patch_test_prefix.<locals>.FoorWcSs|jS)N)r�)rrrr�foo_oneMsz5PatchTest.test_patch_test_prefix.<locals>.Foo.foo_onecSs|jS)N)r�)rrrr�foo_twoOsz5PatchTest.test_patch_test_prefix.<locals>.Foo.foo_twocSs|jS)N)r�)rrrrrQsz6PatchTest.test_patch_test_prefix.<locals>.Foo.test_onecSs|jS)N)r�)rrrrrSsz6PatchTest.test_patch_test_prefix.<locals>.Foo.test_twoN)rrrr�rHrIrrrrrrr%Js
r%r��changedrW)r"rrIrHrIrr)rr%r1rrr�test_patch_test_prefixHsz PatchTest.test_patch_test_prefixr*cs�G�fdd�dt�}ddi�tj�dd�|�}|�}|�|��ddi�|�|��ddi�|�|��ddi�|�|��ddi�dS)Ncs<eZdZ�fdd�Z�fdd�Z�fdd�Z�fdd�Zd	S)
z2PatchTest.test_patch_dict_test_prefix.<locals>.Foocst��S)N)r�)r)�the_dictrr�bar_onebsz:PatchTest.test_patch_dict_test_prefix.<locals>.Foo.bar_onecst��S)N)r�)r)rLrr�bar_twodsz:PatchTest.test_patch_dict_test_prefix.<locals>.Foo.bar_twocst��S)N)r�)r)rLrrrfsz;PatchTest.test_patch_dict_test_prefix.<locals>.Foo.test_onecst��S)N)r�)r)rLrrrhsz;PatchTest.test_patch_dict_test_prefix.<locals>.Foo.test_twoN)rrrrMrNrrr)rLrrr%asr%�keyrWrJ)rO)r"rr�rIrMrNrr)rr%r1r)rLr�test_patch_dict_test_prefix_s
z%PatchTest.test_patch_dict_test_prefixc	Cs�x�dD]x}tdtf|di�}|��}zL|�dt|��|�dt|j��|�dt|���|�dt|�j��Wd|��XqWdS)N)rpr�r�z%s.SomeClassTz name='SomeClass'z! name='SomeClass.class_attribute'z name='SomeClass()'z# name='SomeClass().class_attribute')rrr�r�rrer�)rr�rr�rrr�test_patch_with_spec_mock_reprus
z(PatchTest.test_patch_with_spec_mock_reprc	CsJtddd��4}|�dt|j����|�dt|������WdQRXdS)Nzunittest.test.testmock.supportT)r�z" name='support.SomeClass.wibble()'z$ name='support.SomeClass().wibble()')rr�rrrt)rr�rrr�test_patch_nested_autospec_repr�s
z)PatchTest.test_patch_nested_autospec_reprc	Csx�dD]�}tdtf|di�}|��}z�|��t��g}|�|j|�|�|j|�|�|jjt�g�|�}|�t��|�|j|�|��|�t����|�|j|�|�|jt��g�|�|jjt�g�|�|jt��g�Wd|�	�XqWdS)N)rpr�r�z%s.SomeClassT)
rrr�rtrrIZ
mock_callsZmethod_calls�appendr�)rr�rr�Zkallsr�rrr�test_mock_calls_with_patch�s&

z$PatchTest.test_mock_calls_with_patchc	Csptd�}|�t|j�td��:t�}|tjd<d|_td�}d|_|��|�	�WdQRX|�
|jd�dS)Nz
squizz.squozz�squizz�r�)rr>�ImportErrorr�rr
r�r�Zsquozzr�rI)rZp1rUrrr�test_patch_imports_lazily�s

z#PatchTest.test_patch_imports_lazilyc	s�Gdd�d��G�fdd�dt���fdd�}|d�dd	��}td
��"t�}|tjd
<|�t|�WdQRX|��jdt�|�	�jdd
�|�	�jdd�dS)Nc@seZdZdZdS)z<PatchTest.test_patch_propogrates_exc_on_exit.<locals>.holder)NNNN)rrrrrrrr�holder�srYcseZdZd�fdd�	ZeZdS)zBPatchTest.test_patch_propogrates_exc_on_exit.<locals>.custom_patchNcs t�||||�|||f�_dS)N)r
�__exit__r)r�etype�val�tb)rYrrrZ�szKPatchTest.test_patch_propogrates_exc_on_exit.<locals>.custom_patch.__exit__)NNN)rrrrZr�r)rYrr�custom_patch�sr^c
s$t|�\}}�||tdddddi�	S)NF)rr)r��getterrF)r^rr�with_custom_patch�szGPatchTest.test_patch_propogrates_exc_on_exit.<locals>.with_custom_patchz
squizz.squozzcSst�dS)N)r�)rcrrrrK�sz:PatchTest.test_patch_propogrates_exc_on_exit.<locals>.testrUrr�zexception value not propgatedr�z!exception traceback not propgated)
r
rr
r�r�r>r�r�rZassertIsNotNone)rr`rKrUr)r^rYr�"test_patch_propogrates_exc_on_exit�s

z,PatchTest.test_patch_propogrates_exc_on_exitcCstxndD]f}tdtfddi|di��}|�t|j�|�tdd��ttfddi|di��}|��|��qWdS)N)rpr�r�z%s.doesnotexistr�TcSstS)N)�doesnotexistrrrrrr�rsz1PatchTest.test_create_and_specs.<locals>.<lambda>)rrr>r?r�r��MODNAMEr�)r�kwargrrrr�test_create_and_specs�s
zPatchTest.test_create_and_specscCs�t}x>dD]6}ttfddi|di��}|�t|j�|�t|�q
Wx>dD]6}ttfddi|di��}|�t|j�|�t|�qJWx>dD]6}ttfddi|di��}|�t|j�|�t|�q�WdS)N)rpr�r�r)rpr�r�)r�r�rp)rYrrcr>r?r�r�)rrWrdrrrr�test_multiple_specs�s


zPatchTest.test_multiple_specscCs8ttdddd�}|��}z|jd|_Wd|��XdS)NF)rpr�r�r�)rrcr�Zdoes_not_existr�)rrrcrrr� test_specs_false_instead_of_none�s
z*PatchTest.test_specs_false_instead_of_nonec	CsJxDdD]<}ttf|di�}|��}z|�tt|d�Wd|��XqWdS)N)rpr�r�rZdoesnotexit)rrcr�r>rurr�)rrdrr�rrr�test_falsey_specs
zPatchTest.test_falsey_specc	Csdx^dD]V}ttfddi|di��}|��}z&|�tt|dd�|�tt|d�Wd|��XqWdS)N)rpr�r�TrbrU)rrcr�r>rurrr�)rrdrr�rrr�test_spec_set_true
s

zPatchTest.test_spec_set_truecCs:d}tt|d�}|��}z|�t|��Wd|��XdS)N)�__call__)rp)rrcr�r@�callabler�)rrprr�rrr�test_callable_spec_as_listsz$PatchTest.test_callable_spec_as_listcCs:d}tt|d�}|��}z|�t|��Wd|��XdS)N)r1r*)rp)rrcr�rArkr�)rrprr�rrr�test_not_callable_spec_as_list#sz(PatchTest.test_not_callable_spec_as_listcs^tj�tj�tj}tdt���tdt���td����fdd��}|���tj|�dS)Nz	os.unlinkzos.chdirzos.pathcs6t����tj|���tj����tj��dS)N)r�stopallr�r��path�unlink�chdir)Z	mock_path)rqrrprr�patched4sz-PatchTest.test_patch_stopall.<locals>.patched)	r�rprqrorrUr�rZr�)rrorrr)rqrrpr�test_patch_stopall-szPatchTest.test_patch_stopallcsRg�Gdd�dt����fdd���fdd�dD�t��|��dd	d
g�dS)Nc@seZdZdZZZdS)z*PatchTest.test_stopall_lifo.<locals>.thingN)rrr�one�two�threerrrrr�@sr�c
s8G���fdd�dt����fdd��ddddddi�	S)Ncs"eZdZ����fdd�Z�ZS)z?PatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.mypatchcs����t�|���S)N)rS�superr�)r)�	__class__rF�mypatch�stoppedrrr�Es
zDPatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.mypatch.stop)rrrr��
__classcell__r)rFryrz)rxrryDsrycs�S)Nrr)r�rrrrHrsz@PatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.<lambda>F)r
)rF)rzr�)rFryr�	get_patchCsz.PatchTest.test_stopall_lifo.<locals>.get_patchcsg|]}�|����qSr)r�)�.0r\)r|rr�
<listcomp>Jsz/PatchTest.test_stopall_lifo.<locals>.<listcomp>)rtrurvrvrurt)r"rrnrI)rr)r|rzr�r�test_stopall_lifo>szPatchTest.test_stopall_lifoc	Cs>ddd�}t�|dd��|�|�d�WdQRX|�|�d�t�|dd��|�|jd�WdQRX|�|jd	�t�|d
d��|�|jd�WdQRX|�|jd�t�|d
tdg���|�|jtdg��WdQRX|�|jt��dd�dd�}t�|dtdg���|�|�d�WdQRX|�|�d�dS)NrcSs|S)�TESTr)rrrrr1Qsz)PatchTest.test_special_attrs.<locals>.foo�__defaults__)r�r��__doc__ZFUNr�rZ
testpatch2z unittest.test.testmock.testpatch�__annotations__)�sr�)rcWs|S)Nr)rr&rrrr1ds�__kwdefaults__)rr�)r)rr"rIr�rr�r�)rr1rrr�test_special_attrsPs"
zPatchTest.test_special_attrsN)T)irrrrDrLrNrPrTrXrdrgrorwryrzr{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�r�rrrrrrrrrrrrr r%r&r'r*r/r1r2r4r5r7r=r?rCrDrGrrKrPrQrRrTrXrarerfrgrhrirlrmrsrr�rrrrr=[s�


+*

		
!
+	



G	




+!!	"



r=�__main__)T)(r�r�rZunittest.test.testmockrZunittest.test.testmock.supportrrZtest.test_importlib.utilrZ
unittest.mockrrrr	r
rrr
rrrrar�rrYrcr$rGrUr[rZr"r%r�r5r6ZTestCaser=�mainrrrr�<module>sB4