File: //proc/self/root/lib/python3/dist-packages/twisted/test/__pycache__/test_logfile.cpython-38.pyc
U
W[3G � @ s� d dl mZmZ d dlZd dlZd dlZd dlZd dlZd dlm Z d dl
mZmZ G dd� de j
�ZG dd� dej�ZG d d
� d
e j
�ZdS )� )�division�absolute_importN)�unittest)�logfile�runtimec @ s� e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� Zdd
� Z dd� Z
dd� Zdd� Zdd� Z
dd� Zdd� Zdd� Zdd� Zdd� Zej�� r�d e_d!d"� Zd#d$� Zd%d&� Zd'd(� Zd)S )*�LogFileTestsz%
Test the rotating log file.
c C s4 | � � | _t�| j� d| _tj�| j| j�| _d S )Nztest.log�Zmktemp�dir�os�makedirs�name�path�join��self� r �;/usr/lib/python3/dist-packages/twisted/test/test_logfile.py�setUp s
zLogFileTests.setUpc C s. t �| jd� t j�| j�r*t �| jd� dS )z�
Restore back write rights on created paths: if tests modified the
rights, that will allow the paths to be removed easily afterwards.
� N)r
�chmodr r
�existsr r r r �tearDown s zLogFileTests.tearDownc C s. t �| j| j�}| �|j� | �t|j� dS )zf
L{BaseLogFile.shouldRotate} is abstract and must be implemented by
subclass.
N) r ZBaseLogFiler r �
addCleanup�close�assertRaises�NotImplementedErrorZshouldRotate�r �logr r r �test_abstractShouldRotate% s z&LogFileTests.test_abstractShouldRotatec C sr t �t�| j| j���,}|�d� |�d� |�� |�d� W 5 Q R X t| j ��}| �
|�� d� W 5 Q R X dS )zn
Log files can be written to, flushed and closed. Closing a log file
also flushes it.
�123�456�7890�
1234567890N)�
contextlib�closingr �LogFiler r �write�flush�openr
�assertEqual�read�r r �fr r r �test_writing/ s
zLogFileTests.test_writingc C sL t �tj| j| jdd����}|�d� |�d� |�d� | �tj �
d�| j ��� | �tj �
d�| j ��� |�d� | �tj �
d�| j ��� | �tj �
d�| j ��� | �tj �
d �| j ��� |�d
� | �tj �
d �| j ��� |�
� | �tj �
d �| j ��� | �tj �
d�| j ��� W 5 Q R X | �|�� dd
dg� dS )zq
Rotating log files autorotate after a period of time, and can also be
manually rotated.
�
)�rotateLengthr �4567890�11111111111�{0}.1�{0}.2� �{0}.3�3�{0}.4� � � N)r# r$ r r% r r r&