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


W[,�@sjdZddlmZddlZddlmZddlmZddlm	Z	ddl
mZdd	lm
Z
Gd
d�dej�ZdS)z'
Test cases for L{twisted.logger._io}.
�)�print_functionN)�unittest�)�LogLevel)�Logger)�LogPublisher)�LoggingFilec@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,S)-�LoggingFileTestsz#
    Tests for L{LoggingFile}.
    cCst�|_t|jd�|_dS)zK
        Create a logger for test L{LoggingFile} instances to use.
        ��observerN)rZ	publisherr�logger��self�r�=/usr/lib/python3/dist-packages/twisted/logger/test/test_io.py�setUpszLoggingFileTests.setUpcCs|�tjd�dS)z0
        L{LoggingFile.softspace} is 0.
        rN)�assertEqualrZ	softspacer
rrr�test_softspace"szLoggingFileTests.test_softspacecCsjt|j�}|�tt|dd�|�tt|dd�|�tt|dd�|�tt|ddg�|�tt|d	d
�dS)z?
        Some L{LoggingFile} attributes are read-only.
        �closedT�encoding�utf-8�mode�r�newlines�
�nameZfooN)rr�assertRaises�AttributeError�setattr�r�frrr�test_readOnlyAttributes)s
z(LoggingFileTests.test_readOnlyAttributescCs~t|j�}|�t|j�|�t|j�|�t|j�|�t|j�|�t|j�|�t|j	�|�t|j
�|�t|j�dS)z>
        Some L{LoggingFile} methods are unsupported.
        N)rrr�IOError�read�next�readline�	readlinesZ
xreadlines�seek�tell�truncaterrrr�test_unsupportedMethods6s
z(LoggingFileTests.test_unsupportedMethodscCs>t|j�}|�|jtj�t|jtjd�}|�|jtj�dS)z?
        Default level is L{LogLevel.info} if not set.
        ��levelN)rrrr,r�info�errorrrrr�
test_levelFs
zLoggingFileTests.test_levelcCs<t|j�}|�|jt���t|jdd�}|�|jd�dS)zM
        Default encoding is C{sys.getdefaultencoding()} if not set.
        r�rN)rrrr�sys�getdefaultencodingrrrr�
test_encodingQs
zLoggingFileTests.test_encodingcCst|j�}|�|jd�dS)z*
        Reported mode is C{"w"}.
        �wN)rrrrrrrr�	test_mode\s
zLoggingFileTests.test_modecCst|j�}|�|j�dS)z7
        The C{newlines} attribute is L{None}.
        N)rrZassertIsNonerrrrr�
test_newlinesds
zLoggingFileTests.test_newlinescCst|j�}|�|jd�dS)z1
        The C{name} attribute is fixed.
        z.<LoggingFile twisted.logger.test.test_io#info>N)rrrrrrrr�	test_namels

�zLoggingFileTests.test_namecCs2t|j�}|��|�|j�|�t|jd�dS)z7
        L{LoggingFile.close} closes the file.
        �HelloN)rr�closeZ
assertTruerr�
ValueError�writerrrr�
test_closews
zLoggingFileTests.test_closecCst|j�}|��dS)z4
        L{LoggingFile.flush} does nothing.
        N)rr�flushrrrr�
test_flush�s
zLoggingFileTests.test_flushcCst|j�}|�|��d�dS)z6
        L{LoggingFile.fileno} returns C{-1}.
        ���N)rrr�filenorrrr�test_fileno�s
zLoggingFileTests.test_filenocCst|j�}|�|���dS)z9
        L{LoggingFile.isatty} returns C{False}.
        N)rrZassertFalse�isattyrrrr�test_isatty�s
zLoggingFileTests.test_isattycCs\|��}|�d�|�|jg�|�d�|�|jdg�|�d�|�|jdddg�dS)z,
        Writing buffers correctly.
        r8z	, world!
�
Hello, world!zIt's nice to meet you.

Indeed.�It's nice to meet you.�N��observedFiler;r�messagesrrrr�test_writeBuffering�s


��z$LoggingFileTests.test_writeBufferingcCs*|jdd�}|�d�|�|jdg�dS)z/
        Bytes are decoded to unicode.
        rr0sHello, Mr. Sánchez
�Hello, Mr. SánchezNrGrrrr�test_writeBytesDecoded�s
z'LoggingFileTests.test_writeBytesDecodedcCs*|jdd�}|�d�|�|jdg�dS)z(
        Unicode is unmodified.
        rr0uHello, Mr. Sánchez
rKNrGrrrr�test_writeUnicode�s
z"LoggingFileTests.test_writeUnicodecCs�|��}|�d�|�t|j�d�|�|jddtj�|jtjd�}|�d�|�t|j�d�|�|jddtj�dS)z0
        Log level is emitted properly.
        �Hello
�rZ	log_levelr+N)rHr;r�len�eventsrr-r.rrrr�test_writeLevel�s

z LoggingFileTests.test_writeLevelcCs>|��}|�d�|�t|j�d�|�|jddd�dS)z0
        Log format is C{u"{message}"}.
        rNrOrZ
log_formatz{log_io}N)rHr;rrPrQrrrr�test_writeFormat�s
z!LoggingFileTests.test_writeFormatcCs\|��}|�d�|�|jg�|�d�|�|jdg�|�d�|�|jdddg�dS)z6
        C{writelines} does not add newlines.
        )r8z, rF)zworld!
rD)zIt's nice to meet you.

zIndeed.rErFN)rH�
writelinesrrIrrrr�test_writelinesBuffering�s


��z)LoggingFileTests.test_writelinesBufferingcCs>|��}|�td|�tddd�td�|�|jdg�dS)z;
        L{LoggingFile} can replace L{sys.stdout}.
        �stdoutzHello,� )�endzworld.z
Hello, world.N)rHZpatchr1�printrrIrrrr�
test_print�s
zLoggingFileTests.test_printcs8�fdd�}t|d�}tfd|i|���g�_g�_�S)a�
        Construct a L{LoggingFile} with a built-in observer.

        @param kwargs: keyword arguments for the L{LoggingFile}.
        @type kwargs: L{dict}

        @return: a L{LoggingFile} with an observer that appends received
            events into the file's C{events} attribute (a L{list}) and
            event messages into the file's C{messages} attribute (a L{list}).
        @rtype: L{LoggingFile}
        cs(�j�|�d|kr$�j�|d�dS)NZlog_io)rQ�appendrI)Zevent�r rrrsz/LoggingFileTests.observedFile.<locals>.observerr
r)rrrQrI)r�kwargsr�logrr\rrH�s
zLoggingFileTests.observedFileN)�__name__�
__module__�__qualname__�__doc__rrr!r*r/r3r5r6r7r<r>rArCrJrLrMrRrSrUrZrHrrrrr	s,
		

r	)rbZ
__future__rr1Z
twisted.trialrZ_levelsrZ_loggerrZ	_observerr�_iorZTestCaser	rrrr�<module>s