HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/logger/test/__pycache__/test_stdlib.cpython-38.pyc
U


W[�!�@s�dZddlZddlmZmZddlZddlmZddl	m
Z
mZddlm
Z
mZddlmZddlmZd	d
lmZd	dlmZd	dlmZd
d�ZGdd�dej�ZGdd�de�Zdd�ZGdd�dej�Z dS)z+
Test cases for L{twisted.logger._format}.
�N)�BytesIO�
TextIOWrapper)�
getsourcefile)�verifyObject�BrokenMethodImplementation)�_PY3�currentframe)�Failure)�unittest�)�LogLevel)�ILogObserver)�STDLibLogObservercCs&td�}ttj|jd�|jdfS)z�
    Retrive the file name and line number immediately after where this function
    is called.

    @return: the file name and line number
    @rtype: 2-L{tuple} of L{str}, L{int}
    ��__name__)rr�sys�modules�	f_globals�f_lineno)Zcaller�r�A/usr/lib/python3/dist-packages/twisted/logger/test/test_stdlib.py�nextLines�rc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�STDLibLogObserverTestsz)
    Tests for L{STDLibLogObserver}.
    c
CsFt�}ztt|�Wn,tk
r@}z|�|�W5d}~XYnXdS)z=
        L{STDLibLogObserver} is an L{ILogObserver}.
        N)rrr
rZfail)�self�observer�errr�test_interface+s
z%STDLibLogObserverTests.test_interfacecCst�}|�|j�|S)z�
        Create a logging object we can use to test with.

        @return: a stdlib-style logger
        @rtype: L{StdlibLoggingContainer}
        )�StdlibLoggingContainerZ
addCleanup�close)rZloggerrrr�	py_logger6sz STDLibLogObserverTests.py_loggercGs:|��}ttjdd�}|D]}||�q|jj|��fS)a`
        Send one or more events to Python's logging module, and
        capture the emitted L{logging.LogRecord}s and output stream as
        a string.

        @param events: events
        @type events: L{tuple} of L{dict}

        @return: a tuple: (records, output)
        @rtype: 2-tuple of (L{list} of L{logging.LogRecord}, L{bytes}.)
        r)Z
stackDepth)rrZdefaultStackDepth�bufferedHandler�records�outputAsText)r�eventsZplr�eventrrr�logEventBs�
zSTDLibLogObserverTests.logEventcCs4|�i�\}}|�t|�d�|�|djd�dS)z
        Logger name.
        rrZtwistedN)r%�assertEqual�len�name�rr!�outputrrr�	test_nameYsz STDLibLogObserverTests.test_namec	Cs�dtjtjtjtjtjtjtjtjtj	tj
tji}g}|��D]2\}}i}|dk	rZ||d<t
|�|d<|�|�q>|j|�\}}|�t|�t|��tt|��D]}|�||j||d�q�dS)z
        Log levels.
        NZ	log_levelZ
py_levelno)�
py_logging�INFOr�debug�DEBUG�info�warnZWARNING�errorZERRORZcriticalZCRITICAL�items�int�appendr%r&r'�rangeZlevelno)	rZlevelMappingr#�levelZpyLevelr$r!r*�irrr�test_levelscs0�
z"STDLibLogObserverTests.test_levelscCs`t�\}}|�i�\}}|�t|�d�|�|dj|�|�|dj|�|�|dj�dS)zb
        C{pathname}, C{lineno}, C{exc_info}, C{func} is set properly on
        records.
        rrN)rr%r&r'�pathname�linenoZassertIsNone�exc_info)r�filenameZlogLiner!r*rrr�test_callerInfo�s
z&STDLibLogObserverTests.test_callerInfocCsVtddd�}|�|�\}}|�t|�d�|�t|dj�d�|�|djd�dS)	zL
        Basic formattable event passes the format along correctly.
        �
Hello, {who}!�dude��
log_format�whorrzHello, dude!rN)�dictr%r&r'�str�msg�args�rr$r!r*rrr�test_basicFormat�s
z'STDLibLogObserverTests.test_basicFormatcCsDtddd�}|�|�\}}|�t|�d�|�|�d�t|��dS)z<
        Basic formattable event renders correctly.
        r?r@rArz:Hello, dude!
N)rDr%r&r'Z
assertTrue�endswith�reprrHrrr�test_basicFormatRendered�s�z/STDLibLogObserverTests.test_basicFormatRenderedcCs8|�i�\}}|�t|�d�|�t|dj�d�dS)z'
        Event with no format.
        rr�N)r%r&r'rErFr)rrr�
test_noFormat�sz$STDLibLogObserverTests.test_noFormatcCs�dd�}z
|�Wntk
r,t�}YnXtdd|d�}|�|�\}}|�t|�d�|�d|�|�d|�|�d|�d	S)
zK
        An event with a failure logs the failure details as well.
        cSsdddS�Nrrrrrrr�failing_func�sz9STDLibLogObserverTests.test_failure.<locals>.failing_func�Hi mom�me�rBrCZlog_failurer�in failing_func�ZeroDivisionErrorN)rUr	rDr%r&r'�assertIn�rrPZfailurer$r!r*rrr�test_failure�s
z#STDLibLogObserverTests.test_failurecCs�dd�}z
|�Wntk
r,t�}YnX|��tdd|d�}|�|�\}}|�t|�d�|�d|�|�d|�|�d|�d	S)
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.
        cSsdddSrOrrrrrrP�sz@STDLibLogObserverTests.test_cleanedFailure.<locals>.failing_funcrQrRrSrrTrUN)rUr	ZcleanFailurerDr%r&r'rVrWrrr�test_cleanedFailure�s
z*STDLibLogObserverTests.test_cleanedFailureN)r�
__module__�__qualname__�__doc__rrr%r+r9r>rIrLrNrXrYrrrrr&s
$
rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	rzF
    Continer for a test configuration of stdlib logging objects.
    cCs\t�d�|_|j��|_|j�tj�t�|_|j�	|j�t
�\|_|_|j�	|j�dS)NrM)
r,Z	getLogger�
rootLoggerZgetEffectiveLevel�
originalLevel�setLevelr/�BufferedHandlerr Z
addHandler�handlerAndBytesIO�
streamHandlerr*�rrrr�__init__�szStdlibLoggingContainer.__init__cCsB|j�|j�|j�|j�|j�|j�|j��|j��dS)z#
        Close the logger.
        N)r]r_r^Z
removeHandlerr rbrr*rcrrrr�s

zStdlibLoggingContainer.closecCs|j���d�S)z
        Get the output to the underlying stream as text.

        @return: the output text
        @rtype: L{unicode}
        �utf-8)r*�getvalue�decodercrrrr"sz#StdlibLoggingContainer.outputAsTextN)rrZr[r\rdrr"rrrrr�s
rcCsHt�}|}tj}tr"t|ddd�}t�|�}t�|�}|�|�||fS)z�
    Construct a 2-tuple of C{(StreamHandler, BytesIO)} for testing interaction
    with the 'logging' module.

    @return: handler and io object
    @rtype: tuple of L{StreamHandler} and L{io.BytesIO}
    re�
)�encoding�newline)rr,ZBASIC_FORMATrrZ	FormatterZ
StreamHandlerZsetFormatter)r*�stream�templateZ	formatterZhandlerrrrras


rac@s eZdZdZdd�Zdd�ZdS)r`zN
    A L{py_logging.Handler} that remembers all logged records in a list.
    cCstj�|�g|_dS)z5
        Initialize this L{BufferedHandler}.
        N)r,�Handlerrdr!rcrrrrd$szBufferedHandler.__init__cCs|j�|�dS)z&
        Remember the record.
        N)r!r5)r�recordrrr�emit,szBufferedHandler.emitN)rrZr[r\rdrorrrrr`sr`)!r\r�iorrZloggingr,�inspectrZzope.interface.verifyrrZtwisted.python.compatrrZtwisted.python.failurer	Z
twisted.trialr
Z_levelsrZ	_observerr
Z_stdlibrrZTestCaser�objectrrarmr`rrrr�<module>s">(