HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/test/__pycache__/test_monkey.cpython-38.pyc
U


W[�@sPdZddlmZmZddlmZddlmZGdd�d�ZGdd�dej	�Z
d	S)
z%
Tests for L{twisted.python.monkey}.
�)�division�absolute_import)�unittest)�
MonkeyPatcherc@seZdZdd�ZdS)�TestObjcCsd|_d|_d|_dS)Nz	foo valuez	bar valuez	baz value)�foo�bar�baz��self�r�:/usr/lib/python3/dist-packages/twisted/test/test_monkey.py�__init__szTestObj.__init__N)�__name__�
__module__�__qualname__rrrrr
rsrc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�MonkeyPatcherTestsz;
    Tests for L{MonkeyPatcher} monkey-patching class.
    cCst�|_t�|_t�|_dS�N)r�
testObject�originalObjectr�
monkeyPatcherr
rrr
�setUpszMonkeyPatcherTests.setUpcCsJ|j��|�|jj|jj�|�|jj|jj�|�|jj|jj�dS)zL
        A monkey patcher without patches shouldn't change a thing.
        N)r�patch�assertEqualrrrrr	r
rrr
�
test_empty!s
zMonkeyPatcherTests.test_emptycCsZt|jddf|jddf�}|��|�d|jj�|�d|jj�|�|jj|jj�dS)z}
        Constructing a L{MonkeyPatcher} with patches should add all of the
        given patches to the patch list.
        r�haharZheheN)rrrrrrrr	)rZpatcherrrr
�test_constructWithPatches.s
�z,MonkeyPatcherTests.test_constructWithPatchescCs0|j�|jdd�|j��|�|jjd�dS)zf
        Patching an attribute that exists sets it to the value defined in the
        patch.
        rrN)r�addPatchrrrrr
rrr
�test_patchExisting;s
z%MonkeyPatcherTests.test_patchExistingcCs&|j�|jdd�|�t|jj�dS)zT
        Patching a non-existing attribute fails with an C{AttributeError}.
        Znowherezblow up pleaseN)rrr�assertRaises�AttributeErrorrr
rrr
�test_patchNonExistingEs�z(MonkeyPatcherTests.test_patchNonExistingcCs`|j�|jdd�|j�|jdd�|j��|�|jjd�|j��|�|jj|jj�dS)z|
        Adding a patch for an object and attribute that already have a patch
        overrides the existing patch.
        r�blahZBLAHN)rrrrrr�restorerr
rrr
�test_patchAlreadyPatchedNs

z+MonkeyPatcherTests.test_patchAlreadyPatchedcCs\|j�|jdd�|j��|j��|�|jj|jj�|j��|�|jj|jj�dS)zH
        Restoring an already-restored monkey patch is a no-op.
        rr"N)rrrrr#rrrr
rrr
�test_restoreTwiceIsANoOp[s


z+MonkeyPatcherTests.test_restoreTwiceIsANoOpcsDg�d
�fdd�	}|jj|dddd�}|�d|�|�d	g��dS)z�
        runWithPatches should run the given callable, passing in all arguments
        and keyword arguments, and return the return value of the callable.
        Ncs��|||f�dS)Nr)�append)�a�b�c��logrr
�fnsz;MonkeyPatcherTests.test_runWithPatchesDecoration.<locals>.f���
)r)r)r-r.r/)N)r�runWithPatchesr�rr,�resultrr*r
�test_runWithPatchesDecorationgs
z0MonkeyPatcherTests.test_runWithPatchesDecorationcsn�fdd�}�j��jdd��j�|�}��d�jj�jjf|��j�|�}��d�jj�jjf|�dS)z�
        We should be able to call the same function with runWithPatches more
        than once. All patches should apply for each call.
        cs�jj�jj�jjfSr)rrrr	rr
rr
r,|s�z9MonkeyPatcherTests.test_repeatedRunWithPatches.<locals>.frrN)rrrr0rrrr	r1rr
r
�test_repeatedRunWithPatchesws��z.MonkeyPatcherTests.test_repeatedRunWithPatchescCsN|j�|jdd�|�|jj|jj�|j�dd��|�|jj|jj�dS)zo
        C{runWithPatches} should restore the original values after the function
        has executed.
        rrcSsdSrrrrrr
�<lambda>��z@MonkeyPatcherTests.test_runWithPatchesRestores.<locals>.<lambda>N)rrrrrrr0r
rrr
�test_runWithPatchesRestores�sz.MonkeyPatcherTests.test_runWithPatchesRestorescsn�fdd�}�j��jdd��j��jdd���t�jj|����jj�jj����jj	�jj	�dS)zv
        Test runWithPatches restores the original values even when the function
        raises an exception.
        cs,���jjd����jjd�td��dS)Nr�blahblahzSomething went wrong!)rrrr�RuntimeErrorrr
rr
�_�szDMonkeyPatcherTests.test_runWithPatchesRestoresOnException.<locals>._rrrr8N)
rrrrr9r0rrrr)rr:rr
r
�&test_runWithPatchesRestoresOnException�sz9MonkeyPatcherTests.test_runWithPatchesRestoresOnExceptionN)rrr�__doc__rrrrr!r$r%r3r4r7r;rrrr
rs


	
rN)r<Z
__future__rrZ
twisted.trialrZtwisted.python.monkeyrrZSynchronousTestCaserrrrr
�<module>s