Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/testfixtures/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/testfixtures/__pycache__/logcapture.cpython-37.pyc

B

R�Xd�@sjddlmZddlZddlZddlZddlmZddlmZGdd�dej	�Z
Gdd�de
�Zd	d
�ZdS)�)�defaultdictN)�compare)�wrapc@s�eZdZdZe�ZdZdZd!dd�Ze	d	d
��Z
dd�Zd
d�Zdd�Z
dd�Ze	dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �ZdS)"�
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`.
    FNT���nameZ	levelnameZ
getMessagecCs\tj�|�t|t�s|f}||_||_||_||_||_	t
t�|_|�
�|rX|��dS)N)�logging�Handler�__init__�
isinstance�tuple�names�level�	propagate�
attributes�recursive_checkr�dict�old�clear�install)�selfrrrrrr�r�H/opt/alt/python37/lib/python3.7/site-packages/testfixtures/logcapture.pyr5s

zLogCapture.__init__cCs*|jr&t�dd�dd�|jD���dS)NzFLogCapture instances not uninstalled by shutdown, loggers captured:
%s�
css|]}t|j�VqdS)N)�strr)�.0�irrr�	<genexpr>Ksz$LogCapture.atexit.<locals>.<genexpr>)�	instances�warnings�warn�join)�clsrrr�atexitEszLogCapture.atexitcCs
g|_dS)z*Clear any entries that have been captured.N)�records)rrrrrNszLogCapture.clearcCs|j�|�dS)N)r%�append)r�recordrrr�emitRszLogCapture.emitcCs�x�|jD]z}t�|�}|j|jd|<|j|jd|<|j|jd|<|j|jd|<|�|j�|g|_d|_|jdk	r|j|_qW|j	�
|�|jjs�t
�|j
�d|j_dS)z�
        Install this :class:`LogHandler` into the Python logging
        framework for the named loggers.

        This will remove any existing handlers for those loggers and
        drop their level to 1 in order to capture all logging.
        �levels�handlers�disabled�	progagateFNT)rr	�	getLoggerrrr*r+r�setLevelr�add�	__class__�atexit_setupr$�register)rr�loggerrrrrUs

zLogCapture.installcCsx||jkrtx\|jD]R}t�|�}|�|jd|�|jd||_|jd||_|jd||_qW|j�	|�dS)a%
        Un-install this :class:`LogHandler` 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 retore their level
        that prior to installation.
        r)r*r+r,N)
rrr	r-r.rr*r+r�remove)rrr3rrr�	uninstallms	

zLogCapture.uninstallcCs xt|j�D]}|��qWdS)z=This will uninstall all existing :class:`LogHandler` objects.N)r
rr5)r#rrrr�
uninstall_allszLogCapture.uninstall_allccs4x.|jD]$}t||d�}t|�r&|�}|VqWdS)N)r�getattr�callable)rr'�a�valuerrr�_actual_row�s
zLogCapture._actual_rowccsXxR|jD]H}t|j�r$|�|�Vqt|�|��}t|�dkrJ|dVq|VqWdS)Nrr)r%r8rr
r;�len)r�r�resultrrr�actual�s
zLogCapture.actualcCs"|js
dSd�dd�|��D��S)NzNo logging capturedrcSsg|]}d|�qS)z
%s %s
  %sr)rr=rrr�
<listcomp>�sz&LogCapture.__str__.<locals>.<listcomp>)r%r"r?)rrrr�__str__�szLogCapture.__str__cGst|t|���|jd�S)at
        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 3-tuples containing the
                         expected log entries. Each tuple should be of
                         the form (logger_name, string_level, message)
        )r?�	recursive)rr
r?r)rZexpectedrrr�check�s

zLogCapture.checkcCs|S)Nr)rrrr�	__enter__�szLogCapture.__enter__cCs|��dS)N)r5)r�typer:�	tracebackrrr�__exit__�szLogCapture.__exit__)NTrNrF)�__name__�
__module__�__qualname__�__doc__�setrr1Z	installedr�classmethodr$rr(rr5r6r;r?rArCrDrGrrrrr
s&"
	rc@seZdZdd�ZdS)�LogCaptureForDecoratorcCst�|�|S)N)rr)rrrrr�s
zLogCaptureForDecorator.installN)rHrIrJrrrrrrN�srNcOs&t|pdfddi|��}t|j|j�S)a�
    A decorator for making a :class:`LogCapture` installed an
    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)rNrrr5)r�kw�lrrr�log_capture�srQ)
�collectionsrr$r	r Ztestfixtures.comparisonrZtestfixtures.utilsrr
rrNrQrrrr�<module>s'