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.10/unittest/test/testmock/__pycache__/testpatch.cpython-310.opt-2.pyc
o

�i��@s
ddlZddlZddlmZddlZddlmZddlmZm	Z	ddl
mZddlm
Z
mZmZmZmZmZmZmZmZmZmZdZejeZdeZdd
d�Zejaej Z!Gdd
�d
e"�Z#deZ$e#fdd�Z%Gdd�de"�Z&Gdd�dej'�Z(edkr�e�)�dSdS)�N)�OrderedDict)�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.10/unittest/test/testmock/testpatch.py�__getattr__�
z%_get_proxy.<locals>.Proxy.__getattr__N)�__name__�
__module__�__qualname__rrrrr�Proxy�r!cst�||�dSr)�setattr�rr�valuerrr�__setattr__ �z_get_proxy.<locals>.__setattr__cst�|�dSr)�delattrrrrr�__delattr__"�z_get_proxy.<locals>.__delattr__)�objectr&r))r�get_onlyr!r&r)rrr�
_get_proxysr-c@sPeZdZdd�Zdd�Zdd�ZdZedd	��Ze	d
d��Z
Gdd
�d
e�ZdS)�FoocC�dSrr�r�arrr�__init__/�zFoo.__init__cCr/rrr0rrr�f0r3zFoo.fcCr/rr�rrrr�g1r3zFoo.g�barcCr/rrrrrr�
static_method4�zFoo.static_methodcCr/rr)�clsrrr�class_method7r9zFoo.class_methodc@�eZdZdd�ZdS)zFoo.BarcCr/rrr5rrrr1;r3z	Foo.Bar.aN�rrr r1rrrr�Bar:�r>N)
rrr r2r4r6�foo�staticmethodr8�classmethodr;r+r>rrrrr..s

r.z%s.FoocCr/rr�r1�brrr�function@r3rEc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�	ContainercCs
i|_dSr��valuesr5rrrr2DrzContainer.__init__cCs
|j|SrrGrrrr�__getitem__GrzContainer.__getitem__cCs||j|<dSrrGr$rrr�__setitem__Jr*zContainer.__setitem__cCs|j|=dSrrGrrrr�__delitem__MszContainer.__delitem__cCs
t|j�Sr)�iterrHr5rrr�__iter__PrzContainer.__iter__N)rrr r2rIrJrKrMrrrrrFCsrFc@s�eZdZd�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��ZVd�d��ZWd�d��ZXeYd�d��d�d���ZZeYd�d��d�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�dքZld�d؄Zmd�dڄZnd�d܄Zod�dބZpd�S)��	PatchTestTcCs<t}|st}|�t|�|�t||��|�t|t��dSr)rr�assertRaises�	TypeError�
assertTruer�assertFalser)rr�magic�	MockClassrrr�assertNotCallableWszPatchTest.assertNotCallablecsJGdd�dt��t��dtj���fdd��}|����jtjd�dS)Nc@�eZdZejZdS)z4PatchTest.test_single_patchobject.<locals>.SomethingN�rrr r	�Original�	attributerrrr�	Somethingb�
rZrYc����jtjd�dS�NZ	unpatched��assertEqualrYr	�Patchedr�rZrrr�teste�z/PatchTest.test_single_patchobject.<locals>.test�patch not restored�r+r
r	r`r_rYrX�rrbrrar�test_single_patchobjectas�z!PatchTest.test_single_patchobjectcCsBd}|�t|��t�dd�Wd�dS1swYdS)Nz>'Something' must be the actual object to be patched, not a strrZZdo_something)ZassertRaisesRegexrPr
r+)r�msgrrr�&test_patchobject_with_string_as_targetms"�z0PatchTest.test_patchobject_with_string_as_targetcsHGdd�dt��t��dd���fdd��}|����jtjd�dS)Nc@rV)z7PatchTest.test_patchobject_with_none.<locals>.SomethingNrWrrrrrZsr[rZrYc����jd�dSr])�assertIsNonerYrrarrrbv�z2PatchTest.test_patchobject_with_none.<locals>.testrd)r+r
r_rYr	rXrfrrar�test_patchobject_with_noners�z$PatchTest.test_patchobject_with_nonecslGdd�dt��t��dtj�t��dtj���fdd���}|����jtjd����jtj	d�dS)Nc@�eZdZejZejZdS)z6PatchTest.test_multiple_patchobject.<locals>.SomethingN�rrr r	rXrY�	Original2�next_attributerrrrrZ��
rZrYrqcs(���jtjd����jtjd�dSr])r_rYr	r`rq�Patched2rrarrrb����z1PatchTest.test_multiple_patchobject.<locals>.testrd)
r+r
r	r`rsr_rYrXrqrprfrrar�test_multiple_patchobjects��z#PatchTest.test_multiple_patchobjectcCsHt}tdttj�dd��}ztja|�|�ttj�W|adS|aw)N�%s.somethingcSr/rrrrrrrb��z8PatchTest.test_object_lookup_is_quite_lazy.<locals>.test)�	somethingr
rr	�
Something2Zreplacement_valuer_�r�originalrbrrr� test_object_lookup_is_quite_lazy�s
z*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)	Nrvc���tjtjd�dSr])r_�PTModulerxr	ryrr5rrrb�s�z"PatchTest.test_patch.<locals>.testrdz%s.something_elsecs(��tjtjd���tjtjd�dSr])r_r~rxr	ry�something_else�
SomethingElserr5rrrb�rt�%s.opencs��tdd�tjd�dS)N�filename�rzopen not patched)r_�openr	�Handlerr5rrrb�s�)r
rr	ryr_r~rxrZr�rrr��return_value�builtin_string�assertNotEqualr�)rrb�mockrr5r�
test_patch�s:�����zPatchTest.test_patchcs6tdttj��fdd��}|���tjjd�dS)Nz%s.SomeClass.class_attributecs��tjjtjd�dSr])r_r~r�class_attributer	�ClassAttributerr5rrrb�s
�z2PatchTest.test_patch_class_attribute.<locals>.testrd)r
rr	r�rkr~rr�rfrr5r�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@rn)z:PatchTest.test_patchobject_with_default_mock.<locals>.TestN)rrr r	rXrxrp�
something2rrrr�Test�rrr�rxcs"��|�jd���|td�dS)N�"Mock not passed into test function�.patch with two arguments did not create a mock)r_rx�assertIsInstancer
�r�)r�rrrrb�s
��z:PatchTest.test_patchobject_with_default_mock.<locals>.testr�cs���|tjd���|tjd���|�jd���|�jd���|td���|td����|d����|d�||fS)Nz0Patched function didn't receive initial argumentz/Patched function didn't receive second argumentr�z)Second Mock not passed into test functionr�zunexpected value for mock1)	r_r	�this1�this2r�rxr�r
r�)r�r�Zmock1Zmock2�r�Z
outerMock1Z
outerMock2rrrrb�s*
�
�
�
���)r+r
r	r�r�rfrr�r�"test_patchobject_with_default_mock�s


z,PatchTest.test_patchobject_with_default_mockcs&tdttd��fdd��}|�dS)N�%s.SomeClass��specc�2��t|���ttjt����tdd��dS)NcS�tjSr�r�
not_wibblerrrr�<lambda>�z>PatchTest.test_patch_with_spec.<locals>.test.<locals>.<lambda>�r_rrQr�wibbler
rO�AttributeError��
MockSomeClassr5rrrb�z,PatchTest.test_patch_with_spec.<locals>.test)r
rrrfrr5r�test_patch_with_specs
zPatchTest.test_patch_with_speccs&tjtdtd��fdd��}|�dS)Nr�r�c�6��tj|���ttjjt����tdd��dS)NcS�tjjSr�rr�r�rrrrr��zDPatchTest.test_patchobject_with_spec.<locals>.test.<locals>.<lambda>�	r_rr�rQrr�r
rOr��Z
MockAttributer5rrrb���z2PatchTest.test_patchobject_with_spec.<locals>.test�r
r+rrfrr5r�test_patchobject_with_spec
�
z$PatchTest.test_patchobject_with_speccs(tdtdgd��fdd��}|�dS)Nr�r�r�cr�)NcSr�rr�rrrrr�r�zFPatchTest.test_patch_with_spec_as_list.<locals>.test.<locals>.<lambda>r�r�r5rrrbr�z4PatchTest.test_patch_with_spec_as_list.<locals>.test�r
rrfrr5r�test_patch_with_spec_as_lists
z&PatchTest.test_patch_with_spec_as_listcs(tjtddgd��fdd��}|�dS)Nr�r�r�cr�)NcSr�rr�rrrrr�*r�zLPatchTest.test_patchobject_with_spec_as_list.<locals>.test.<locals>.<lambda>r�r�r5rrrb$r�z:PatchTest.test_patchobject_with_spec_as_list.<locals>.testr�rfrr5r�"test_patchobject_with_spec_as_list#s
z,PatchTest.test_patchobject_with_spec_as_listcs4tdt�tdtdgd��fdd���}|�dS)Nr�r�r�r�cr�)NcSr�rr�rrrrr�6r�zMPatchTest.test_nested_patch_with_spec_as_list.<locals>.test.<locals>.<lambda>r�)r�ZMockOpenr5rrrb1sz;PatchTest.test_nested_patch_with_spec_as_list.<locals>.test)r
r�rrfrr5r�#test_nested_patch_with_spec_as_list/s

z-PatchTest.test_nested_patch_with_spec_as_listc�&tdtdd��fdd��}|�dS)Nr�Tr�c�*��t���j��t�fdd��dS)Nc��jSr�r�rr�rrr�Ar�zIPatchTest.test_patch_with_spec_as_boolean.<locals>.test.<locals>.<lambda>�r_rr�rOr�r�r5r�rrb;�z7PatchTest.test_patch_with_spec_as_boolean.<locals>.testr�rfrr5r�test_patch_with_spec_as_boolean:r�z)PatchTest.test_patch_with_spec_as_booleancs&tjtddd��fdd��}|�dS)NrTr�cr�)Ncr�rr�rr�rrr�Mr�zPPatchTest.test_patch_object_with_spec_as_boolean.<locals>.test.<locals>.<lambda>r�r�r5r�rrbGr�z>PatchTest.test_patch_object_with_spec_as_boolean.<locals>.test)r
r+r~rfrr5r�&test_patch_object_with_spec_as_booleanFr�z0PatchTest.test_patch_object_with_spec_as_booleancr�)Nr�Tr�cs>��t|t��|�������j��t�fdd��dS)Ncr�rr�r��instancerrr�[r�zVPatchTest.test_patch_class_acts_with_spec_is_inherited.<locals>.test.<locals>.<lambda>)rQrr
rUr�rOr�r�r5r�rrbSs

zDPatchTest.test_patch_class_acts_with_spec_is_inherited.<locals>.testr�rfrr5r�,test_patch_class_acts_with_spec_is_inheritedRs
	z6PatchTest.test_patch_class_acts_with_spec_is_inheritedcs:tdttjdd��fdd��}|���tdd��dS)N�
%s.froobleT��createcs��ttj�dSr)r_�froobler	�Frooblerr5rrrbarlzLPatchTest.test_patch_with_create_mocks_non_existent_attributes.<locals>.testcS�tSr�r�rrrrr�fr3zPPatchTest.test_patch_with_create_mocks_non_existent_attributes.<locals>.<lambda>)r
r�r	r�rO�	NameErrorrfrr5r�4test_patch_with_create_mocks_non_existent_attributes`�z>PatchTest.test_patch_with_create_mocks_non_existent_attributescs:tjtdtjdd��fdd��}|���ttd��dS)Nr�Tr�cs��tjtj�dSr)r_rr�r	r�rr5rrrbj�zRPatchTest.test_patchobject_with_create_mocks_non_existent_attributes.<locals>.test)r
r+rr	r�rR�hasattrrfrr5r�:test_patchobject_with_create_mocks_non_existent_attributesir�zDPatchTest.test_patchobject_with_create_mocks_non_existent_attributescCs\|�t��tdttj�dd��}|�Wd�n1swY|�tdd��dS)Nr�cSr/rrrrrrrbtr9z9PatchTest.test_patch_wont_create_by_default.<locals>.testcSr�rr�rrrrr�xr3z=PatchTest.test_patch_wont_create_by_default.<locals>.<lambda>)rOr�r
r�r	r�r�rfrrr�!test_patch_wont_create_by_defaultrs
�z+PatchTest.test_patch_wont_create_by_defaultcCs\|�t��t�tdtj�dd��}|�Wd�n1swY|�ttd��dS)N�ordcSr/rrrrrrrb}r9z?PatchTest.test_patchobject_wont_create_by_default.<locals>.test)	rOr�r
r+rr	r�rRr�rfrrr�'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
rr_)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>.FoocSr�r)r	�Staticrrrr�woot�sz:PatchTest.test_patch_with_static_methods.<locals>.Foo.wootN)rrr rAr�rrrrr.�sr.r�cSr�r)r	r`rrrrr��r�z:PatchTest.test_patch_with_static_methods.<locals>.<lambda>cs�����tj�dSr)r_r�r	r`r�r.rrr�	anonymous�rcz;PatchTest.test_patch_with_static_methods.<locals>.anonymous)r+r
rAr_r�r	r�)rr�rr�r�test_patch_with_static_methods�s
z(PatchTest.test_patch_with_static_methodscs8tj}t�tdd��fdd��}|���tj|�dS)Nr.cs��tjd�dS�Nr.)r_r	r.rr5rrr��rlz-PatchTest.test_patch_local.<locals>.anonymous)r	r.r
r+r_)rr@r�rr5r�test_patch_local�s
zPatchTest.test_patch_localcsTGdd�dt�}|��tj�_t��dd���fdd��}|����jtj�dS)Nc@�eZdZdZdS)z'PatchTest.test_patch_slots.<locals>.Foo)r.N)rrr �	__slots__rrrrr.��r.crjr�)r_r.r�r@rrrr��rlz-PatchTest.test_patch_slots.<locals>.anonymous)r+r	r.r
r_)rr.r�rr�r�test_patch_slots�szPatchTest.test_patch_slotscsfGdd�dt��G��fdd�dt�}t��dtj�|�}|�}|��|�����jtjd�dS)Nc@rV)z=PatchTest.test_patchobject_class_decorator.<locals>.SomethingNrWrrrrrZ�r[rZc�(eZdZ��fdd�Z��fdd�ZdS)z7PatchTest.test_patchobject_class_decorator.<locals>.Foocr\r]r^��
other_selfrarr�test_method���zCPatchTest.test_patchobject_class_decorator.<locals>.Foo.test_methodcr\�Nznon-test method patched)r_rYr	rXr�rarr�not_test_method�r�zGPatchTest.test_patchobject_class_decorator.<locals>.Foo.not_test_methodN)rrr r�r�rrarrr.�sr.rYrd)	r+r
r	r`r�r�r_rYrX)rr.r4rrar� test_patchobject_class_decorator�s�z*PatchTest.test_patchobject_class_decoratorcsrGdd�dt�}G�fdd�dt�}tdt�|�}|�}|��|����|jtjd���t	j
tjd�dS)Nc@rV)z7PatchTest.test_patch_class_decorator.<locals>.SomethingNrWrrrrrZ�r[rZcs(eZdZdZ�fdd�Z�fdd�ZdS)z1PatchTest.test_patch_class_decorator.<locals>.FooZwhatevercs��tj|d�dSr])r_r~rx)r�Zmock_somethingr5rrr��s
�z=PatchTest.test_patch_class_decorator.<locals>.Foo.test_methodcr}r�)r_r~rxr	rZr�r5rrr��r�zAPatchTest.test_patch_class_decorator.<locals>.Foo.not_test_methodN)rrr Ztest_class_attrr�r�rr5rrr.�sr.rvrd)r+r
rr�r�r_rYr	rXr~rxrZ)rrZr.r4rr5r�test_patch_class_decorator�s
��z$PatchTest.test_patch_class_decoratorcsZGdd�dt��t��dtj�t��dtj���fdd���}|����jtjd�dS)Nc@rn)z3PatchTest.test_patchobject_twice.<locals>.SomethingNrorrrrrZ�rrrZrYcr\r]r^rrarrrb�sz.PatchTest.test_patchobject_twice.<locals>.testrdrerfrrar�test_patchobject_twice�s�z PatchTest.test_patchobject_twicecs�t�dd�����}t����fdd��}|����|�t��ddi���fdd��}|����|�t��dg���fd	d��}|����|�dS)
Nrx��initial�otherc�d�d<�d=d�d<dS�N�r1r��something elser�rr�r@rrrb�z'PatchTest.test_patch_dict.<locals>.testr1rDc�$��t��d����dd�dS�Nr�r1rD�r_�lenrr�rrrb�rCcr�r�r�rr�rrrbr��r+�copyr
�dictr_rzrr�r�test_patch_dict�szPatchTest.test_patch_dictcs�t��t��d<d�d<�j��}t����fdd��}|����j|�t��ddi���fdd��}|����j|�dS)	Nr�rxr�cr�r�rrr�rrrb&r�z=PatchTest.test_patch_dict_with_container_object.<locals>.testr1rDcs&��t�j�d����dd�dSr�)r_r�rHrr�rrrb0s�rFr+rHrr
rr_rzrr�r�%test_patch_dict_with_container_objects

z/PatchTest.test_patch_dict_with_container_objectcs�t�dd�����}tj�dd���fdd��}|����|�tj�ddidd���fd	d��}|����|�tj�d
gdd���fdd��}|����|�dS)Nrxr�T��clearcs ���i�d�d<d�d<dS�Nr�r1r�r��r_rr�rrrb>sz2PatchTest.test_patch_dict_with_clear.<locals>.testr1rDc����ddi�dS�Nr1rDr	rr�rrrbHr�rCcr
rr	rr�rrrbPr�rrzrr�r�test_patch_dict_with_clear:s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�rxr�Trcs"���ji�d�d<d�d<dSr�r_rHrr�rrrb`szGPatchTest.test_patch_dict_with_container_object_and_clear.<locals>.testr1rDcs���jddi�dSrr
rr�rrrbjrcrrzrr�r�/test_patch_dict_with_container_object_and_clearYs

z9PatchTest.test_patch_dict_with_container_object_and_clearcCsZddi}tj|dd��}|�|ddi�Wd�n1swY|�|ddi�dS)Nr1rDr�)r1)r
rr_)rr@�patchedrrr�"test_patch_dict_as_context_managerss
�z,PatchTest.test_patch_dict_as_context_managercCsZi}tdtt��tdtt�dd�t�tt��t�|�dd�����}|�|jd�dS)Nr�T��autospeccSr/rrrrrr�	some_name}sz0PatchTest.test_name_preserved.<locals>.some_namer)r
rr+rrr_)rr@rrrr�test_name_preservedzszPatchTest.test_name_preservedcCs\i}t�|ddi�dd��}|�t��|�Wd�n1s!wY|�|i�dS)Nr1rDcS�td��)NZKonrad�r�rrrrrb�sz1PatchTest.test_patch_with_exception.<locals>.test)r
rrOr�r_)rr@rbrrr�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�environrr5rrrb�rlz3PatchTest.test_patch_dict_with_string.<locals>.test)r
rrfrr5r�test_patch_dict_with_string�s
z%PatchTest.test_patch_dict_with_stringcs^tj��}t�dddi��fdd��}zddit_|���tjddi�W|t_dS|t_w)Nz%unittest.test.testmock.support.targetr7�BARcs��tjddd��dS)N�BAZr�r@r7)r_r�targetrr5rrrb�sz<PatchTest.test_patch_dict_decorator_resolution.<locals>.testr@r)rr rr
rr_rzrr5r�$test_patch_dict_decorator_resolution�s

z.PatchTest.test_patch_dict_decorator_resolutioncCs�tdttdd�dd��}|�t|�tjtdtdd�dd��}|�t|�tdtdd�d	d��}|�t|�tjtddd�d
d��}|�t|�dS)Nr�T�r��spec_setcS�
d|_dS�Nr@��z�rTrrrrb��
z+PatchTest.test_patch_spec_set.<locals>.testrcSr$r%r&r(rrrrb�r)�r#cSr$r%r&r(rrrrb�r)cSr$r%r&r(rrrrb�r))r
rrrOr�r+rrfrrr�test_patch_spec_set�s



zPatchTest.test_patch_spec_setcCs(tdtdd�dd��}|�t|�dS)Nr�Tr*cSs|�}d|_dSr%r&)rTr�rrrrb�s
z-PatchTest.test_spec_set_inherit.<locals>.test)r
rrOr�rfrrr�test_spec_set_inherit�s
zPatchTest.test_spec_set_inheritcCsdt}tdt�}|�t|�|��}z|�||�|�t|�W|��n|��w|�t|�dS)Nrv)rxr
r�assertIs�start�assertIsNot�stop)rr{�patcherr�rrr�test_patch_start_stop�szPatchTest.test_patch_start_stopcCsttdd�}|�|���dS�Nr7r�)r
�foo_namerkr0�rr1rrr�test_stop_without_start�sz!PatchTest.test_stop_without_startcCs.ttdd�}|��|��|�|���dSr3)r
r4r.r0rkr5rrr�test_stop_idempotent�szPatchTest.test_stop_idempotentcCsft}t�tdd�}|�t|�|��}z|�|d�|�t|�W|��n|��w|�t|�dS)Nrxr@)rxr
r+r~r-r.r_r0)rr{r1Zreplacedrrr�test_patchobject_start_stop�sz%PatchTest.test_patchobject_start_stopcCsnddi}|��}tj|dgdd�}|�||�|��z|�|ddi�W|��n|��w|�||�dS)Nr@r7��spam�eggsTrr:r;)rr
rr_r.r0�r�dr{r1rrr�test_patch_dict_start_stop�sz$PatchTest.test_patch_dict_start_stopcCs@ddi}|��}tj|dgdd�}|�|���|�||�dS)Nr@r7r9Tr)rr
rrRr0r_r<rrr�"test_patch_dict_stop_without_starts
z,PatchTest.test_patch_dict_stop_without_startcs�|�ddi����}G��fdd�dt�}tj�ddidd�|�}|��|�|�}|��|��|�|��|��|�|�}|��|��|�|��|��|�dS)	Nr:r;cr�)z7PatchTest.test_patch_dict_class_decorator.<locals>.Testcr
�Nr@r7r	r5�r=�thisrr�
test_first�zBPatchTest.test_patch_dict_class_decorator.<locals>.Test.test_firstcr
r@r	r5rArr�test_secondrDzCPatchTest.test_patch_dict_class_decorator.<locals>.Test.test_secondN)rrr rCrErrArrr�sr�r@r7Tr)rr+r
rr_rCrE)rr{r�rbrrAr�test_patch_dict_class_decorator
s z)PatchTest.test_patch_dict_class_decoratorcs�Gdd�dt�}Gdd�d�}|||�|fD],}t|��t��dd���fdd��}|����jd���|jd���d�j�qdS)	Nc@r�)z0PatchTest.test_get_only_proxy.<locals>.Somethingr@N�rrr r@rrrrrZ-r�rZc@r�)z4PatchTest.test_get_only_proxy.<locals>.SomethingElser@NrGrrrrr�/r�r�r@r7crj�Nr7�r_r@r��proxyrrrrb5rlz+PatchTest.test_get_only_proxy.<locals>.test�r+r-r
r_r@ZassertNotIn�__dict__�rrZr��thingrbrrJr�test_get_only_proxy,s�zPatchTest.test_get_only_proxycs�Gdd�dt�}Gdd�d�}|||�|fD].}t|dd��t��dd���fd	d
��}|����jd���|jd���d�j�qdS)Nc@r�)z6PatchTest.test_get_set_delete_proxy.<locals>.Somethingr@NrGrrrrrZ?r�rZc@r�)z:PatchTest.test_get_set_delete_proxy.<locals>.SomethingElser@NrGrrrrr�Ar�r�F)r,r@r7crjrHrIrrJrrrbGrlz1PatchTest.test_get_set_delete_proxy.<locals>.testrLrNrrJr�test_get_set_delete_proxy>s�z#PatchTest.test_get_set_delete_proxycCs^tdt�d�}ttfi|��}|��}|��|�t|�|�|j�	�d�|�
|jt�dS)N�!�Zside_effectzfoo.bar.return_valuer@)�KeyErrorr
r
r4r.r0rOr_r@r7r��r�kwargsr1r�rrr�test_patch_keyword_argsPs�z!PatchTest.test_patch_keyword_argscCsbtdt�d�}tjtdfi|��}|��}|��|�t|�|�|j	�
�d�|�|j	t�dS)NrRrSr4)rTr
r
r+r.r.r0rOr_r@r7r�rUrrr�test_patch_object_keyword_args]s�z(PatchTest.test_patch_object_keyword_argscCshddi}|��}tj|dddd�}|��z|�|tdddd��W|��n|��w|�||�dS)Nr@r7r���)r@r7Zbaz)rr
rr.r_r0)rr{rr1rrr�test_patch_dict_keyword_argsjsz&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>.BoocSr/rrr0rrrr2{r3z-PatchTest.test_autospec.<locals>.Boo.__init__cSr/rrr0rrrr4|r3z&PatchTest.test_autospec.<locals>.Boo.fcSr/rrr5rrrr6}r3z&PatchTest.test_autospec.<locals>.Boo.gr7c@r<)z(PatchTest.test_autospec.<locals>.Boo.BarcSr/rrr5rrrr1�r3z*PatchTest.test_autospec.<locals>.Boo.Bar.aNr=rrrrr>�r?r>N)	rrr r2r4r6r@r+r>rrrr�Boozsr\cs"|d�|�d���t|�dS�N�)�assert_called_withrOrPr�r5rr�_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^�hr7rD)r4r_rOrPr6r�rr@�lowerr>r1r�r5rr�_test2�s(




z'PatchTest.test_autospec.<locals>._test2cs,�|��|��|d����|t�|Sr])r-r.r��r`rcrrrrE�s
z)PatchTest.test_autospec.<locals>.functionTrr.)r+r
r4r/r.�sys�modulesr)rr\rErbr��modulerrdr�
test_autospecys	

zPatchTest.test_autospeccr�)N�%s.functionTrcs�t����ttj���ttj�td���ttj�t�d�t��t��tdd�t�dd���tt���tt	td�dS)Nr^�r�r@)
rEZassert_not_calledrO�AssertionErrorZ
assert_calledZassert_called_oncer_rPr�rr�r5rrrb�s

z.PatchTest.test_autospec_function.<locals>.testr�rfrr5r�test_autospec_function�s
z PatchTest.test_autospec_functioncCs0tdtddd�dd��}|�}|�|d�dS)NriTr�)rr�cSs
tdd�S)Nr^rj)rE)Z
mock_functionrrrrb�s
z.PatchTest.test_autospec_keywords.<locals>.testr�)rrb�resultrrr�test_autospec_keywords�s
�
z PatchTest.test_autospec_keywordscC�Ftdtdd��}t��|��Wd�dS1swYdS)Nz%s.Foo.static_methodTr)r
rr.r8�assert_called_once_with�r�methodrrr�test_autospec_staticmethod��
"�z$PatchTest.test_autospec_staticmethodcCro)Nz%s.Foo.class_methodTr)r
rr.r;rprqrrr�test_autospec_classmethod�rtz#PatchTest.test_autospec_classmethodcCsNtdtddd�}|�t|j�tjt}tj|dddd�}|�t|j�dS)Nrir�T)�newrrE)r
rrOrPr.rerfr+)rr1rgrrr�test_autospec_with_new�s

z PatchTest.test_autospec_with_newcCsXGdd�dt�}tt|d�}|��}z|�||�|�|jt�W|��dS|��w)Nc@seZdZgZdS)z0PatchTest.test_autospec_with_object.<locals>.BarN)rrr �extrarrrrr>�r�r>r)r.r
r4r.r�rx�listr0)rr>r1r�rrr�test_autospec_with_object�sz#PatchTest.test_autospec_with_objectcCsNt}ttdd�}|��}z|�||�|�|d�|�W|��dS|��w)NTrr�)r.r
r4r.r�r0)rZFooClassr1r�rrr�test_autospec_inherits�sz PatchTest.test_autospec_inheritscCszttdd�}|��}z-|�dt|��|�dt|j��|�dt|d���|�dt|d�j��W|��dS|��w)NTrz name='Foo'z
 name='Foo.f'z
 name='Foo()'z name='Foo().f')r
r4r.r�reprr4r0)rr1r�rrr�test_autospec_nameszPatchTest.test_autospec_namecCs^t�tdt��dd��}z|�Wnt��}Yt�ddd�}|�||�}|�d|�dS)Nr4cS�t�r)rkrrrrrbrwz'PatchTest.test_tracebacks.<locals>.testrzraise AssertionError)	r
r+r.re�exc_info�unittestZTextTestResultZ_exc_info_to_stringr)rrb�errrm�	tracebackrrr�test_tracebackss


zPatchTest.test_tracebackscCsTtttd�}|��}|��|��}|��|�||�||fD]}|�|�q dS)N��new_callable)r
r4rr.r0r/rU�rr1Zm1Zm2r�rrr�test_new_callable_patch#s�z!PatchTest.test_new_callable_patchcCsXtjtdtd�}|��}|��|��}|��|�||�||fD]}|�|�q"dS)Nr4r�)r
r+r.rr.r0r/rUr�rrr�test_new_callable_patch_object0s�z(PatchTest.test_new_callable_patch_objectcslG�fdd�dt��tt�ddd�}|��}z|�t|���|��jtddd��W|�	�dS|�	�w)Nc�eZdZdZ�fdd�ZdS)z:PatchTest.test_new_callable_keyword_arguments.<locals>.BarNc�
|�_dSr�rV�rrV�r>rrr2@rzCPatchTest.test_new_callable_keyword_arguments.<locals>.Bar.__init__�rrr rVr2rr�rrr>>�r>r^rj)r��arg1�arg2)r�r�)
r+r
r4r.r-�typer_rVrr0)rr1r�rr�r�#test_new_callable_keyword_arguments=sz-PatchTest.test_new_callable_keyword_argumentscs�G�fdd�dt��tt��d�}|��z|��jt�d��W|��n|��wtt��d�}|��z|��jt�d��W|��dS|��w)Ncr�)z-PatchTest.test_new_callable_spec.<locals>.BarNcr�rr�r�r�rrr2Orz6PatchTest.test_new_callable_spec.<locals>.Bar.__init__r�rr�rrr>Mr�r>�r�r�r�)r�r#r*)r+r
r4r.r_rVrr0r5rr�r�test_new_callable_specLsz PatchTest.test_new_callable_speccCs`dt}t|td�}|�t|j�t|tdd�}|��}z|j|dd�W|��dS|��w)Nz	%s.weeeeer�T)r�r�F)rS)r4r
rrOr�r.rUr0)rZnon_existent_attr�pr�rrr�test_new_callable_createas�z"PatchTest.test_new_callable_createcCs4|jtttt�td�|jttjtdt�td�dS)N)rvr�r4)rO�
ValueErrorr
r4r+r
r.r5rrr�'test_new_callable_incompatible_with_newos�
�z1PatchTest.test_new_callable_incompatible_with_newcCs0|jttttdd�|jttjtdtdd�dS)NT)r�rr4)rOr�r
r4r
r+r.r5rrr�,test_new_callable_incompatible_with_autospecys�
�z6PatchTest.test_new_callable_incompatible_with_autospecc	
Cs�Gdd�dt�}tttt|f}|D]/}dD]*}|di}ttfd|i|��}|��}z|j}|�t	t
|d�W|��q|��wqdS)Nc@�eZdZdS)z>PatchTest.test_new_callable_inherit_for_mocks.<locals>.MockSubN�rrr rrrr�MockSub��r�r"Tr��x)rrrr
r
r4r.r�rOr�rr0)	rr�ZMockClassesZKlass�argrVr�r�r�rrr�#test_new_callable_inherit_for_mocks�s
���z-PatchTest.test_new_callable_inherit_for_mockscCspGdd�dt�}tt|dd�}|��}z|�t||��|�tt|d�W|�	�n|�	�w|�
|jt�dS)Nc@r<)z>PatchTest.test_new_callable_inherit_non_mock.<locals>.NotAMockcSs
||_dSrr�)rr�rrrr2�rzGPatchTest.test_new_callable_inherit_non_mock.<locals>.NotAMock.__init__N)rrr r2rrrr�NotAMock�r?r�Tr�r�)
r+r
r4r.rQrrOr�rr0r_r�r.)rr�r�r�rrr�"test_new_callable_inherit_non_mock�sz,PatchTest.test_new_callable_inherit_non_mockcsR|�t�G��fdd�dt�}tttd�|�}|���|���|�t��dS)Nc�*eZdZ��fdd�Zdd�Zdd�ZdS)z>PatchTest.test_new_callable_class_decorating.<locals>.SomeTestcs(��t����t|���tt�dSr)r/r.r-r�r�rZmock_foo�r{rbrrr`�szDPatchTest.test_new_callable_class_decorating.<locals>.SomeTest._testcS�|�|�dSr�r`r�rrr�test_two�r*zGPatchTest.test_new_callable_class_decorating.<locals>.SomeTest.test_twocSr�rr�r�rrr�test_one�r*zGPatchTest.test_new_callable_class_decorating.<locals>.SomeTest.test_oneN�rrr r`r�r�rr�rr�SomeTest�sr�r�)r.r+r
r4rr�r�r-)rr�rr�r�"test_new_callable_class_decorating�s

z,PatchTest.test_new_callable_class_decoratingc	s�t�tj}tj}tjtddd�}tjtddd�}||fD]:}|��z��t����tjd���tjd�W|�	�n|�	�w��t����tj|���tj|�qtjtddd���fdd��}|�dS)Nr^rj)r4r6r�rYcs,��t����tjd���tjd�dS)Nr�rY)r-r.r_r4r6r��original_foorrrrb�sz+PatchTest.test_patch_multiple.<locals>.test)
r.r4r6r
�multipler4r.r-r_r0)r�
original_f�
original_gZpatcher1Zpatcher2r1rbrr�r�test_patch_multiple�s$
zPatchTest.test_patch_multiplecCs$|�ttjt�|�ttjt�dSr)rOr�r
r�r4r.r5rrr�test_patch_multiple_no_kwargs�sz'PatchTest.test_patch_multiple_no_kwargscsVt�tj}tj}tjttdtd���fdd��}|���tj|���tj|�dS)Nr��r4r6r@csZ��t����tj|���tjd���tj|���t|t����t|t��dS�Nr��	r-r.r4r_r6r@rQrr
)r4r@r�rrrb�sz8PatchTest.test_patch_multiple_create_mocks.<locals>.test�r.r4r6r
r�r4rr_)rr�r�rbrr�r� test_patch_multiple_create_mocks�sz*PatchTest.test_patch_multiple_create_mockscsrtj}tj}t�tdd�}d|_t�tdt�}d|_|g|_|�fdd��}|���tj|���tj|�dS)Nr4r�r6cs ��tj|���tjd�dSr�)r-r.r6r_r4)r6r5rrrb�szHPatchTest.test_patch_multiple_create_mocks_different_order.<locals>.test)	r.r4r6r
r+�attribute_namer�additional_patchersr_)rr�r�r1r�rbrr5r�0test_patch_multiple_create_mocks_different_order�sz: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)r4r�z.gc��|fi|��dSrr�r6rVr�rr�test1
�z?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test1cr�rrr�r�rr�test2r�z?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test2cr�rrr�r�rr�test3r�z?PatchTest.test_patch_multiple_stacked_decorators.<locals>.test3cs�|�d�}|�d�}��|���t����tj|���tj|���tj|���t|t	����t|t	����t|t	��dS)Nr4r@)
�poprRr-r.r4r6r@rQrr
)r6rVr4r@r�rrr`s


z?PatchTest.test_patch_multiple_stacked_decorators.<locals>._testr�)rr�r�r�r�r�r)r`r�rr�&test_patch_multiple_stacked_decoratorss*



z0PatchTest.test_patch_multiple_stacked_decoratorscCs�t}tj}tj}tjttdtd�}|��}z>|d}|d}|�t	|�t	ddg��|�
t|�|�
tj|�|�
tj|�|�t
|t��|�t
|t��W|��n|��w|�tj|�|�tj|�dS)Nr�r�r4r@)r.r4r6r
r�r4rr.r_�setr-r@rQrr
r0)rr�r�r�r1rmr4r@rrr�(test_patch_multiple_create_mocks_patcher3s"z2PatchTest.test_patch_multiple_create_mocks_patchercsv|�t�tj}tj}G��fdd�dt�}tjttdtd�|�}|�}|��|�	�|�
tj|�|�
tj|�dS)Ncr�)z@PatchTest.test_patch_multiple_decorating_class.<locals>.SomeTestcsZ��t����tj|���tjd���tj|���t|t����t|t��dSr�r��rr4r@�r�rbrrr`TszFPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest._testcS�|�||�dSrr�r�rrrr�\r'zIPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest.test_twocSr�rr�r�rrrr�^r'zIPatchTest.test_patch_multiple_decorating_class.<locals>.SomeTest.test_oneNr�rr�rrr�Rsr�r�r�)r.r4r6r+r
r�r4rr�r�r_)rr�r�r�rOrr�r�$test_patch_multiple_decorating_classLs��z.PatchTest.test_patch_multiple_decorating_classcCsntjtdd�}|�t|j�tjtddd�}|��z
|�tjd�W|��n|��w|�	t
td��dS)N�blam)r�T)r�r�)r
r�r.rOr�r.r_r�r0rRr�r5rrr�test_patch_multiple_createmsz$PatchTest.test_patch_multiple_createcCs�tjttddgd�}|��}z4|�tj|d�tj�d�tj�d�tjj�	d�tjj�	d�|�
tttjdd�W|�
�dS|�
�w)Nr1rD)r@r#r@r^rjr�)r
r�r.rr.r_r@r1rDr_rOr�r#r0)rr1rmrrr�test_patch_multiple_spec_set{sz&PatchTest.test_patch_multiple_spec_setcCs�Gdd�dt�}tjttt|d�}|��}z/|�tj|d�|�tj|d�|�	tj|�|�	tj|�|�
tjtj�W|��dS|��w)Nc@r�)z9PatchTest.test_patch_multiple_new_callable.<locals>.ThingNr�rrrr�Thing�r�r�)r4r6r�r4r6)r+r
r�r.rr.r-r4r6r�r/r0)rr�r1rmrrr� test_patch_multiple_new_callable�s�z*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
����}|||fD]}|�t|�|�tj|�|�tj|�qVdS)Nr6r^�missingr4cSr/rrrrrr�thing1��z3PatchTest.test_nested_patch_failure.<locals>.thing1cSr/rrrrrr�thing2�r�z3PatchTest.test_nested_patch_failure.<locals>.thing2cSr/rrrrrr�thing3�r�z3PatchTest.test_nested_patch_failure.<locals>.thing3)r.r4r6r
r+rOr�r_)rr�r�r�r�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
����}|||fD]}|�t|�|�tj|�|�tj|�|�tj|�q`dS)NcSr�N�crasherrrrrrr���z4PatchTest.test_new_callable_failure.<locals>.crasherr6r^r@r�r4cSr/rrrrrrr��r�z3PatchTest.test_new_callable_failure.<locals>.thing1cSr/rrrrrrr��r�z3PatchTest.test_new_callable_failure.<locals>.thing2cSr/rrrrrrr��r�z3PatchTest.test_new_callable_failure.<locals>.thing3)	r.r4r6r@r
r+rOr�r_)	rr�r�r�r�r�r�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|_||g||gfD]}||_|dd��}|�t|�|�	tj|�|�	tj|�q,dS)Nr4r^r6r�cSr/rrrrrrr��r9z3PatchTest.test_patch_multiple_failure.<locals>.func)
r.r4r6r
r+r�r�rOr�r_)rr�r�r1�good�bad�additionalsr�rrr�test_patch_multiple_failure�s 
�z%PatchTest.test_patch_multiple_failurec
Cs�tj}tj}tj}dd�}t�tdd�}d|_t�tdd�}d|_tjtd|d�}d|_||g||gfD]&}||_|dd	��}	|�t	|	�|�
tj|�|�
tj|�|�
tj|�q4dS)
NcSrr�rrrrrr��r�zCPatchTest.test_patch_multiple_new_callable_failure.<locals>.crasherr4r^r6r@r�cSr/rrrrrrr�r9z@PatchTest.test_patch_multiple_new_callable_failure.<locals>.func)r.r4r6r@r
r+r�r�rOr�r_)
rr�r�r�r�r1r�r�r�r�rrr�(test_patch_multiple_new_callable_failure�s&
�z2PatchTest.test_patch_multiple_new_callable_failurecsLtdtfddi�}|��tj�dd���fdd��}|����jd�dS)Nr.�fishZtasty�nearly gone)r�crj)Nr�)r_r�rr�rrrbrlz=PatchTest.test_patch_multiple_string_subclasses.<locals>.test)r��strr
r�r_r�)rr.rbrr�r�%test_patch_multiple_string_subclasses	sz/PatchTest.test_patch_multiple_string_subclasseszunittest.mock.patch.TEST_PREFIXr@cCslGdd�dt�}t�|dd�|�}|�}|�|��d�|�|��d�|�|��d�|�|��d�dS)Nc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)z-PatchTest.test_patch_test_prefix.<locals>.Foor{cS�|jSr�rOr5rrr�foo_one�z5PatchTest.test_patch_test_prefix.<locals>.Foo.foo_onecSr�rr�r5rrr�foo_twor�z5PatchTest.test_patch_test_prefix.<locals>.Foo.foo_twocSr�rr�r5rrrr�r�z6PatchTest.test_patch_test_prefix.<locals>.Foo.test_onecSr�rr�r5rrrr�r�z6PatchTest.test_patch_test_prefix.<locals>.Foo.test_twoN)rrr rOr�r�r�r�rrrrr.sr.rO�changedr{)r+r
r_r�r�r�r��rr.r@rrr�test_patch_test_prefixsz PatchTest.test_patch_test_prefixr7cs�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>.Fooc�t��Sr�rr5�Zthe_dictrr�bar_one.r�z:PatchTest.test_patch_dict_test_prefix.<locals>.Foo.bar_onecr�rr�r5r�rr�bar_two0r�z:PatchTest.test_patch_dict_test_prefix.<locals>.Foo.bar_twocr�rr�r5r�rrr�2r�z;PatchTest.test_patch_dict_test_prefix.<locals>.Foo.test_onecr�rr�r5r�rrr�4r�z;PatchTest.test_patch_dict_test_prefix.<locals>.Foo.test_twoN)rrr r�r�r�r�rr�rrr.-s
r.�keyr{r�)r�)r+r
rr_r�r�r�r�r�rr�r�test_patch_dict_test_prefix+s
z%PatchTest.test_patch_dict_test_prefixc	Cs�dD]A}tdtfi|di��}|��}z*|�dt|��|�dt|j��|�dt|���|�dt|�j��W|��q|��wdS)N�r�rr#r�Tz name='SomeClass'z! name='SomeClass.class_attribute'z name='SomeClass()'z# name='SomeClass().class_attribute')r
rr.rr|r�r0)rr�r�r�rrr�test_patch_with_spec_mock_reprAs�
��z(PatchTest.test_patch_with_spec_mock_reprcCs`tddd�� }|�dt|j����|�dt|������Wd�dS1s)wYdS)N�unittest.test.testmock.supportTrz" name='support.SomeClass.wibble()'z$ name='support.SomeClass().wibble()')r
rr|rr�)rr�rrr�test_patch_nested_autospec_reprPs��"�z)PatchTest.test_patch_nested_autospec_reprc	CsdD]}tdtfi|di��}|��}zh|��t��g}|�|j|�|�|j|�|�|jjt�g�|�}|�t��|�|j|�|��|�t����|�|j|�|�|jt��g�|�|jjt�g�|�|jt��g�W|�	�q|�	�wdS)Nr�r�T)
r
rr.r�rr_Z
mock_callsZmethod_calls�appendr0)rr�r�r�Zkallsrmrrr�test_mock_calls_with_patchYs(
�z$PatchTest.test_mock_calls_with_patchcCs�td�}|�t|j�td��"t�}|tjd<d|_td�}d|_|��|�	�Wd�n1s4wY|�
|jd�dS)N�
squizz.squozz�squizz�r�)r
rO�ImportErrorr.rrrerfZsquozzr0r_)rZp1r�rrr�test_patch_imports_lazilyts


�	z#PatchTest.test_patch_imports_lazilycs�Gdd�d��G�fdd�dt���fdd�}|d�dd	��}td
��t�}|tjd
<|�t|�Wd�n1s<wY|��jdt�|�	�jdd
�|�	�jdd�dS)Nc@r�)z;PatchTest.test_patch_propagates_exc_on_exit.<locals>.holder�NNNN)rrr rrrrr�holder�r�r�cseZdZd�fdd�	ZeZdS)zAPatchTest.test_patch_propagates_exc_on_exit.<locals>.custom_patchNcs t�||||�|||f�_dSr)r�__exit__r)r�etype�val�tb�r�rrr�szJPatchTest.test_patch_propagates_exc_on_exit.<locals>.custom_patch.__exit__r�)rrr rr0rrrr�custom_patch�src
s$t|�\}}�||tdddddi�	S)NF)rr)r �getterrY)rrr�with_custom_patch�s
�zFPatchTest.test_patch_propagates_exc_on_exit.<locals>.with_custom_patchr�cSr~r)�RuntimeErrorr�rrrrb�rwz9PatchTest.test_patch_propagates_exc_on_exit.<locals>.testr�rr^zexception value not propagatedrjz"exception traceback not propagated)
rrrrerfrOrr-rZassertIsNotNone)rrrbr�r)rr�r�!test_patch_propagates_exc_on_exit�s"


���z+PatchTest.test_patch_propagates_exc_on_exitcCspdD]3}tdtfddi|di��}|�t|j�|�tdd��ttfddi|di��}|��|��qdS)N�r�r#rz%s.doesnotexistr�TcSr�r)�doesnotexistrrrrr��r3z1PatchTest.test_create_and_specs.<locals>.<lambda>)r
rrOrPr.r��MODNAMEr0)r�kwargr�rrr�test_create_and_specs�s�
�zPatchTest.test_create_and_specscCs�t}dD]}ttfddi|di��}|�t|j�|�t|�qdD]}ttfddi|di��}|�t|j�|�t|�q"dD]}ttfddi|di��}|�t|j�|�t|�q@dS)Nr"rr�r�rr#)r#rr�)r~r
rrOrPr.r-)rr{r
r�rrr�test_multiple_specs�s�zPatchTest.test_multiple_specscCs>ttdddd�}|��}z
|jd|_W|��dS|��w)NFr
r�)r
rr.Zdoes_not_existr0)rr�r�rrr� test_specs_false_instead_of_none�sz*PatchTest.test_specs_false_instead_of_nonec	CsPdD]#}ttfi|di��}|��}z|�tt|d�W|��q|��wdS)Nr�rZdoesnotexit)r
rr.rOr�rr0�rr
r�r�rrr�test_falsey_spec�s�zPatchTest.test_falsey_specc	CsfdD].}ttfddi|di��}|��}z|�tt|dd�|�tt|d�W|��q|��wdS)Nrr#Trrx)r
rr.rOr�r#rr0rrrr�test_spec_set_true�s
��zPatchTest.test_spec_set_truecC�@d}tt|d�}|��}z|�t|��W|��dS|��w)N)�__call__r�)r
rr.rQ�callabler0�rr�r�r�rrr�test_callable_spec_as_list��z$PatchTest.test_callable_spec_as_listcCr)Nrr�)r
rr.rRrr0rrrr�test_not_callable_spec_as_list�rz(PatchTest.test_not_callable_spec_as_listcs^tj�tj�tj}tdt���tdt���td����fdd��}|���tj|�dS)N�	os.unlink�os.chdirzos.pathcs6t����tj|���tj����tj��dSr)r
�stopallr-r�path�unlink�chdir)Z	mock_path�r!rr rrrsz-PatchTest.test_patch_stopall.<locals>.patched)	rr r!rr
rxr.rr-)rrrrr"r�test_patch_stopall�szPatchTest.test_patch_stopallcsPg�Gdd�dt����fdd���fdd�dD�t��|��gd��dS)	Nc@seZdZdZZZdS)z*PatchTest.test_stopall_lifo.<locals>.thingN)rrr �one�two�threerrrrrOr"rOc
s8G���fdd�dt����fdd��ddddddi�	S)Ncs"eZdZ����fdd�Z�ZS)z?PatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.mypatchcs����t�|���Sr)r��superr0r5)�	__class__rY�mypatch�stoppedrrr0s
zDPatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.mypatch.stop)rrr r0�
__classcell__r)rYr)r*)r(rr)sr)cs�Srrrr�rrr�r3z@PatchTest.test_stopall_lifo.<locals>.get_patch.<locals>.<lambda>F)r)rY)r*rO)rYr)r�	get_patchs
�z.PatchTest.test_stopall_lifo.<locals>.get_patchcsg|]}�|����qSr)r.)�.0r)r,rr�
<listcomp>sz/PatchTest.test_stopall_lifo.<locals>.<listcomp>)r$r%r&)r&r%r$)r+r
rr_r5r)r,r*rOr�test_stopall_lifo
szPatchTest.test_stopall_lifocs�i}ddi}ddd��|��}|��}���}t�|ddd����t�|dd	i���t����fd
d��}|�|�||�|�||�|��|�t��|�||�|�||�|��|�dS)Nr^r1�A�B�r^rj�I�IIrjrDcs
�d=dSr]rr�Zdic3rrr%r)z2PatchTest.test_patch_dict_stopall.<locals>.patched)rr
rr.r�r_r)r�dic1�dic2�origdic1�origdic2Zorigdic3rrr5r�test_patch_dict_stopalls$
z!PatchTest.test_patch_dict_stopallcCs�tj}tj}i}ddd�}|��}|��}tdt���tdt���t�|ddd����t�|���|d=|�	tj|�|�	tj|�|�
||�|�
||�t��|�tj|�|�tj|�|�
||�|�
||�dS)	Nr0r1r2rrr3r4r^)rr r!rr
rxr.rrr/r�rr-r_)rZoriginal_unlinkZoriginal_chdirr6r7r8r9rrr�!test_patch_and_patch_dict_stopall5s(
z+PatchTest.test_patch_and_patch_dict_stopallcCs�ddd�}t�|dd��|�|�d�Wd�n1swY|�|�d�|j}t�|dd��|�|jd�Wd�n1sFwY|�|j|�t�|d	d
��|�|jd
�Wd�n1skwY|�|jd�t�|dtd
g���|�|jtd
g��Wd�n1s�wY|�|jt��dd�dd�}t�|dtdg���|�|�d�Wd�n1s�wY|�|�d�dS)NrcSs	|Srr�r�rrrr@Osz)PatchTest.test_special_attrs.<locals>.foo�__defaults__)r^r^�__doc__ZFUNrZ
testpatch2z unittest.test.testmock.testpatch�__annotations__)�sr^r<cWs|Srr)r�r1rrrr@cr9�__kwdefaults__)r�r^)r)r
r+r_r>rrr?)rr@Zorig_docrrr�test_special_attrsNs.
�����zPatchTest.test_special_attrscCs�t�}t�|d<d|d<|��}ttdtd���}t|���|}t�|t|���|�	t|���|�Wd�n1s>wY|�	||�t�||��|�	t|���|�Wd�n1sdwY|�	||�dS)Nr1ZpythonrDZcdefghijklmnopqrstuvwxyz�)
rr+rry�zip�range�itemsr
rr_)rr@r{Z
update_valuesZpatched_valuesrrr�test_patch_orderdictis
��zPatchTest.test_patch_orderdictcCsnddl}t�d��$tjd=tjd=tjd=tjd=td�dd	��}|�Wd�dS1s0wYdS)
Nrzsys.modulesr�zunittest.test.testmockz
unittest.testr�� unittest.test.testmock.support.XcSr/rrr�rrrrb�rwz9PatchTest.test_dotted_but_module_not_loaded.<locals>.test)�unittest.test.testmock.supportr
rrerf)rr�rbrrr�!test_dotted_but_module_not_loaded|s
"�z+PatchTest.test_dotted_but_module_not_loadedc
Cs�Gdd�d�}dd|�fD]1}|j|d��!|�t��t|�Wd�n1s*wYWd�n1s9wYq
dS)Nc@r�)z*PatchTest.test_invalid_target.<locals>.FooNr�rrrrr.�r�r.��)r )ZsubTestrOrPr
)rr.r rrr�test_invalid_target�s
�����zPatchTest.test_invalid_targetcCsNtdt�dd�dd��}|�t��|�Wd�dS1s wYdS)NrHr^)rvr�cSr/rrrrrrrb�r9z@PatchTest.test_cant_set_kwargs_when_passing_a_mock.<locals>.test)r
r+rOrPrfrrr�(test_cant_set_kwargs_when_passing_a_mock�s

"�z2PatchTest.test_cant_set_kwargs_when_passing_a_mockN�T)qrrr rUrgrirmrur|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrr!r+r,r2r6r7r8r>r?rFrPrQrWrXr[rhrlrnrsrurwrzr{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	rrrrrrrr#r/r:r;rBrGrJrMrNrrrrrNUs�


+*

			
!
	
	


C	




+!

	"




rN�__main__rO)*rre�collectionsrr�Zunittest.test.testmockrrIrrZtest.test_importlib.utilrZ
unittest.mockrrr	r
rrr
rrrrr�rfrr~rr-rZrxr�rr+r.r4rErFZTestCaserN�mainrrrr�<module>sH4

Y�