HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/twisted/test/__pycache__/test_monkey.cpython-310.pyc
o

�b��@s@dZddlmZddlmZGdd�d�ZGdd�dej�ZdS)	z%
Tests for L{twisted.python.monkey}.
�)�
MonkeyPatcher)�unittestc@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__s
zTestObj.__init__N)�__name__�
__module__�__qualname__rr
r
r
rr
src@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�
monkeyPatcherrr
r
r�setUpszMonkeyPatcherTests.setUpcCsJ|j��|�|jj|jj�|�|jj|jj�|�|jj|jj�dS)zL
        A monkey patcher without patches shouldn't change a thing.
        N)r�patch�assertEqualrrrrrrr
r
r�
test_emptys
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�hahar�heheN)rrrrrrrr)r	�patcherr
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�addPatchrrrrrr
r
r�test_patchExisting7s
z%MonkeyPatcherTests.test_patchExistingcCs&|j�|jdd�|�t|jj�dS)zT
        Patching a non-existing attribute fails with an C{AttributeError}.
        �nowherezblow up pleaseN)rrr�assertRaises�AttributeErrorrrr
r
r�test_patchNonExisting@sz(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�blah�BLAHN)rrrrrr�restorerrr
r
r�test_patchAlreadyPatchedGs

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%rrrrr
r
r�test_restoreTwiceIsANoOpSs


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�fesz;MonkeyPatcherTests.test_runWithPatchesDecoration.<locals>.f���
)r+r)r/r0r1r)r�runWithPatchesr�r	r.�resultr
r,r�test_runWithPatchesDecoration^s
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)rrrrr
rr
rr.ssz9MonkeyPatcherTests.test_repeatedRunWithPatches.<locals>.frrN)rrrr2rrrrr3r
rr�test_repeatedRunWithPatchesms��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>�sz@MonkeyPatcherTests.test_runWithPatchesRestores.<locals>.<lambda>N)rrrrrrr2rr
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��)Nr�blahblahzSomething went wrong!)rrrr�RuntimeErrorr
rr
r�_�szDMonkeyPatcherTests.test_runWithPatchesRestoresOnException.<locals>._rrrr9N)
rrrr r:r2rrrr)r	r;r
rr�&test_runWithPatchesRestoresOnException�sz9MonkeyPatcherTests.test_runWithPatchesRestoresOnExceptionN)r
rr�__doc__rrrrr"r&r'r5r6r8r<r
r
r
rrs
	
rN)r=�twisted.python.monkeyr�
twisted.trialrr�SynchronousTestCaserr
r
r
r�<module>s