%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f!"��H�dZddlmZddlZddlZddlmZddlm	Z	m
Z
ddlmZmZm
Z
mZddlmZmZmZddlmZdd	lmZdd
lmZddlmZddlmZd
dlmZmZd
dl m!Z!d
dl"m#Z#dd�Z$Gd�d�Z%Gd�dejL�Z'dd�Z(Gd�dejR�Z*y)z+
Test cases for L{twisted.logger._format}.
�)�annotationsN)�
getsourcefile)�BytesIO�
TextIOWrapper)�	Formatter�	LogRecord�
StreamHandler�	getLogger)�List�Optional�Tuple)�BrokenMethodImplementation)�verifyObject)�currentframe)�Failure)�unittest�)�ILogObserver�LogEvent)�LogLevel)�STDLibLogObserverc��td�}ttj|jd�|j
dzfS)z�
    Retrive the file name and line number immediately after where this function
    is called.

    @return: the file name and line number
    ��__name__)rr�sys�modules�	f_globals�f_lineno)�callers �A/usr/lib/python3/dist-packages/twisted/logger/test/test_stdlib.py�nextLiner!s?���!�_�F��c�k�k�&�"2�"2�:�">�?�@����!����c�(�eZdZdZdd�Zdd�Zdd�Zy)�StdlibLoggingContainerzF
    Continer for a test configuration of stdlib logging objects.
    c��td�|_|jj�|_|jj	t
j�t�|_|jj|j�t�\|_|_|jj|j�y)N�)
r
�
rootLogger�getEffectiveLevel�
originalLevel�setLevel�
py_logging�DEBUG�BufferedHandler�bufferedHandler�
addHandler�handlerAndBytesIO�
streamHandler�output��selfs r �__init__zStdlibLoggingContainer.__init__.s���#�B�-���!�_�_�>�>�@������ � ��!1�!1�2�.�0������"�"�4�#7�#7�8�*;�*=�'���D�K����"�"�4�#5�#5�6r"c�J�|jj|j�|jj|j�|jj|j
�|j
j
�|jj
�y)z#
        Close the logger.
        N)r'r*r)�
removeHandlerr.r1�closer2r3s r r8zStdlibLoggingContainer.close:sn��	
��� � ��!3�!3�4����%�%�d�&:�&:�;����%�%�d�&8�&8�9���� � �"������r"c�T�|jj�jd�S)zd
        Get the output to the underlying stream as text.

        @return: the output text
        �utf-8)r2�getvalue�decoder3s r �outputAsTextz#StdlibLoggingContainer.outputAsTextDs"���{�{�#�#�%�,�,�W�5�5r"N��return�None)r?�str)r�
__module__�__qualname__�__doc__r5r8r=�r"r r$r$)s���
7��6r"r$c�h�eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Zdd�Z
dd�Zy
)�STDLibLogObserverTestsz)
    Tests for L{STDLibLogObserver}.
    c��t�}	tt|�y#t$r}|j	|�Yd}~yd}~wwxYw)z=
        L{STDLibLogObserver} is an L{ILogObserver}.
        N)rrrr�fail)r4�observer�es   r �test_interfacez%STDLibLogObserverTests.test_interfaceRs8��%�&��	���x�0��)�	��I�I�a�L�L��	�s��	A�<�Ac�P�t�}|j|j�|S)zj
        Create a logging object we can use to test with.

        @return: a stdlib-style logger
        )r$�
addCleanupr8)r4�loggers  r �	py_loggerz STDLibLogObserverTests.py_logger\s!��(�)��������%��
r"c���|j�}ttjdz��}|D]
}||��|jj|j�fS)z�
        Send one or more events to Python's logging module, and capture the
        emitted L{LogRecord}s and output stream as a string.

        @param events: events

        @return: a tuple: (records, output)
        r)�
stackDepth)rPr�defaultStackDepthr.�recordsr=)r4�events�plrJ�events     r �logEventzSTDLibLogObserverTests.logEventfse���^�^�
��$�)�:�:���
���	�E��U�O�	��!�!�)�)�2�?�?�+<�<�<r"c��|ji�\}}|jt|�d�|j|djd�y)z
        Logger name.
        rr�twistedN)rX�assertEqual�len�name�r4rTr2s   r �	test_namez STDLibLogObserverTests.test_name|sB���-�-��+��������W��q�)���������)�4r"c��dtjtjtjtj
tjtjtjtjtjtjtji}g}|j�D]-\}}i}|�||d<t|�|d<|j|��/|j|�\}}|j!t#|�t#|��t%t#|��D]'}|j!||j&||d��)y)z
        Log levels.
        N�	log_level�
py_levelno)r+�INFOr�debugr,�info�warn�WARNING�error�ERROR�critical�CRITICAL�items�int�appendrXr[r\�range�levelno)	r4�levelMappingrU�level�pyLevelrWrTr2�is	         r �test_levelsz"STDLibLogObserverTests.test_levels�s#��

�*�/�/��N�N�J�,�,��M�M�:�?�?��M�M�:�-�-��N�N�J�,�,����z�2�2�

����*�0�0�2�	!�N�E�7��E�� �%*��k�"�#&�g�,�E�,���M�M�%� �	!�(�$�-�-��0��������W��s�<�'8�9��s�7�|�$�	J�A����W�Q�Z�/�/����<�1H�I�	Jr"c�4�t�\}}|ji�\}}|jt|�d�|j|dj|�|j|dj
|�|j
|dj�y)zb
        C{pathname}, C{lineno}, C{exc_info}, C{func} is set properly on
        records.
        rrN)r!rXr[r\�pathname�lineno�assertIsNone�exc_info)r4�filename�logLinerTr2s     r �test_callerInfoz&STDLibLogObserverTests.test_callerInfo�s���
%�J���'��-�-��+��������W��q�)�������,�,�h�7�������*�*�G�4����'�!�*�-�-�.r"c�
�tdd��}|j|�\}}|jt|�d�|jt	|dj
�d�|j|djd�y)	zL
        Basic formattable event passes the format along correctly.
        �
Hello, {who}!�dude��
log_format�whorrzHello, dude!rEN)�dictrXr[r\rA�msg�args�r4rWrTr2s    r �test_basicFormatz'STDLibLogObserverTests.test_basicFormat�sk����V�<���-�-��.��������W��q�)�����W�Q�Z�^�^�,�n�=���������"�-r"c���tdd��}|j|�\}}|jt|�d�|j	|jd�t
|��y)z<
        Basic formattable event renders correctly.
        rr�r�rz:Hello, dude!
N)r�rXr[r\�
assertTrue�endswith�reprr�s    r �test_basicFormatRenderedz/STDLibLogObserverTests.test_basicFormatRendered�sR����V�<���-�-��.��������W��q�)�������(9�:�D��L�Ir"c��|ji�\}}|jt|�d�|jt|dj�d�y)z'
        Event with no format.
        rrr&N)rXr[r\rAr�r^s   r �
test_noFormatz$STDLibLogObserverTests.test_noFormat�sG���-�-��+��������W��q�)�����W�Q�Z�^�^�,�b�1r"c�4�d	d�}	|�tdd��}|j|�\}}|j	t|�d�|j
d|�|j
d|�|j
d|�y#t$r
t�}Y��wxYw)
zK
        An event with a failure logs the failure details as well.
        c��ddzy�NrrrErEr"r �failing_funcz9STDLibLogObserverTests.test_failure.<locals>.failing_func��	��
��Er"�Hi mom�me�r�r��log_failurer�in failing_func�ZeroDivisionErrorNr>)r�rr�rXr[r\�assertIn�r4r��failurerWrTr2s      r �test_failurez#STDLibLogObserverTests.test_failure�s���
	�	 ��N���d��H���-�-��.��������W��q�)��
�
�h��'��
�
�'��0��
�
�)�6�2��!�	 ��i�G�	 �s�B�B�Bc�T�d	d�}	|�tdd��}|j	|�\}}|jt
|�d�|jd|�|jd|�|jd|�y#t$rt�}|j�Y��wxYw)
z�
        A cleaned Failure object has a fake traceback object; make sure that
        logging such a failure still results in the exception details being
        logged.
        c��ddzyr�rErEr"r r�z@STDLibLogObserverTests.test_cleanedFailure.<locals>.failing_func�r�r"r�r�r�rr�r�Nr>)r�r�cleanFailurer�rXr[r\r�r�s      r �test_cleanedFailurez*STDLibLogObserverTests.test_cleanedFailure�s���	�	#��N�
��d��H���-�-��.��������W��q�)��
�
�h��'��
�
�'��0��
�
�)�6�2��!�	#��i�G�� � �"�	#�s�B�#B'�&B'Nr>)r?r$)rUrr?zTuple[List[LogRecord], str])rrBrCrDrLrPrXr_rur}r�r�r�r�r�rEr"r rGrGMsA�����=�,5�!J�F/�"	.�J�2�3�*3r"rGc��t�}tj}t|dd��}t	|�}t|�}|j
|�||fS)z�
    Construct a 2-tuple of C{(StreamHandler, BytesIO)} for testing interaction
    with the 'logging' module.

    @return: handler and io object
    r:�
)�encoding�newline)rr+�BASIC_FORMATrrr	�setFormatter)r2�template�stream�	formatter�handlers     r r0r0sP���Y�F��&�&�H�
�6�G�T�
B�F��(�#�I��F�#�G�����#��F�?�r"c� �eZdZdZdd�Zdd�Zy)r-zN
    A L{py_logging.Handler} that remembers all logged records in a list.
    c�P�tjj|�g|_y)z5
        Initialize this L{BufferedHandler}.
        N)r+�Handlerr5rTr3s r r5zBufferedHandler.__init__s��	���#�#�D�)�(*��r"c�:�|jj|�y)z&
        Remember the record.
        N)rTrn)r4�records  r �emitzBufferedHandler.emit!s��	
�����F�#r"Nr>)r�rr?r@)rrBrCrDr5r�rEr"r r-r-s���+�$r"r-)r?zTuple[Optional[str], int])r?z,tuple[StreamHandler[TextIOWrapper], BytesIO])+rD�
__future__r�loggingr+r�inspectr�iorrrrr	r
�typingrrr
�zope.interface.exceptionsr�zope.interface.verifyr�twisted.python.compatr�twisted.python.failurer�
twisted.trialr�_interfacesrr�_levelsr�_stdlibrr!r$�TestCaserGr0r�r-rEr"r �<module>r�s{���#��
�!�%�B�B�(�(�@�.�.�*�"�0��'��!6�!6�Hu3�X�.�.�u3�p
� $�j�(�(�$r"

Zerion Mini Shell 1.0