%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/test/__pycache__/test_monkey.cpython-312.pyc

�

Ϫ�f���v�dZddlmZddlmZddlmZddlmZGd�d�Z	Gd�d	ej�Zy
)z%
Tests for L{twisted.python.monkey}.
�)�annotations)�NoReturn)�
MonkeyPatcher)�unittestc��eZdZdd�Zy)�TestObjc�.�d|_d|_d|_y)Nz	foo valuez	bar valuez	baz value)�foo�bar�baz��selfs �:/usr/lib/python3/dist-packages/twisted/test/test_monkey.py�__init__zTestObj.__init__s�����������N��return�None)�__name__�
__module__�__qualname__r�rrrrs��rrc�x�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Zdd�Z
dd�Zdd
�Zdd�Zy)�MonkeyPatcherTestsz;
    Tests for L{MonkeyPatcher} monkey-patching class.
    c�^�t�|_t�|_t�|_y�N)r�
testObject�originalObjectr�
monkeyPatcherr
s r�setUpzMonkeyPatcherTests.setUps��!�)���%�i���*�_��rc��|jj�|j|jj|j
j�|j|jj|j
j�|j|jj|j
j�y)zL
        A monkey patcher without patches shouldn't change a thing.
        N)r�patch�assertEqualrr
rrrr
s r�
test_emptyzMonkeyPatcherTests.test_empty s���	
��� � �"�	
����,�,�0�0�$�/�/�2E�2E�F�����,�,�0�0�$�/�/�2E�2E�F�����,�,�0�0�$�/�/�2E�2E�Frc�|�t|jddf|jddf�}|j�|jd|jj�|jd|jj
�|j|jj|jj�y)z}
        Constructing a L{MonkeyPatcher} with patches should add all of the
        given patches to the patch list.
        r
�hahar�heheN)rrr"r#r
rrr)r�patchers  r�test_constructWithPatchesz,MonkeyPatcherTests.test_constructWithPatches,s���
 �
�_�_�e�V�,�t����v�.N�
��	�
�
���������!4�!4�5��������!4�!4�5�����,�,�0�0�$�/�/�2E�2E�Frc���|jj|jdd�|jj�|j	|jj
d�y)zf
        Patching an attribute that exists sets it to the value defined in the
        patch.
        r
r&N)r�addPatchrr"r#r
r
s r�test_patchExistingz%MonkeyPatcherTests.test_patchExisting9sL��
	
���#�#�D�O�O�U�F�C���� � �"�������,�,�f�5rc��|jj|jdd�|jt|jj
�y)zT
        Patching a non-existing attribute fails with an C{AttributeError}.
        �nowherezblow up pleaseN)rr+r�assertRaises�AttributeErrorr"r
s r�test_patchNonExistingz(MonkeyPatcherTests.test_patchNonExistingBs=��	
���#�#�D�O�O�Y�@P�Q����.�$�*<�*<�*B�*B�Crc���|jj|jdd�|jj|jdd�|jj�|j	|jj
d�|jj
�|j	|jj
|jj
�y)z|
        Adding a patch for an object and attribute that already have a patch
        overrides the existing patch.
        r
�blah�BLAHN)rr+rr"r#r
�restorerr
s r�test_patchAlreadyPatchedz+MonkeyPatcherTests.test_patchAlreadyPatchedIs���
	
���#�#�D�O�O�U�F�C����#�#�D�O�O�U�F�C���� � �"�������,�,�f�5����"�"�$�������,�,�d�.A�.A�.E�.E�Frc���|jj|jdd�|jj�|jj	�|j|jj|jj�|jj	�|j|jj|jj�y)zH
        Restoring an already-restored monkey patch is a no-op.
        r
r3N)rr+rr"r5r#r
rr
s r�test_restoreTwiceIsANoOpz+MonkeyPatcherTests.test_restoreTwiceIsANoOpUs���	
���#�#�D�O�O�U�F�C���� � �"����"�"�$�������,�,�d�.A�.A�.E�.E�F����"�"�$�������,�,�d�.A�.A�.E�.E�Frc���g�d	d
�fd�
}|jj|ddd��}|jd|�|jdg��y)z�
        runWithPatches should run the given callable, passing in all arguments
        and keyword arguments, and return the return value of the callable.
        Nc�.���j|||f�y)Nr
)�append)�a�b�c�logs   �r�fz;MonkeyPatcherTests.test_runWithPatchesDecoration.<locals>.fgs����J�J��1�a�y�!�r���
)r>r
)rArBrCr)r<�intr=rDr>z
int | Noner�str)r�runWithPatchesr#)rr@�resultr?s   @r�test_runWithPatchesDecorationz0MonkeyPatcherTests.test_runWithPatchesDecoration`sR���
24��	��#�#�2�2�1�a��b�2�A�������'����*��s�+rc���d�fd�}�jj�jdd��jj|�}�j	d�j
j�j
jf|��jj|�}�j	d�j
j�j
jf|�y)z�
        We should be able to call the same function with runWithPatches more
        than once. All patches should apply for each call.
        c����jj�jj�jjfSr)rr
rrr
s�rr@z9MonkeyPatcherTests.test_repeatedRunWithPatches.<locals>.fus.����O�O�'�'����)<�)<�d�o�o�>Q�>Q�R�Rrr
r&N)rztuple[str, str, str])rr+rrFr#rrr)rr@rGs`  r�test_repeatedRunWithPatchesz.MonkeyPatcherTests.test_repeatedRunWithPatchesos����	S�	
���#�#�D�O�O�U�F�C��#�#�2�2�1�5�����
�T�(�(�,�,�d�.A�.A�.E�.E�F��	
��#�#�2�2�1�5�����
�T�(�(�,�,�d�.A�.A�.E�.E�F��	
rc�r�|jj|jdd�|j|jj
|jj
�|jj
d��|j|jj
|jj
�y)zo
        C{runWithPatches} should restore the original values after the function
        has executed.
        r
r&c��yrrrrr�<lambda>z@MonkeyPatcherTests.test_runWithPatchesRestores.<locals>.<lambda>�s�rN)rr+rr#rr
rFr
s r�test_runWithPatchesRestoresz.MonkeyPatcherTests.test_runWithPatchesRestores�s���
	
���#�#�D�O�O�U�F�C�����,�,�0�0�$�/�/�2E�2E�F����)�)�,�7�����,�,�0�0�$�/�/�2E�2E�Frc����d�fd�}�jj�jdd��jj�jdd��jt�jj
|��j
�jj�jj��j
�jj�jj�y)zv
        Test runWithPatches restores the original values even when the function
        raises an exception.
        c����j�jjd��j�jjd�t	d��)Nr&�blahblahzSomething went wrong!)r#rr
r�RuntimeErrorr
s�r�_zDMonkeyPatcherTests.test_runWithPatchesRestoresOnException.<locals>._�sC������T�_�_�0�0�&�9����T�_�_�0�0�*�=��6�7�7rr
r&rrRN)rr)
rr+rr/rSrFr#r
rr)rrTs` r�&test_runWithPatchesRestoresOnExceptionz9MonkeyPatcherTests.test_runWithPatchesRestoresOnException�s����	8�
	
���#�#�D�O�O�U�F�C����#�#�D�O�O�U�J�G����,��(:�(:�(I�(I�1�M�������,�,�d�.A�.A�.E�.E�F�������,�,�d�.A�.A�.E�.E�Frc�T�|jj|jdd�|j5|j|jjd�ddd�|j|jj|j
j�y#1swY�DxYw)z�
        L{MonkeyPatcher} is a context manager that applies its patches on
        entry and restore original values on exit.
        r
z
patched valueN)rr+rr#r
rr
s r�test_contextManagerz&MonkeyPatcherTests.test_contextManager�s���
	
���#�#�D�O�O�U�O�L�
�
�
�	C����T�_�_�0�0�/�B�	C�������,�,�d�.A�.A�.E�.E�F�	C�	C�s�'B�B'c��|jt�5|j5td��#1swYnxYw	ddd�y#1swYyxYw)zh
        Exceptions propagate through the L{MonkeyPatcher} context-manager
        exit method.
        �	somethingN)r/rSrr
s r�'test_contextManagerPropagatesExceptionsz:MonkeyPatcherTests.test_contextManagerPropagatesExceptions�sP��
�
�
�|�
,�	0��#�#�
0�"�;�/�/�
0�
0��
0�	0�	0�	0�s�
A�/�8	�A�ANr)rrr�__doc__r r$r)r,r1r6r8rHrKrOrUrWrZrrrrrsP���-�

G�G�6�D�
G�	G�
,�
�&G�G�$G�0rrN)r[�
__future__r�typingr�twisted.python.monkeyr�
twisted.trialrr�SynchronousTestCaserrrr�<module>ras6���#��/�"���Y0��5�5�Y0r

Zerion Mini Shell 1.0