%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�1���dZddlZddlmZmZmZmZmZmZm	Z	m
Z
ddlmZddl
mZddlmZddlmZmZdd	lmZmZdd
lmZddlmZddlmZdd
lmZdej>deedeeddfd�Z Gd�dej>�Z!y)z+
Test cases for L{twisted.logger._global}.
�N)�IO�Any�List�Optional�TextIO�Tuple�Type�cast)�Failure)�unittest�)�textFileLogObserver)�MORE_THAN_ONCE_WARNING�LogBeginner)�ILogObserver�LogEvent)�LogLevel)�Logger)�LogPublisher)�nextLine�test�actualEvents�expectedEvents�returnc�.��t|�t|�k7r|j||�t��|D]}�t|j��z�� dtdtf�fd�}|D�cgc]
}||���}}|j||�ycc}w)a7
    Compare two sequences of log events, examining only the the keys which are
    present in both.

    @param test: a test case doing the comparison
    @param actualEvents: A list of log events that were emitted by a logger.
    @param expectedEvents: A list of log events that were expected by a test.
    �eventrc�~��|j�}|j�D]}|�vs�|j|��|S�N)�copy�keys�pop)rr�key�
allMergedKeyss   ��A/usr/lib/python3/dist-packages/twisted/logger/test/test_global.py�simplifyzcompareEvents.<locals>.simplify*s=����z�z�|���:�:�<�	�C��-�'�����
�	���N)�len�assertEqual�setr r)rrrrr%�simplifiedActualr#s      @r$�
compareEventsr+s�����<��C��/�/�����~�6��E�M��+����U�Z�Z�\�*�*�
�+����X��6B�B�E����B��B����%�~�6��Cs�.Bc��eZdZdZdd�Zdd�Zdd�Zdededdfd	�Z	dd
�Z
dd�Zdd�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zy)�LogBeginnerTestsz#
    Tests for L{LogBeginner}.
    rNc�"�t�|_tj�|_Gd�d�}Gd�d�}|�|_|�|_t|j|j|j
|j�|_y)Nc�(�eZdZe�Ze�Zy)�&LogBeginnerTests.setUp.<locals>.NotSysN)�__name__�
__module__�__qualname__�object�stdout�stderr�r&r$�NotSysr0>s���X�F��X�Fr&r8c�V�eZdZdd�Z		ddedeedededee	e
d	eeddfd
�Zy)
�+LogBeginnerTests.setUp.<locals>.NotWarningsrNc��g|_yr)�warnings)�selfs r$�__init__z4LogBeginnerTests.setUp.<locals>.NotWarnings.__init__Cs��
�	�
r&�message�category�filename�lineno�file�linec�F�|jj||||||f�y)a
                Emulate warnings.showwarning.

                @param message: A warning message to emit.
                @param category: A warning category to associate with
                    C{message}.
                @param filename: A file name for the source code file issuing
                    the warning.
                @param lineno: A line number in the source file where the
                    warning was issued.
                @param file: A file to write the warning message to.  If
                    L{None}, write to L{sys.stderr}.
                @param line: A line of source code to include with the warning
                    message. If L{None}, attempt to read the line from
                    C{filename} and C{lineno}.
                N)r<�append)r=r?r@rArBrCrDs       r$�showwarningz7LogBeginnerTests.setUp.<locals>.NotWarnings.showwarningJs$��2�
�
�$�$�g�x��6�4�QU�%V�Wr&�rN)NN)r1r2r3r>�strr	�Warning�intrrrrGr7r&r$�NotWarningsr:Bsq��
�+/�&*�
X��
X��w�-�
X��	
X�
�
X��r�#�w�'�

X��s�m�
X��
Xr&rL)	r�	publisher�io�StringIO�errorStream�	sysModule�warningsModuler�beginner)r=r8rLs   r$�setUpzLogBeginnerTests.setUp:sn��%�����;�;�=���	�	�!	X�!	X�F ����)�m���#��N�N�D�,�,�d�n�n�d�>Q�>Q�
��
r&c����tdd��}g�g�tt�fd��}tt�fd��}|jj	||f�|j|�|j
|g��|j
|g��y)z?
        Test that C{beginLoggingTo()} adds observers.
        �r
��foo�barc�&���j|�Sr�rF��e�events1s �r$�<lambda>zBLogBeginnerTests.test_beginLoggingToAddObservers.<locals>.<lambda>t����'�.�.��*;�r&c�&���j|�Srr[�r]�events2s �r$r_zBLogBeginnerTests.test_beginLoggingToAddObservers.<locals>.<lambda>ur`r&N)�dictr
rrS�beginLoggingTorMr(�r=r�o1�o2r^rcs    @@r$�test_beginLoggingToAddObserversz0LogBeginnerTests.test_beginLoggingToAddObserversks{������"��"$��"$��
�,� ;�
<��
�,� ;�
<���
�
�$�$�b�"�X�.����u�����%��'�*����%��'�*r&c����tdd��}g�g�tt�fd��}tt�fd��}|j|�|jj||f�|j
|g��|j
|g��y)z\
        Test that events are buffered until C{beginLoggingTo()} is
        called.
        rVr
rWc�&���j|�Srr[r\s �r$r_zDLogBeginnerTests.test_beginLoggingToBufferedEvents.<locals>.<lambda>�r`r&c�&���j|�Srr[rbs �r$r_zDLogBeginnerTests.test_beginLoggingToBufferedEvents.<locals>.<lambda>�r`r&N)rdr
rrMrSrer(rfs    @@r$�!test_beginLoggingToBufferedEventsz2LogBeginnerTests.test_beginLoggingToBufferedEvents}s{���
���"��"$��"$��
�,� ;�
<��
�,� ;�
<�����u���
�
�$�$�b�"�X�.����%��'�*����%��'�*r&�limitrSc	�(�t|dz�D]}|jt|����g}|jt	t
|j�g�|jttd|dz��td�|D���y)a�
        Verify that when more than C{limit} events are logged to L{LogBeginner},
        only the last C{limit} are replayed by L{LogBeginner.beginLoggingTo}.

        @param limit: The maximum number of events the log beginner should
            buffer.
        @param beginner: The L{LogBeginner} against which to verify.

        @raise: C{self.failureException} if the wrong events are replayed by
            C{beginner}.
        rV)�countc3�&K�|]	}|d���y�w)rpNr7)�.0rs  r$�	<genexpr>z4LogBeginnerTests._bufferLimitTest.<locals>.<genexpr>�s����4�E��w��4�s�N)	�rangerMrdrer
rrFr(�list)r=rnrSrp�eventss     r$�_bufferLimitTestz!LogBeginnerTests._bufferLimitTest�s}���5�1�9�%�	.�E��N�N�4�e�,�-�	.�!#������l�F�M�M�!B� C�D������q�%�!�)�$�%��4�V�4�4�	
r&c�\�tj}|j||j�y)z�
        Up to C{LogBeginner._DEFAULT_BUFFER_SIZE} log events are buffered for
        replay by L{LogBeginner.beginLoggingTo}.
        N)r�_DEFAULT_BUFFER_SIZErwrS)r=rns  r$�test_defaultBufferLimitz(LogBeginnerTests.test_defaultBufferLimit�s#��
�0�0�����e�T�]�]�3r&c��d}t|j|j|j|j|��}|j||�y)z�
        The size of the L{LogBeginner} event buffer can be overridden with the
        C{initialBufferSize} initilizer argument.
        �)�initialBufferSizeN)rrMrPrQrRrw)r=rnrSs   r$�test_overrideBufferLimitz)LogBeginnerTests.test_overrideBufferLimit�sH��
����N�N�����N�N����#�
��	
���e�X�.r&c
�\�g}g}tj�}t|�}|jt	d���t�\}}|jjtt|j�|g�|jt	d���t�\}}|jjtt|j�|g�|jt	d���t	ttj||||��}	d|_t||t	d��t	d��|	t	d��g�t|||	t	d��g�|j!�}
|j#d|�d|�d	�|
�|j#d|�d|�d	�|
�y)
z�
        When invoked twice, L{LogBeginner.beginLoggingTo} will emit a log
        message warning the user that they previously began logging, and add
        the new log observers.
        �	prebuffer)r�
postbuffer�postwarn)�
log_format�	log_level�fileNow�lineNow�fileThen�lineThenN�<�:�>)rNrOrrMrdrrSrer
rrFrr�warn�maxDiffr+�getvalue�assertIn)r=r^rc�
fileHandle�textObserver�
firstFilename�	firstLine�secondFilename�
secondLine�warning�outputs           r$�test_beginLoggingToTwicez)LogBeginnerTests.test_beginLoggingToTwice�sj��#%��"$���[�[�]�
�*�:�6�����t�+�.�/�#+�:� �
�y��
�
�$�$�d�<����&H�,�%W�X����t�,�/�0�%-�Z�"��
��
�
�$�$�d�<����&H�,�%W�X����t�*�-�.��-��m�m�"��"��

���������;�'��<�(���:�&�	
�		
�	�d�G�g�t�*�/E�%F�G��$�$�&���
�
��-���)��A�6��?��
�
��.�)��:�,�a�8�&�Ar&c���t|j��}|jd�|jdd��|j	|j
j
�d�y)zP
        Critical messages will be written as text to the error stream.
        ��observerzignore thisza critical {message}r?)r?za critical message
N)rrM�info�criticalr(rPr��r=�logs  r$�test_criticalLoggingz%LogBeginnerTests.test_criticalLogging�sO���d�n�n�-����������+�Y��?�����)�)�2�2�4�6L�Mr&c���t|j��}|jjd�|j	d�|j|jj�d�y)z�
        Once logging has begun with C{beginLoggingTo}, critical messages are no
        longer written to the output stream.
        r�r7zanother critical message�N)rrMrSrer�r(rPr�r�s  r$�test_criticalLoggingStopsz*LogBeginnerTests.test_criticalLoggingStops�sP��
�d�n�n�-���
�
�$�$�R�(����/�0�����)�)�2�2�4�b�9r&c��g}|jjtt|j�g�tdtt|jj���t||tdd��g�|dd�=tdtt|jj���t||tdd��g�y)z�
        L{LogBeginner.beginLoggingTo} will re-direct the standard output and
        error streams by setting the C{stdio} and C{stderr} attributes on its
        sys module object.
        z
Hello, world.�rCr5)�
log_namespace�log_ioNz
Error, world.r6)rSrer
rrF�printrrQr5r+rdr6)r=rvs  r$�%test_beginLoggingToRedirectStandardIOz6LogBeginnerTests.test_beginLoggingToRedirectStandardIO�s���"$���
�
�$�$�d�<����&G�%H�I�
�o�D�����1F�1F�$G�H���&�4�h��O�P�	
�
�1�I�
�o�D�����1F�1F�$G�H���&�4�h��O�P�	
r&c�.�|jj}|jj}|jj	dd��|j|jj|�|j|jj|�y)z�
        L{LogBeginner.beginLoggingTo} will leave the existing stdout/stderr in
        place if it has been told not to replace them.
        r7F)�redirectStandardION)rQr5r6rSre�assertIs)r=�oldOut�oldErrs   r$�test_beginLoggingToDontRedirectz0LogBeginnerTests.test_beginLoggingToDontRedirectsi��
���&�&�����&�&���
�
�$�$�R�E�$�B��
�
�d�n�n�+�+�V�4��
�
�d�n�n�+�+�V�4r&c���tjtj�d�}tjtj�d�}||j_||j_g}|jjtt|j�g�tt|jj�}tt|jj
�}|j|jd�|j|jd�|jd�|jd�t||t!d��t!d��g�y)	z�
        When L{LogBeginner.beginLoggingTo} redirects stdout/stderr streams, the
        replacement streams will preserve the encoding of the replaced streams,
        to minimally disrupt any application relying on a specific encoding.
        z	shift-JIS�big5s��
s��
u李)r�u瑩N)rN�
TextIOWrapper�BytesIOrQr5r6rSrer
rrFrr(�encoding�writer+rd)r=�weird�weirderrrvr5r6s      r$�$test_beginLoggingToPreservesEncodingz5LogBeginnerTests.test_beginLoggingToPreservesEncodings���� � �����{�;���#�#�B�J�J�L�&�9�� %����� (�����!#���
�
�$�$�d�<����&G�%H�I��f�d�n�n�3�3�4���f�d�n�n�3�3�4��������+�6�������&�1����]�#����]�#��d�F�T��%:�D��<Q�$R�Sr&c
��|jjdttd�g}|jjt
t|j�g�|jjdttd�tj�}|jjdttd|��|j|jjdttdddfdttd|dfg�t||tdtjd	ztj ztd�
�g�y)z�
        L{LogBeginner.beginLoggingTo} will redirect the warnings of its
        warnings module into the logging system.
        z	a messagerVzanother messager
zyet anotherr|r�N�.)r�r@rArB)rRrG�DeprecationWarning�__file__rSrer
rrFrNrOr(r<r+rdr2r1)r=rv�fs   r$�test_warningsModulez$LogBeginnerTests.test_warningsModule/s"��
	
���'�'��5G��ST�U�!#���
�
�$�$�d�<����&G�%H�I����'�'��1�8�Q�	
�
�K�K�M�����'�'��-�x���	(�	
�	
������(�(��0�(�A�t�T�J�� 2�H�a��D�I�
�	
�	����-�*�5�5���,�5�5�6�&��	�
�	
r&c��ttd��}t|j��}|j	d|��|j
j
�}|jd|�|jd|�|jd|�y)zR
        The string resulting from a logged failure contains a traceback.
        z,this is not the behavior you are looking forr�z	a failure)�failure�	TracebackN)r�	ExceptionrrMr�rPr�r�)r=r�r��msgs    r$�test_failuresAppendTracebacksz.LogBeginnerTests.test_failuresAppendTracebacksVsq��
�I�L�M�N���d�n�n�-�����K���+����'�'�)���
�
�k�3�'��
�
�D�c�J��
�
�k�3�'r&rH)r1r2r3�__doc__rTrirmrKrrwrzr~r�r�r�r�r�r�r�r�r7r&r$r-r-5sh���/
�b+�$+�&
�c�
�[�
�T�
�*4�
/�)B�VN�:�
�$	5�T�0%
�N
(r&r-)"r�rN�typingrrrrrrr	r
�twisted.python.failurer�
twisted.trialr�_filer�_globalrr�_interfacesrr�_levelsr�_loggerr�	_observerr�test.test_stdlibr�TestCaser+r-r7r&r$�<module>r�s~���
�E�E�E�*�"�'�9�0���$�'�7�
�
�
�7��x�.�7���N�7�
�	7�>k(�x�(�(�k(r&

Zerion Mini Shell 1.0