Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/testfixtures/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/testfixtures/__pycache__/logcapture.cpython-311.pyc

�

�܋f+����ddlmZddlmZddlmZmZmZmZm	Z	m
Z
mZddlZddlZddl
Z
ddlmZddlmZmZddlmZGd	�d
ej��ZGd�de��Zd
efd�ZdS)�)�defaultdict)�	LogRecord)�List�Union�Tuple�Sequence�Callable�Any�OptionalN)�pformat�)�SequenceComparison�compare)�wrapc��eZdZUdZeeed<eeed<e	��Z
dZdZe
jZ							d&d	eeeefd
ededed
eeeeegeffdedefd�Zed���Zd�Zd�Zd�Zd�Zd�Zd'defd�Zde
jfd�Z d�Z!d�Z"ed���Z#d�Z$defd�Z%d�Z&d �Z'dd!�d"efd#�Z(d$�Z)d%�Z*dS)(�
LogCapturea
    These are used to capture entries logged to the Python logging
    framework and make assertions about what was logged.

    :param names: A string (or tuple of strings) containing the dotted name(s)
                  of loggers to capture. By default, the root logger is
                  captured.

    :param install: If `True`, the :class:`LogCapture` will be
                    installed as part of its instantiation.

    :param propagate: If specified, any captured loggers will have their
                      `propagate` attribute set to the supplied value. This can
                      be used to prevent propagation from a child logger to a
                      parent logger that has configured handlers.

    :param attributes:

      The sequence of attribute names to return for each record or a callable
      that extracts a row from a record.

      If a sequence of attribute names, those attributes will be taken from the
      :class:`~logging.LogRecord`. If an attribute is callable, the value
      used will be the result of calling it. If an attribute is missing,
      ``None`` will be used in its place.

      If a callable, it will be called with the :class:`~logging.LogRecord`
      and the value returned will be used as the row.

    :param recursive_check:

      If ``True``, log messages will be compared recursively by
      :meth:`LogCapture.check`.

    :param ensure_checks_above:

      The log level above which checks must be made for logged events.
      See :meth:`ensure_checked`.

    �records�ensure_checks_aboveFNTr
��name�	levelname�
getMessage�names�install�level�	propagate�
attributes�recursive_checkc�p�tj�|��t|t��s|f}||_||_||_||_||_	tt��|_|�
|j
|_n||_|���|r|���dSdS�N)�logging�Handler�__init__�
isinstance�tuplerrrrrr�dict�old�default_ensure_checks_abover�clearr)�selfrrrrrrrs        �h/builddir/build/BUILD/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/testfixtures/logcapture.pyr#zLogCapture.__init__As���	�� � ��&�&�&��%��'�'�	��I�E���
���
�"���$���.����t�$�$����&�'+�'G�D�$�$�':�D�$��
�
�����	��L�L�N�N�N�N�N�	�	�c��|jr;tjdd�d�|jD����z��dSdS)NzFLogCapture instances not uninstalled by shutdown, loggers captured:
%s�
c3�>K�|]}t|j��V��dSr )�strr)�.0�is  r+�	<genexpr>z$LogCapture.atexit.<locals>.<genexpr>ds*����"G�"G�A�3�q�w�<�<�"G�"G�"G�"G�"G�"Gr,)�	instances�warnings�warn�join)�clss r+�atexitzLogCapture.atexit^s_���=�	��M���	�	�"G�"G���"G�"G�"G�H�H�J�
�
�
�
�
�	�	r,c�*�t|j��Sr )�lenr�r*s r+�__len__zLogCapture.__len__gs���4�<� � � r,c�B�|�|j|��Sr )�_actual_rowr)r*�indexs  r+�__getitem__zLogCapture.__getitem__js�������U� 3�4�4�4r,c�f�t|��D] \}}||krd|j|_dS�!dS)NT)�	enumerater�checked)r*�whatr2�items    r+�__contains__zLogCapture.__contains__msH�� ����	�	�G�A�t��t�|�|�*.���Q��'��t�t��	�	r,c��g|_dS)z*Clear any entries that have been captured.N)rr<s r+r)zLogCapture.clearss
������r,c�(�|jD]	}d|_�
dS)z�
        Mark all captured events as checked.
        This should be called if you have made assertions about logging
        other than through :class:`LogCapture` methods.
        TN)rrD�r*�records  r+�mark_all_checkedzLogCapture.mark_all_checkedws(���l�	"�	"�F�!�F�N�N�	"�	"r,c�
�|�|j}|tjkrdSg}|jD]<}|j|kr/|js(|�|�|�����=|rtdt|��z���dS)z�
        Ensure every entry logged above the specified `level` has been checked.
        Raises an :class:`AssertionError` if this is not the case.

        :param level: the logging level, defaults to :attr:`ensure_checks_above`.
        NzNot asserted ERROR log(s): %s)
rr!�NOTSETr�levelnorD�appendr?�AssertionErrorr)r*r�
un_checkedrKs    r+�ensure_checkedzLogCapture.ensure_checked�s����=��,�E��G�N�"�"��F��
��l�	<�	<�F��~��&�&�v�~�&��!�!�$�"2�"2�6�":�":�;�;�;���	+� �3��Z�(�(�"*�+�+�
+�	+�	+r,rKc�H�d|_|j�|��dS)z9
        Record the :class:`~logging.LogRecord`.
        FN)rDrrPrJs  r+�emitzLogCapture.emit�s'���������F�#�#�#�#�#r,c�4�|jD]�}tj|��}|j|jd|<|j|jd|<|j|jd|<|j|jd|<|j|jd|<|�	|j��g|_|g|_d|_|j�|j|_��|j
�|��|jj
s'tj|j��d|j_
dSdS)	a)
        Install this :class:`LogCapture` into the Python logging
        framework for the named loggers.

        This will remove any existing handlers for those loggers and
        drop their level to that specified on this :class:`LogCapture` in order
        to capture all logging.
        �levels�filters�handlers�disabledrFNT)rr!�	getLoggerrr'rXrYrZr�setLevelr4�add�	__class__�atexit_setupr9�register�r*r�loggers   r+rzLogCapture.install�s���J�	2�	2�D��&�t�,�,�F�'-�|�D�H�X��t�$�(.��D�H�Y���%�)/��D�H�Z� ��&�)/��D�H�Z� ��&�*0�*:�D�H�[�!�$�'��O�O�D�J�'�'�'��F�N�#�f�F�O�#�F�O��~�)�#'�>�� ������4� � � ��~�*�	/��O�D�K�(�(�(�*.�D�N�'�'�'�	/�	/r,c��||jvr�|jD]�}tj|��}|�|jd|��|jd||_|jd||_|jd||_|jd||_	��|j�
|��dSdS)a&
        Un-install this :class:`LogCapture` from the Python logging
        framework for the named loggers.

        This will re-instate any existing handlers for those loggers
        that were removed during installation and restore their level
        that prior to installation.
        rWrXrYrZrN)r4rr!r[r\r'rXrYrZr�removeras   r+�	uninstallzLogCapture.uninstall�s����4�>�!�!��
�
?�
?�� �*�4�0�0�������� 2�4� 8�9�9�9�!%��)�!4�T�!:���"&�(�:�"6�t�"<���"&�(�:�"6�t�"<���#'�8�K�#8��#>�� � ��N�!�!�$�'�'�'�'�'�"�!r,c�\�t|j��D]}|����dS)z=This will uninstall all existing :class:`LogCapture` objects.N)r%r4re)r8r2s  r+�
uninstall_allzLogCapture.uninstall_all�s6���s�}�%�%�	�	�A�
�K�K�M�M�M�M�	�	r,c�>�t|j��r|�|��Sg}|jD]A}t||d��}t|��r
|��}|�|���Bt	|��dkr|dSt|��S)Nr
r)�callabler�getattrrPr;r%)r*rK�values�a�values     r+r?zLogCapture._actual_row�s����D�O�$�$�	%��?�?�6�*�*�*��F��_�
%�
%�����4�0�0���E�?�?�$�!�E�G�G�E��
�
�e�$�$�$�$��6�{�{�a����a�y� ��V�}�}�$r,�returnc�n�g}|jD]*}|�|�|�����+|S)a�
        The sequence of actual records logged, having had their attributes
        extracted as specified by the ``attributes`` parameter to the
        :class:`LogCapture` constructor.

        This can be useful for making more complex assertions about logged
        records. The actual records logged can also be inspected by using the
        :attr:`records` attribute.
        )rrPr?)r*�actual�rs   r+rpzLogCapture.actual�sB������	/�	/�A��M�M�$�*�*�1�-�-�.�.�.�.��
r,c�v�|jsdSd�d�|���D����S)NzNo logging capturedr.c��g|]}d|z��S)z
%s %s
  %s�)r1rqs  r+�
<listcomp>z&LogCapture.__str__.<locals>.<listcomp>�s��C�C�C��-�!�+�C�C�Cr,)rr7rpr<s r+�__str__zLogCapture.__str__�s;���|�	)�(�(��y�y�C�C�T�[�[�]�]�C�C�C�D�D�Dr,c��t||���|j���|���dS)a7
        This will compare the captured entries with the expected
        entries provided and raise an :class:`AssertionError` if they
        do not match.

        :param expected:

          A sequence of entries of the structure specified by the ``attributes``
          passed to the constructor.
        )rp�	recursiveN)rrprrL)r*�expecteds  r+�checkzLogCapture.check�sI��	���;�;�=�=��*�	�	�	�	�
	
�������r,)�
order_mattersr{c��|���}t||d|jd��}||krt|j���|jD]}d|j|_�dS)as
        This will check if the captured entries contain all of the expected
        entries provided and raise an :class:`AssertionError` if not.
        This will ignore entries that have been captured but that do not
        match those in ``expected``.

        :param expected:

          A sequence of entries of the structure specified by the ``attributes``
          passed to the constructor.

        :param order_matters:

          A keyword-only parameter that controls whether the order of the
          captured entries is required to match those of the expected entries.
          Defaults to ``True``.
        T)�ordered�partialrxN)rprrrQ�failed�checked_indicesrrD)r*r{ryrpr@s     r+�
check_presentzLogCapture.check_presents|��$������%�
�}�d�d�FZ�
�
�
���v��� ���1�1�1��-�	/�	/�E�*.�D�L���'�'�	/�	/r,c��|Sr rtr<s r+�	__enter__zLogCapture.__enter__"s���r,c�V�|���|���dSr )rerS)r*�typerm�	tracebacks    r+�__exit__zLogCapture.__exit__%s*���������������r,)NTr
NrFNr )+�__name__�
__module__�__qualname__�__doc__rr�__annotations__r�int�setr4r_�	installedr!rNr(rr0r�boolrr	r
r#�classmethodr9r=rArGr)rLrSrUrrergr?rprvrzr�r�r�rtr,r+rr
sq�������'�'�T�)�_����!�#��&�&�&�����I��L��I�")�.��-1� ��"�L�%*�'+�����e�C�j��)�����	�
���h�s�m�X�y�k�3�6F�-G�G�H�
�"��"%�����:����[��!�!�!�5�5�5�������"�"�"�+�+�C�+�+�+�+�($�7�,�$�$�$�$�/�/�/�6(�(�(�&����[��
%�%�%�$
��
�
�
�
�E�E�E�
 � � �$>B�/�/�/�d�/�/�/�/�6�������r,rc��eZdZd�ZdS)�LogCaptureForDecoratorc�b�t�|��|���|Sr )rrr)r<s r+rzLogCaptureForDecorator.install,s(�����4� � � ��
�
�����r,N)r�r�r�rrtr,r+r�r�*s#����������r,r�rc�X�t|pdfddi|��}t|j|j��S)a�
    A decorator for making a :class:`LogCapture` installed and
    available for the duration of a test function.

    :param names: An optional sequence of names specifying the loggers
                  to be captured. If not specified, the root logger
                  will be captured.

    Keyword parameters other than ``install`` may also be supplied and will be
    passed on to the :class:`LogCapture` constructor.
    NrF)r�rrre)r�kw�ls   r+�log_capturer�2s6��	�u�}��B�B�e�B�r�B�B�A���	�1�;�'�'�'r,)�collectionsrr!r�typingrrrrr	r
rr9r5�pprintr�
comparisonrr�utilsrr"rr�r0r�rtr,r+�<module>r�s:��#�#�#�#�#�#�������H�H�H�H�H�H�H�H�H�H�H�H�H�H�H�H�H�H�
�
�
�
���������������3�3�3�3�3�3�3�3�������Z�Z�Z�Z�Z���Z�Z�Z�z�����Z����
(��
(�
(�
(�
(�
(�
(r,

Hacked By AnonymousFox1.0, Coded By AnonymousFox