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_logger.cpython-38.pyc
U


W[��@s�dZddlmZddlmZddlmZddlmZddlm	Z	ddl
mZGd	d
�d
e	�ZGdd�de
�ZGd
d�dej�ZdS)z+
Test cases for L{twisted.logger._logger}.
�)�unittest�)�InvalidLogLevelError)�LogLevel)�formatEvent��Logger)�globalLogPublisherc@seZdZdZddd�ZdS)�
TestLoggerz^
    L{Logger} with an overridden C{emit} method that keeps track of received
    events.
    Nc	sL�fdd�}t�|�ztj�||f|�W5t�|�X|||d��_dS)Ncs
|�_dS�N��eventr��self��A/usr/lib/python3/dist-packages/twisted/logger/test/test_logger.py�observersz!TestLogger.emit.<locals>.observer)�level�format�kwargs)r	ZaddObserverZremoveObserverr�emit�emitted)rrrrrrrrrs
�zTestLogger.emit)N)�__name__�
__module__�__qualname__�__doc__rrrrrr
sr
c@s(eZdZdZe�Zddd�Zdd�ZdS)�LogComposedObjectz3
    A regular object, with a logger attached.
    NcCs
||_dSr��state)rrrrr�__init__0szLogComposedObject.__init__cCsdj|jd�S)Nz<LogComposedObject {state}>r)rrrrrr�__str__4szLogComposedObject.__str__)N)rrrrr
�logrr rrrrr*s
rc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�LoggerTestsz
    Tests for L{Logger}.
    cCs*d}t|�}|�t|�d�t|���dS)z"
        repr() on Logger
        Zblearghz<Logger {0}>N)r�assertEqual�reprr)r�	namespacer!rrr�	test_repr>szLoggerTests.test_reprcCst�}|�|jt�dS)z3
        Default namespace is module name.
        N)rr#r%r�rr!rrr�test_namespaceDefaultGsz!LoggerTests.test_namespaceDefaultcCs.g}tdttd�t��|�|djd�dS)z�
        Default namespace is C{"<unknown>"} when a logger is created from a
        context in which is can't be determined automatically and no namespace
        was specified.
        zresult.append(Logger())rrz	<unknown>N)�exec�dictr�localsr#r%)r�resultrrr�test_namespaceOMGItsTooHardOs�z'LoggerTests.test_namespaceOMGItsTooHardcCsjt�}d�|j|jj�}|�|jj|�|�tjj|�|�tjj	t�|�|jj	|�|�
t�j	�dS)z�
        Default namespace for classes using L{Logger} as a descriptor is the
        class name they were retrieved from.
        z{0}.{1}N)rrr�	__class__rr#r!r%ZassertIs�source�assertIsNoner)r�objZexpectedNamespacerrr�test_namespaceAttribute]s�z#LoggerTests.test_namespaceAttributecsLg�G�fdd�dt�}|j�d�|�t��d�|��ddd�dS)zH
        When used as a descriptor, the observer is propagated.
        cseZdZe�jd�ZdS)z5LoggerTests.test_descriptorObserver.<locals>.MyObject�rN)rrrr�appendr!r�Zobservedrr�MyObjecttsr6�hello�r�
log_formatN)�objectr!�infor#�len)rr6rr5r�test_descriptorObserverns
z#LoggerTests.test_descriptorObservercCsRtd�}|j}|�d�|�d|j�|�|jd|�t|j�}|�d|�dS)z�
        On instances that have a L{Logger} class attribute, the C{log_source}
        key is available to format strings.
        r7zHello, {log_source}.�
log_sourcez!Hello, <LogComposedObject hello>.N)rr!�errorZassertInr
r#r)rr1r!Zstuffrrr�!test_sourceAvailableForFormatting|s

z-LoggerTests.test_sourceAvailableForFormattingcCs�t�}t��D]�}d}|j|jd�}t||j�}||||jd�|�|jd|�|�|jd|�|�|jdd|�|�t	|d�d	�|�|j
d
|�|�|j
d|�|�|j
dt�|�|j
d
�|�|j
d|�|�t
|j
�|�qdS)z]
        Test that log levels and messages are emitted correctly for
        Logger.
        zThis is a {level_name} message)�
level_name)�junkrArrrrBr
zNo event observed.r9�	log_level�
log_namespacer>N)r
rZ
iterconstantsr�name�getattrr#rZ
assertTrue�hasattrr
rr0r)rr!rr�messageZ	logMethodrrr�test_basicLogger�s zLoggerTests.test_basicLoggercs0��fdd��G�fdd�dt���j��dS)z>
        C{log_source} event key refers to the class.
        cs��|d��dS�Nr>�r#r)�Thingorrrr�sz0LoggerTests.test_sourceOnClass.<locals>.observercseZdZe�d�ZdS)z.LoggerTests.test_sourceOnClass.<locals>.Thingor3N�rrrr
r!rr3rrrL�srLN�r:r!r;rr)rLrrr�test_sourceOnClass�szLoggerTests.test_sourceOnClasscs6��fdd��G�fdd�dt�}|���j��dS)zA
        C{log_source} event key refers to the instance.
        cs��|d��dSrJrKr)r�thingorrr�sz3LoggerTests.test_sourceOnInstance.<locals>.observercseZdZe�d�ZdS)z1LoggerTests.test_sourceOnInstance.<locals>.Thingor3NrMrr3rrrL�srLNrN)rrLr)rrrPr�test_sourceOnInstance�sz!LoggerTests.test_sourceOnInstancecs"�fdd�}t|d�}|��dS)z5
        C{log_source} event key is L{None}.
        cs��|d�dSrJ)r0rrrrr�sz0LoggerTests.test_sourceUnbound.<locals>.observerr3N�r
r;)rrr!rrr�test_sourceUnbound�s
zLoggerTests.test_sourceUnboundcCsvt�}ztd��Wntk
r0|�d�YnX|�t�}|�t|�d�|�|jdtj�|�|jdd�dS)z?
        Test that log.failure() emits the right data.
        zbaloney!ZWhoopsr8rrN)	r
�RuntimeErrorZfailure�flushLoggedErrorsr#r<rrZcritical�rr!�errorsrrr�test_defaultFailure�s
zLoggerTests.test_defaultFailurecCsjt�}|jddtjddd�|�|jdd�|�|jdtj�|�|jd|j�|�|jd	�d
S)zQ
        Make sure that kwargs conflicting with args don't pass through.
        �*�#z*namespace*z*source*)r9rCrDr>r9rCrDr>N)r
�warnrr?r#r
r%r0r'rrr�test_conflictingKwargs�s�z"LoggerTests.test_conflictingKwargscCs.t�}|�d�|�t�}|�t|�d�dS)zA
        Test passing in a bogus log level to C{emit()}.
        z*bogus*r8N)r
rrUrr#r<rVrrr�test_logInvalidLogLevel�s

z#LoggerTests.test_logInvalidLogLevelcs8�fdd�����fdd��t�d���jdgd�dS)	zE
        Tracing keeps track of forwarding to the publisher.
        cs�|�dSrrrr3rr�	publishersz)LoggerTests.test_trace.<locals>.publishercs��|d��fg�dS)N�	log_tracerKr)r!r^rrrrsz(LoggerTests.test_trace.<locals>.observerr3zHello.)r_NrRrr)r!rr^rr�
test_traces
zLoggerTests.test_traceN)rrrrr&r(r-r2r=r@rIrOrQrSrXr\r]r`rrrrr"9s	
r"N)rZ
twisted.trialrZ_levelsrrZ_formatrZ_loggerrZ_globalr	r
r:rZTestCaser"rrrr�<module>s