%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_flatten.cpython-312.pyc

�

Ϫ�f�%���dZddlZddlmZddlmZmZmZ	ddlm	Z	ddlmZddl
mZmZmZmZdd	lmZdd
lmZGd�dej,�Zy#e
$rdZ	Y�=wxYw)
z+
Test cases for L{twisted.logger._format}.
�N)�count)�Any�Callable�Optional)�tzset)�unittest�)�KeyFlattener�
aFormatter�extractField�flattenEvent)�formatEvent)�LogEventc��eZdZdZdd�Zdd�Zdd�Zdd�Z	ddee	de	fd	�Z
dd
�Zdd�Zdd�Z
d
�fdee	ge	fddfd�Zdd�Zdd�Zdd�Zdd�Zy)�FlatFormattingTestsz9
    Tests for flattened event formatting functions.
    �returnNc���t��Gd�d�}td�fd�|�ddd��}t|�t|�}|d	=|d
=tjtj
|��}|j
t|�d�y)
a)
        L{flattenEvent} will "flatten" an event so that, if scrubbed of all but
        serializable objects, it will preserve all necessary data to be
        formatted once serialized.  When presented with an event thusly
        flattened, L{formatEvent} will produce the same output.
        c��eZdZdZy)�;FlatFormattingTests.test_formatFlatEvent.<locals>.Ephemeral�valueN)�__name__�
__module__�__qualname__�	attribute���B/usr/lib/python3/dist-packages/twisted/logger/test/test_flatten.py�	Ephemeralr%s���Irrz�callable: {callme()} attribute: {object.attribute} numrepr: {number!r} numstr: {number!s} strrepr: {string!r} unistr: {unistr!s}c���t��S�N)�next��counters�r�<lambda>z:FlatFormattingTests.test_formatFlatEvent.<locals>.<lambda>1s���4��=�r��hello�ö)�
log_format�callme�object�number�string�unistrr)r*uMcallable: 0 attribute: value numrepr: 7 numstr: 7 strrepr: 'hello' unistr: öN)r�dictr
�json�loads�dumps�assertEqualr)�selfr�event1�event2�event3r#s     @r�test_formatFlatEventz(FlatFormattingTests.test_formatFlatEvents�����'��	 �	 ��%�)��;����
�� 	�V���f����8���8�����D�J�J�v�.�/���������
	
rc���tdd��}t|�tjtj|��}|jt
|�jd��y)zH
        If the format string is invalid, an error is produced.
        zstrrepr: {string!X}r&)r(r,zUnable to format eventN)r.r
r/r0r1�
assertTruer�
startswith)r3r4r5s   r�test_formatFlatEventBadFormatz1FlatFormattingTests.test_formatFlatEventBadFormatJsR���-��
��
	�V�����D�J�J�v�.�/������F�+�6�6�7O�P�Qrc��Gd�d�}|�}td|��}t|�|j�|jt	|�d�y)z�
        L{formatEvent} will prefer the stored C{str()} or C{repr()} value for
        an object, in case the other version.
        c�(�eZdZdZdZdd�Zdefd�Zy)�PFlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistablez.
            Unpersitable object.
            FrNc��d|_y)z0
                Self destruct.
                TN��
destructed�r3s r�selfDestructz]FlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistable.selfDestructes��#'��rc��|jryy)Nzpost-serialization garbagezun-persistabler@rBs r�__repr__zYFlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistable.__repr__ks���?�?�7�+r�rN)rrr�__doc__rArC�strrErrr�
Unpersistabler>^s��
��J�
'�
,�#�
,rrIzunpersistable: {unpersistable})r(�
unpersistablezunpersistable: un-persistableN)r.r
rCr2r)r3rI�upr4s    r�%test_formatFlatEventWithMutatedFieldsz9FlatFormattingTests.test_formatFlatEventWithMutatedFieldsXsK��	,�	,�&�_���!A�QS�T���V��
��������V�,�.M�Nrc��dtdtfd�}	|j|d�d�|j|d�d�|j|d�d	�|j|d
�d�|j|d�d
�|j|d�d�|j|d�d�|j|d�d�|j|d�d�|j|d�d�t�}t	j
d�\\}}}}|�J�|j|j
|||�d�|j|j
|||�d�y#t$r�wxYw)zh
        Test that L{KeyFlattener.flatKey} returns the expected keys for format
        fields.
        �formatrc��tj|�D]'\}}}}|�J�t�j|||�cSJd��)Nz*Unable to derive key from format: {format})r�parser
�flatKey)rN�literalText�	fieldName�
formatSpec�
conversions     r�
keyFromFormatz=FlatFormattingTests.test_keyFlattening.<locals>.keyFromFormats`���!�!�&�)�
Q������ �,�,�,�#�~�-�-�i��Z�P�P�
Q�
G�F�F�5rz{}z!:z{foo}zfoo!:z{foo!s}zfoo!s:z{foo!r}zfoo!r:z{foo:%s}zfoo!:%sz{foo:!}zfoo!:!z{foo::}zfoo!::z
{foo!s:%s}zfoo!s:%sz	{foo!s:!}zfoo!s:!z	{foo!s::}zfoo!s::z{x}Nzx!:zx!:/2)rHr2�
ValueErrorr
rrPrQ)r3rV�
sameFlattenerrRrSrTrUs       r�test_keyFlatteningz&FlatFormattingTests.test_keyFlatteningys���		G�#�		G�#�		G�	����]�4�0�$�7�	
����w�/��9�	
����y�1�8�<�����y�1�8�<�	
����z�2�I�>�����y�1�8�<�����y�1�8�<�	
����|�4�j�A�����{�3�Y�?�����{�3�Y�?�$��
�
���U�#�	
�
������$�$�$�����!�!�)�Z��D�e�	
�	
����!�!�)�Z��D�g�	
��K�	�
�		�s�E3�3E>�eventc���|�(t��G�fd�d�}td|���}t|�|jt	|�d�|S)z�
        The same format field used twice in one event is rendered twice.

        @param event: An event to flatten.  If L{None}, create a new event.
        @return: C{event} or the event created.
        c�"��eZdZdZdef�fd�Zy)�JFlatFormattingTests._test_formatFlatEvent_fieldNamesSame.<locals>.CountStrz&
                Hack
                rc�,��tt���Sr )rHr!)r3r#s �r�__str__zRFlatFormattingTests._test_formatFlatEvent_fieldNamesSame.<locals>.CountStr.__str__�s����t�G�}�-�-rN)rrrrGrHr_r"s�r�CountStrr]�s����.�S�.rr`z{x} {x}�r(�xz0 1)rr.r
r2r)r3rZr`r#s   @r�$_test_formatFlatEvent_fieldNamesSamez8FlatFormattingTests._test_formatFlatEvent_fieldNamesSame�sS����=��g�G�
.�
.��$��*��E�
	�U������U�+�U�3��rc�$�|j�y)zR
        The same format field used twice in one event is rendered twice.
        N�rcrBs r�"test_formatFlatEventFieldNamesSamez6FlatFormattingTests.test_formatFlatEventFieldNamesSame�s��	
�1�1�3rc�F�|j�}|j|�y)zb
        The same event flattened twice gives the same (already rendered)
        result.
        Nre)r3rZs  r�'test_formatFlatEventFieldNamesSameAgainz;FlatFormattingTests.test_formatFlatEventFieldNamesSameAgain�s ��
�9�9�;���1�1�%�8rc�n�tdd��}t|�t|�}|j|d�y)zs
        L{formatEvent} will handle a flattened event with tailing text after
        a replacement field.
        ztest {x} trailingrraztest value trailingN)r.r
rr2)r3rZ�results   r� test_formatEventFlatTrailingTextz4FlatFormattingTests.test_formatEventFlatTrailingText�s9��
�*��
��	�U���U�#������!6�7rc��|Sr r)rbs rr$zFlatFormattingTests.<lambda>�s��q�r�flattenFirstc����Gd�d��G�fd�d�}td|���}||��dtdtf�fd	�}|j|d
�d�|j|d�d
�|j|d�d�y)z�
        L{extractField} will extract a field used in the format string.

        @param flattenFirst: callable to flatten an event
        c��eZdZdefd�Zy)�=FlatFormattingTests.test_extractField.<locals>.ObjectWithReprrc��y)N�reprrrBs rrEzFFlatFormattingTests.test_extractField.<locals>.ObjectWithRepr.__repr__�s��rN)rrrrHrErrr�ObjectWithReprrp�s��
�#�
rrsc�"��eZdZd�fd�Zdd�Zy)�8FlatFormattingTests.test_extractField.<locals>.SomethingNc�,��d|_��|_y)Nr%)r+r*)r3rss �r�__init__zAFlatFormattingTests.test_extractField.<locals>.Something.__init__�s������,�.��rc��td��)Nz
Just in case.)�NotImplementedErrorrBs r�__getstate__zEFlatFormattingTests.test_extractField.<locals>.Something.__getstate__s
��)�/�:�:rrF)rrrrwrz)rss�r�	Somethingru�s
���
/�
;rr{z%{something.number} {something.object})r(�	something�fieldrc���t|��Sr )r)r}�	flatteneds �r�extractz6FlatFormattingTests.test_extractField.<locals>.extract
s�����y�1�1rzsomething.numberr%zsomething.number!s�7zsomething.object!srrN)r.rHrr2)r3rmr{rZr�rsrs     @@r�test_extractFieldz%FlatFormattingTests.test_extractField�s����	�	�	;�	;��>��k�
��
!��'�	�	2�3�	2�3�	2�	
����!3�4�a�8�����!5�6��<�����!5�6��?rc�F�dtdtfd�}|j|�y)zi
        L{extractField} behaves identically if the event is explicitly
        flattened first.
        rZrc��t|�|Sr )r
)rZs rrzDFlatFormattingTests.test_extractFieldFlattenFirst.<locals>.flatteneds������LrN)rr�)r3rs  r�test_extractFieldFlattenFirstz1FlatFormattingTests.test_extractFieldFlattenFirsts%��	�X�	�(�	�	
���y�)rc�N�ddd�}t|�|j|ddd��y)zT
        L{flattenEvent} will do nothing to an event with no format string.
        �b�)�a�cN�r
r2�r3�
inputEvents  r�test_flattenEventWithoutFormatz2FlatFormattingTests.test_flattenEventWithoutFormat s+���Q�'�
��Z� �����3�Q�%7�8rc�R�dddd�}t|�|j|dddd��y)zz
        L{flattenEvent} will do nothing to an event with a format string that
        contains no format fields.
        r�r�zsimple message�r�r�r(Nr�r�s  r� test_flattenEventWithInertFormatz4FlatFormattingTests.test_flattenEventWithInertFormat(s8��
�Q�6F�G�
��Z� �������.�
�	
rc�R�dddd�}t|�|j|dddd��y)zb
        L{flattenEvent} will do nothing to an event with log_format set to
        None.
        r�r�Nr�r�r�s  r�test_flattenEventWithNoneFormatz3FlatFormattingTests.test_flattenEventWithNoneFormat8s7��
�Q�d�;�
��Z� �������"�
�	
rrFr )rrrrGr7r;rLrYrrrcrfrhrkrr�r�r�r�r�rrrrrs����,
�\R�O�B;
�|+/���h�'��	��<4�9�
8� >I�!@�$�h�Z��%9�:�!@�	
�!@�F
*�9�
� 
rr)rGr/�	itertoolsr�typingrrr�timer�ImportError�
twisted.trialr�_flattenr
rrr
�_formatr�_interfacesr�TestCaserrrr�<module>r�s[�����*�*���#�K�K�!�"�o
�(�+�+�o
�����E��s�A�A�A

Zerion Mini Shell 1.0