%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�I����dZddlmZddlZddlZddlmZddlmZm	Z	m
Z
ddlmZddl
mZddlmZmZmZdd	lmZGd
�d�Ze
d�Ze
d
�ZGd�de�ZGd�de�ZGd�de�Zy)z?
Tests for Trial's interaction with the Python warning system.
�)�annotationsN)�StringIO)�Mapping�Sequence�TypeVar)�
TestResult)�FilePath)�_collectWarnings�_setWarningRegistryToNone�_Warning)�SynchronousTestCasec�&�eZdZdZGd�de�Zy)�MaskzQ
    Hide a test case definition from trial's automatic discovery mechanism.
    c�4�eZdZUdZdZeZded<dd�Zdd�Z	y)	�Mask.MockTestsz�
        A test case which is used by L{FlushWarningsTests} to verify behavior
        which cannot be verified by code inside a single test method.
        �some warning textz
type[Warning]�categoryc�X�tj|j|j�y)z@
            Generate a warning and don't flush it.
            N)�warnings�warn�messager��selfs �A/usr/lib/python3/dist-packages/twisted/trial/test/test_warning.py�test_unflushedzMask.MockTests.test_unflushed&s��
�M�M�$�,�,��
�
�6�c��tj|j|j�|j	t|j
��d�y)z:
            Generate a warning and flush it.
            �N)rrrr�assertEqual�len�
flushWarningsrs r�test_flushedzMask.MockTests.test_flushed,s8��
�M�M�$�,�,��
�
�6����S��!3�!3�!5�6��:rN��return�None)
�__name__�
__module__�__qualname__�__doc__r�UserWarningr�__annotations__rr"�rr�	MockTestsrs"��	�
&��"-��-�-�	7�	;rr-N)r&r'r(r)r
r-r,rrrrs���;�'�;rr�_K�_Vc��eZdZdZdd�Z						dd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Zdd�Z
dd�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zy)�FlushWarningsTestsze
    Tests for C{flushWarnings}, an API for examining the warnings
    emitted so far in a test.
    c�^�|j�D]\}}|j|||��y)z�
        Assert that all the keys present in C{subset} are also present in
        C{set} and that the corresponding values are equal.
        N)�itemsr)r�set�subset�k�vs     r�assertDictSubsetz#FlushWarningsTests.assertDictSubset>s1��
�L�L�N�	(�D�A�q����S��V�Q�'�	(rc��|jt|�t|��t||�D]\}}|j||��y)z�
        For each pair of corresponding elements in C{sets} and C{subsets},
        assert that the element from C{subsets} is a subset of the element from
        C{sets}.
        N)rr �zipr8)r�sets�subsets�a�bs     r�assertDictSubsetsz$FlushWarningsTests.assertDictSubsetsFsF��	
����T��C��L�1���g�&�	(�D�A�q��!�!�!�Q�'�	(rc�D�|j|j�g�y)zg
        If no warnings are emitted by a test, C{flushWarnings} returns an empty
        list.
        N)rr!rs r�	test_nonezFlushWarningsTests.test_noneRs��
	
����+�+�-�r�2rc���d}t}tj||��d}t}tj||��|j	|j�||d�||d�g�y)z|
        If several warnings are emitted by a test, C{flushWarnings} returns a
        list containing all of them.
        zfirst warning message�rrzsecond warning message�rrN)r*rr�RuntimeWarningr?r!)r�firstMessage�
firstCategory�
secondMessage�secondCategorys     r�test_severalzFlushWarningsTests.test_severalYsc��
/��#�
��
�
�l�]�C�0�
�'���
�
�m�n�E������� �*�|�D�+�
�F�
�	
rc��d}t}td�D]}tj||���|j	|j�||d�gdz�y)z�
        The same warning triggered twice from the same place is included twice
        in the list returned by C{flushWarnings}.
        �the message�rCrDN)rE�rangerrr?r!)rrr�is    r�
test_repeatedz FlushWarningsTests.test_repeatedns[��
 ��!���q��	>�A��M�M�'�H�=�	>�	
������ ��W�#M�"N�QR�"R�	
rc���d}t}tj||��|j|j	�||d�g�|j|j	�g�y)z�
        After a particular warning event has been returned by C{flushWarnings},
        it is not returned by subsequent calls.
        rLrCrDN)rErrr?r!r)rrrs   r�test_clearedzFlushWarningsTests.test_cleared|s[��
 ��!���
�
�g��9������� ��W�#M�"N�	
�	
����+�+�-�r�2rc�*�t�}tjd�}|j|�|j	tjj
g�}|j
|ddd�|j|ddt�t|�j
j}|j}|jdz}|j
|dd|�|j
|dd|�|j
t|�d	�y
)zx
        Any warnings emitted by a test which are not flushed are emitted to the
        Python warning system.
        rrrrr��filename�linenorN)rrr-�runr!rr�assertIdenticalr*�type�__code__�co_filename�co_firstlinenor )r�result�case�
warningsShown�whererUrVs       rrz!FlushWarningsTests.test_unflushed�s���
����~�~�.�/��������*�*�D�N�N�,I�,I�+J�K�
�����q�)�)�4�6I�J����]�1�-�j�9�;�G��T�
�)�)�2�2���$�$���%�%��)������q�)�*�5�x�@�����q�)�(�3�V�<�����]�+�Q�/rc��t�}tjd�}t�}|j	t
d|�}|j
|�|j�|j|j�d�y)zx
        Any warnings emitted by a test which are flushed are not emitted to the
        Python warning system.
        r"�stdout�N)
rrr-r�patch�sysrW�restorer�getvalue)rr]r^�output�monkeys     rr"zFlushWarningsTests.test_flushed�s_��
����~�~�n�-��������C��6�2�����������������*�B�/rc�H�Gd�dt�}t�}tjd�}||_t
jdd}	tjd�|j|�|jt|j�d�|j|jdd|�|j|jddj�djd	��|t
jddy#|t
jddwxYw)
z�
        If a warnings filter has been installed which turns warnings into
        exceptions, tests have an error added to the reporter for them for each
        unflushed warning.
        c��eZdZy)�IFlushWarningsTests.test_warningsConfiguredAsErrors.<locals>.CustomWarningN�r&r'r(r,rr�
CustomWarningrl����rrnrN�errorrr���z CustomWarning: some warning text)�Warningrrr-rr�filters�simplefilterrWrr �errorsrX�
assertTrue�
splitlines�endswith�rrnr]r^�originalWarningss     r�test_warningsConfiguredAsErrorsz2FlushWarningsTests.test_warningsConfiguredAsErrors�s���	�G�	�����~�~�.�/��%��
�#�+�+�A�.��
	3��!�!�'�*��H�H�V�����S����/��3�� � ����q�!1�!�!4�d�;��O�O��
�
�a� ��#����b�"���<�=�
�#3�H���Q���"2�H���Q��s
�
B.D�D!c�p�Gd�dt�}t�}tjd�}||_t
jdd}	tjd�|j|�|j|jg�|t
jddy#|t
jddwxYw)z�
        If a warnings filter has been installed which turns warnings into
        exceptions, tests which emit those warnings but flush them do not have
        an error added to the reporter.
        c��eZdZy)�PFlushWarningsTests.test_flushedWarningsConfiguredAsErrors.<locals>.CustomWarningNrmr,rrrnr~�rorrnr"Nrp)rrrrr-rrrsrtrWrrurys     r�&test_flushedWarningsConfiguredAsErrorsz9FlushWarningsTests.test_flushedWarningsConfiguredAsErrors�s���	�G�	�����~�~�n�-��%��
�#�+�+�A�.��	3��!�!�'�*��H�H�V�����V�]�]�B�/�"2�H���Q���"2�H���Q��s
�
AB � B5c��tjd�|jt|j	��d�tjd�|jt|j	��d�y)z�
        Any warnings emitted after a call to C{flushWarnings} can be flushed by
        another call to C{flushWarnings}.
        z
first messagerzsecond messageN)rrrr r!rs r�test_multipleFlushesz'FlushWarningsTests.test_multipleFlushes�sY��
	�
�
�o�&�����T�/�/�1�2�A�6��
�
�&�'�����T�/�/�1�2�A�6rc������d�t�d��fd�}d�t�d��fd�}|�|�|j|j|g����d�g�|j|j|g����d�g�y)	z�
        The list returned by C{flushWarnings} includes only those
        warnings which refer to the source of the function passed as the value
        for C{offendingFunction}, if a value is passed for that parameter.
        zfirst warning textc�6��tj��d��y�Nr)�
stacklevel�rr)rGrFs��r�onez>FlushWarningsTests.test_filterOnOffendingFunction.<locals>.one�s����M�M�,�
�!�Drz	some textc�6��tj��d��yr�r�)rIrHs��r�twoz>FlushWarningsTests.test_filterOnOffendingFunction.<locals>.two�s����M�M�-��A�Fr��offendingFunctionsrDNr#)r*rEr?r!)rr�r�rGrFrIrHs   @@@@r�test_filterOnOffendingFunctionz1FlushWarningsTests.test_filterOnOffendingFunction�s����,��#�
�	E�$�
�'��	G�	����������3�%��8�'�L�
A�B�	
�	
������3�%��8�(�]�
C�D�	
rc�r�dd�}|�|jt|j|g���d�y)z�
        Verify that warnings emitted at the very edges of a function are still
        determined to be emitted from that function.
        c��tjd�tjd�tjd�y)Nzfirst line warningzinternal line warningzlast line warningr�r,rr�warnerz:FlushWarningsTests.test_functionBoundaries.<locals>.warners)���M�M�.�/��M�M�1�2��M�M�-�.rr��Nr#�rr r!)rr�s  r�test_functionBoundariesz*FlushWarningsTests.test_functionBoundaries	s3��	/�
	������T�/�/�F�8�/�L�M�q�Qrc���tjd�|jt|jdg�|jt
|j	��d�y)z�
        If an object which is neither a function nor a method is included in the
        C{offendingFunctions} list, C{flushWarnings} raises L{ValueError}.  Such
        a call flushes no warnings.
        �oh noNr)rr�assertRaises�
ValueErrorr!rr rs r�test_invalidFilterz%FlushWarningsTests.test_invalidFiltersH��	�
�
�g�����*�d�&8�&8�4�&�A�����T�/�/�1�2�A�6rc��t|j�jd��jd�}|j	�|jd�jd�|jd�jd�|j
�jjd�}tjjd|�|jtjj|�ddl
m}|jtjj d	�|jtjj |j"�|jd�j�|j%�|j't)|j+|j$g��d
�y)zx
        Warnings emitted by a function the source code of which is not
        available can still be flushed.
        �utf-8�twisted_private_helper�__init__.pyrsmissingsourcefile.py�7
import warnings
def foo():
    warnings.warn("oh no")
r)�missingsourcefile�twisted_private_helperrN)r	�mktemp�encode�child�makedirs�
setContent�parent�path�decodere�insert�
addCleanup�remover�r��modules�popr&�foorr r!)r�package�	pathEntryr�s    r�test_missingSourcez%FlushWarningsTests.test_missingSource!s=��
�4�;�;�=�/�/��8�9�?�?�%�
��	�����
�
�n�%�0�0��5��
�
�-�.�9�9�
�	
��N�N�$�)�)�0�0��9�	�������9�%����������3�
	
�	
��������)A�B���������):�)C�)C�D��
�
�-�.�5�5�7���������T�/�/�1B�1F�1F�0G�H�I�1�Mrc�(�t|j�jd��jd�}|j	�|jd�jd�|jd�jd�|j
�jjd�}tjjd|�|jtjj|�ddl
m}tjd	=tj|j =	dd
lm}|�|j)|j+d��ddlm}|jtjj.d�|jtjj.|j �|j1�|j3t5|j7|j0g��d
�y#t&$rY��wxYw)a

        Warnings emitted by a function defined in a file which has been renamed
        since it was initially compiled can still be flushed.

        This is testing the code which specifically supports working around the
        unfortunate behavior of CPython to write a .py source file name into
        the .pyc files it generates and then trust that it is correct in
        various places.  If source files are renamed, .pyc files may not be
        regenerated, but they will contain incorrect filenames.
        r�r�r�rs	module.pyr�r)�moduler�)�invalidate_cachesstwisted_renamed_helper�twisted_renamed_helperrN)r	r�r�r�r�r�r�r�r�rer�r�r�r�r�r�r&�	importlibr��ImportError�moveTo�siblingr�r�r�rr r!)rr�r�r�r�s     r�test_renamedSourcez%FlushWarningsTests.test_renamedSourceDs~���4�;�;�=�/�/��8�9�?�?�%�
��	�����
�
�n�%�0�0��5��
�
�l�#�.�.�
�	
��N�N�$�)�)�0�0��9�	�������9�%����������3�	2�
�K�K�0�1��K�K����(�
	 �3�
��	���w���'@�A�B�	2���������)A�B������������9�	�
�
��	
����T�/�/�����=�>��B��%�	��	�s�.H�	H�Hc�r�ddd�}|�|jt|j|g��d�y)a�
        In Python 3.6 the dis.findlinestarts documented behaviour
        was changed such that the reported lines might not be sorted ascending.
        In Python 3.10 PEP 626 introduced byte-code change such that the last
        line of a function wasn't always associated with the last byte-code.
        In the past flushWarning was not detecting that such a function was
        associated with any warnings.
        rc�:�|r|rtjd�yyy)Nr�r�)r=r>s  rr�zCFlushWarningsTests.test_offendingFunctions_deep_branch.<locals>.foo�s�����M�M�'�*��	rN)rr)r=�intr>r�r$r%r�)rr�s  r�#test_offendingFunctions_deep_branchz6FlushWarningsTests.test_offendingFunctions_deep_branch�s2��	�	��	
����T�/�/���6�7��;rN)r4�Mapping[_K, _V]r5r�r$r%)r;�Sequence[Mapping[_K, _V]]r<r�r$r%r#)r&r'r(r)r8r?rArJrPrRrr"r{rr�r�r�r�r�r�r�r,rrr1r18sy���
(�
(�-�
(�8Q�
(�	
�
(�3�
�*
�3�0�.0�3�<3�,7�
�<R�7�!N�F:C�x<rr1c��eZdZy)�FakeWarningNrmr,rrr�r��s��rr�c�@�eZdZdZd	d�Zd	d�Zd	d�Zd	d�Zd	d�Zd	d�Z	y)
�CollectWarningsTestsz(
    Tests for L{_collectWarnings}.
    c�P�����d��ddd��tddd��g�d
����fd�}t�j|�|j�dd	�t	�dt
�sJ�|j�dj��t	�dt
�sJ�|j�dj��t	�dt
�sJ�|j�djt���|j�d
d�|jt��d�y)zS
        L{_collectWarnings} calls the observer with each emitted warning.
        zdummy calls observer warningNrqrrMr�c�����jd�tj��tj��tj���jd�y)N�call�	returning)�appendrr)�eventsrFrH�thirdMessages����r�fz2CollectWarningsTests.test_callsObserver.<locals>.f�s?����M�M�&�!��M�M�,�'��M�M�-�(��M�M�,�'��M�M�+�&rrr�rTr��r#)	rrr
r�r�
isinstancerr�strr )rr�r�rFrHr�s  @@@@r�test_callsObserverz'CollectWarningsTests.test_callsObserver�s���6��$�T�r�T�*�
��q�!�Q�'��')��	'�	'�	�����*�������F�+��&��)�X�.�.�.�������*�*�L�9��&��)�X�.�.�.�������*�*�M�:��&��)�X�.�.�.�������*�*�C��,=�>�������K�0�����V��a�(rc��t�}|jtd|�td�tj
d�|j
|j�d�y)z�
        Any warnings emitted by a call to a function passed to
        L{_collectWarnings} are not actually emitted to the warning system.
        rbc��y�Nr,��xs r�<lambda>z6CollectWarningsTests.test_suppresses.<locals>.<lambda>���r�textrcN)rrdrer
rrrrg)rrhs  r�test_suppressesz$CollectWarningsTests.test_suppresses�sB��
����
�
�3��&�)�������?�������*�B�/rc����g�t��d
��fd�}td�|dddd��}|j�dddd�fg�|j|��y	)z�
        L{_collectWarnings} returns the result of calling the callable passed to
        it with the parameters given.
        c�.���j||f��Sr�)r�)�args�kwargs�	arguments�values  ��rr�z2CollectWarningsTests.test_callsFunction.<locals>.f�s������d�F�^�,��Lrc��yr�r,r�s rr�z9CollectWarningsTests.test_callsFunction.<locals>.<lambda>�r�rrr=rM�d)r>�c)rr=N)r��objectr�r�r$r�)r�r
rrX)rr�r]r�r�s   @@r�test_callsFunctionz'CollectWarningsTests.test_callsFunction�sY���
�	����	�"�.�!�Q��q�C�H������h�a�c�0B�%C�$D�E����V�U�+rc�<�bdd�}tjd�|�g}t|j|�|jt
|�d�|j|djd�|jt
|j��d�y)z�
        Subsequent emissions of a warning from a particular source site can be
        collected by L{_collectWarnings}.  In particular, the per-module
        emitted-warning cache should be bypassed (I{__warningregistry__}).
        c�.�tjd�y)Nr�r�r,rrr�z>CollectWarningsTests.test_duplicateWarningCollected.<locals>.f�s���M�M�%� r�defaultrrr�Nr#)	�__warningregistry__rrtr
r�rr rr!)rr�r�s   r�test_duplicateWarningCollectedz3CollectWarningsTests.test_duplicateWarningCollected�s���
 �	!�	���i�(�	��!#�������*�����V��a�(�������*�*�E�2�����T�/�/�1�2�A�6rc��t�}|tj|<|jtjj|�|j�y)z�
        L{_collectWarnings}'s behavior is not altered by the presence of an
        object which cannot have attributes set on it as a value in
        C{sys.modules}.
        N)r�rer�r�r�r��r�keys  r�test_immutableObjectz)CollectWarningsTests.test_immutableObject�s;���h������C�����������-��+�+�-rc���i�G�fd�d�}t�}t�}||��|<t�}t�}||��|<t��|j||||ht�j	���y)a�
        If the dictionary passed to L{_setWarningRegistryToNone} changes size
        partway through the process, C{_setWarningRegistryToNone} continues to
        set C{__warningregistry__} to L{None} on the rest of the values anyway.


        This might be caused by C{sys.modules} containing something that's not
        really a module and imports things on setattr.  py.test does this, as
        does L{twisted.python.deprecate.deprecatedModuleAttribute}.
        c�"��eZdZdd�Zd�fd�Zy)�KCollectWarningsTests.test_setWarningRegistryChangeWhileIterating.<locals>.Ac�"�||jd<y)N�_key)�__dict__r�s  r�__init__zTCollectWarningsTests.test_setWarningRegistryChangeWhileIterating.<locals>.A.__init__	s��(+��
�
�f�%rc�$��d�|j<yr�)r�)rr��itemr�s   �r�__setattr__zWCollectWarningsTests.test_setWarningRegistryChangeWhileIterating.<locals>.A.__setattr__s���#��$�)�)�rN)r�r�r$r%)r�r�r�r�r$r%)r&r'r(r�r�)r�s�r�Ar�s
���
,�
$rr�N)r�rrr4�keys)rr��key1�key2�key3�key4r�s      @r�+test_setWarningRegistryChangeWhileIteratingz@CollectWarningsTests.test_setWarningRegistryChangeWhileIterating�sy���%'��	$�	$��x���x���D�'��$���x���x���D�'��$��!�!�$�	
���$��d�D�1�3�q�v�v�x�=�ArNr#)
r&r'r(r)r�r�r�r�r�r�r,rrr�r��s&���)�80�,� 7�2	.� Brr�)r)�
__future__rrer�ior�typingrrr�unittestr�twisted.python.filepathr	�twisted.trial._synctestr
rr�twisted.trial.unittestr
rr.r/r1rrr�r�r,rr�<module>rs~���#�
���-�-��,���
7�;�;�8
�T�]���T�]��]<�,�]<�@	�'�	�B�.�Br

Zerion Mini Shell 1.0