Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_logging.cpython-38.opt-1.pyc
U

>��g���@s&dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZddlmZddlZddlZddlZddlZddlZddl Z ddl!Z!ddl"m#Z#m$Z$ddl%Z%ddl&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-zddl.Z.ddl/Z/ddl0Z0Wn"e1k
�r~dZ.Z/Z0YnXzddl2Z2Wne1k
�r�YnXGdd	�d	ej3�Z4Gd
d�de4�Z5Gdd
�d
e4�Z6dZ7dZ8dZ9dZ:dZ;dZ<dZ=dZ>dZ?dZ@eAe@e7d�ZBe7de8de9de:de;de<de=de>d e?d!e@d"i
ZCGd#d$�d$ejD�ZEGd%d&�d&ejD�ZFGd'd(�d(e4�ZGGd)d*�d*e4�ZHGd+d,�d,eI�ZJGd-d.�d.ejK�ZLGd/d0�d0eI�ZMGd1d2�d2e4�ZNGd3d4�d4e%jO�ZPGd5d6�d6eI�ZQGd7d8�d8eQe#�ZRGd9d:�d:eQe,�ZSGd;d<�d<eQe*�ZTeUed=��rBGd>d?�d?eS�ZVGd@dA�dAeT�ZWGdBdC�dCe4�ZXGdDdE�dEe4�ZYGdFdG�dGejZ�Z[GdHdI�dIe4�Z\GdJdK�dKe4�Z]dLdM�Z^e�_eUed=�dN�GdOdP�dPe]��Z`GdQdR�dRe4�Zae�_eUed=�dN�GdSdT�dTea��ZbGdUdV�dVe4�Zce�_eUed=�dN�GdWdX�dXec��Zde�_ejedY�GdZd[�d[ec��ZfGd\d]�d]e4�ZgGd^d_�d_e4�ZhGd`da�dae4�ZiGdbdc�dce4�Zjd�ddde�ZkGdfdg�dg�Zldhdi�ZmGdjdk�dkejK�ZnGdldm�dme4�ZoGdndo�doe4�ZpGdpdq�dqe4�ZqGdrds�dsejr�ZsGdtdu�due4�ZtGdvdw�dwe4�ZueUejvdx��rFddlwZwddylxmyZyGdzd{�d{e4�Zze�{d�Z|Gd|d}�d}ej}�Z~e~�ZGd~d�dej3�Z�Gd�d��d�ej��Z�Gd�d��d�ej3�Z�Gd�d��d�e4�Z�Gd�d��d�e4�Z�Gd�d��d��Z�Gd�d��d�ej��Z�Gd�d��d�e4�Z�Gd�d��d�e4�Z�Gd�d��d�e4�Z�Gd�d��d�ej3�Z�Gd�d��d�ej3�Z�Gd�d��d�e4�Z�Gd�d��d�e4�Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�d�d��Z�d�d�d�d�d�d�e�d�d�d��ffD](\Z�Z�e�e�fd�d��Z�e�e�d�e�e���q�e�_e.d��Gd�d��d�e4��Z�Gd�d��d�ej3�Z�e��d�d��d�d���Z�e�d�k�r"e��dS)�zoTest harness for the logging module. Run all tests.

Copyright (C) 2001-2017 Vinay Sajip. All Rights Reserved.
�N)�assert_python_ok�assert_python_failure)�support)�
HTTPServer�BaseHTTPRequestHandler)�urlparse�parse_qs)�ThreadingUDPServer�DatagramRequestHandler�ThreadingTCPServer�StreamRequestHandlerc@s>eZdZdZdZdZdZdd�Zdd�Zdd
d�Z	dd
�Z
d	S)�BaseTestzBase class for logging tests.z&%(name)s -> %(levelname)s: %(message)sz^([\w.]+) -> (\w+): (\d+)$rcCs�t��|_t��jj}t��zntj	�
�|_tjdd�|_
|�
�|_}tj�
�|_tj�
�|_i|_}|D]}t||dd�||<qpW5t��Xt�d�|_t�d�|_t�d�|_|j��|_t��|_|j�tj�t�|j�|_ t�!|j"�|_#|j �$|j#�|j�%��r2|jj&|jj&}t'd|��|j�%��rZ|jj&|jj&}t'd|��|j�(|j �|�)|j�%��|�)|j�%��dS)zxSetup the default logging stream to an internal StringIO instance,
        so that we can examine log output as we want.N�disabledu«×»uĿÖG�zUnexpected handlers: %s)*rZthreading_setup�_threading_key�logging�	getLogger�manager�
loggerDict�_acquireLock�_releaseLock�	_handlers�copy�saved_handlers�_handlerList�saved_handler_list�
saved_loggers�_nameToLevel�saved_name_to_level�_levelToName�saved_level_to_name�
logger_states�getattr�logger1�logger2�root_logger�getEffectiveLevel�original_logging_level�io�StringIO�stream�setLevel�DEBUG�
StreamHandler�	root_hdlr�	Formatter�
log_format�root_formatter�setFormatter�hasHandlers�handlers�AssertionError�
addHandler�
assertTrue)�selfZlogger_dictrr!�nameZhlist�r:�0/opt/cppython/lib/python3.8/test/test_logging.py�setUpNsD

�

zBaseTest.setUpcCs0|j��|j�|j�|jjrB|jjd}|j�|�|��q|j�|j�t�	�z�tj��tj�
|j�tj��tj�
|j�tj��tj�
|j�|jtjdd�<t��j}d|_|j}|��|�
|j�|j}|jD] }||dk	r�|||j|_q�W5t�
�X|��tj|j�dS)zJRemove our logging stream, and restore the original logging
        level.rN) r*�closer%�
removeHandlerr.r4r+r'rrrr�clear�updater rrrrrrrr�disablerrr!rZ
doCleanupsrZthreading_cleanupr)r8�hrrr!r9r:r:r;�tearDownxs8







zBaseTest.tearDownNc	Cs�|p|j}t�|p|j�}|����}|�t|�t|��t||�D]8\}}|�	|�}|sh|�
d|�|�t|���|�qD|�
�}|r�|�
d|�dS)z�Match the collected log lines against the regular expression
        self.expected_log_pat, and compare the extracted group values to
        the expected_values list of tuples.z*Log line does not match expected pattern:
z'Remaining output at end of log stream:
N)r*�re�compile�expected_log_pat�getvalue�
splitlines�assertEqual�len�zip�search�fail�tuple�groups�read)	r8Zexpected_valuesr*�patZactual_lines�actual�expected�match�sr:r:r;�assert_log_lines�s

�zBaseTest.assert_log_linescCs|jd7_d|jS)zMGenerate a message consisting solely of an auto-incrementing
        integer.�z%d)�message_num�r8r:r:r;�next_message�szBaseTest.next_message)NN)�__name__�
__module__�__qualname__�__doc__r0rFrXr<rCrVrZr:r:r:r;r
Fs*"
r
c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�BuiltinLevelsTestz*Test builtin levels and their inheritance.c
Cs4|j}t�d�}|�tj�t�t�d�i�}|�tj�t�d�}|�tj�|�tj	|��|�
|��|�tj	|��|�
|��|�|��|�|��|�tj	|��|�
|��|�|��|�|��|�
|��|�|��|�|��|�
|��|�
|��|�dddddd	d
ddd
dg�dS)N�ERR�INF�DEB)r`�CRITICAL�1)r`�ERROR�2)rarc�3)rare�4)ra�WARNING�5)ra�INFO�6)rbrc�7)rbre�8)rbri�9)rbrk�10)rbr,�11)rZrrr+re�
LoggerAdapterrkr,�logrc�error�warning�info�debugrV)r8�mr`rarbr:r:r;�	test_flat�sF

�zBuiltinLevelsTest.test_flatcCs�|j}t�d�}|�tj�t�d�}|�tj�|�tj|��|�|��|�	|��|�
|��|�|��|�ddg�dS)Nra�INF.ERR)rzrcrd)rzrerf�
rZrrr+rkrersrcrtrurvrwrV)r8rxra�INF_ERRr:r:r;�test_nested_explicit�s

�z&BuiltinLevelsTest.test_nested_explicitcCs�|j}t�d�}|�tj�t�d�}|�tj�t�d�}t�d�}t�d�}|�tj|��|�|��|�	|��|�
|��|�tj|��|�|��|�|��|�	|��|�
|��|�|��|�dddd	d
dg�dS)Nrarz�	INF.UNDEF�
INF.ERR.UNDEF�UNDEF)r~rcrd)r~rerf)r~rirg)r~rkrh)rrcrj)rrerlr{)r8rxrar|Z	INF_UNDEFZ
INF_ERR_UNDEFr�r:r:r;�test_nested_inherited�s4




�z'BuiltinLevelsTest.test_nested_inheritedcCs�|j}t�d�}t�d�}t�d�}|�tj�|�tj|��|�|��|�tj|��|�|��|�|��|�|��|�	ddddg�dS)Nra�INF.BADPARENT.UNDEF�
INF.BADPARENT)r�rcrd)r�rkrf)r�rcrg)r�rkrh)
rZrrr+rkrs�FATALrvrwrV)r8rxraZ
GRANDCHILDZCHILDr:r:r;�test_nested_with_virtual_parents"


�z1BuiltinLevelsTest.test_nested_with_virtual_parentcCs,|�t�d�tj�|�t�tj�d�dS)z&See issue #22386 for more information.rkN)rIr�getLevelNamerkrYr:r:r;�test_regression_223869sz'BuiltinLevelsTest.test_regression_22386cCst�d�}|�|tj�dS)Nr�)rr�rIr�)r8�fatalr:r:r;�test_issue27935>s
z!BuiltinLevelsTest.test_issue27935cCs`t�tjd�|�tjtjd�|�t�tj�d�|�t�tj�d�|�t�d�tj�dS)z&See issue #29220 for more information.rrk�NOTSETN)r�addLevelNamerk�
addCleanuprIr�r�rYr:r:r;�test_regression_29220Bs
z'BuiltinLevelsTest.test_regression_29220N)r[r\r]r^ryr}r�r�r�r�r�r:r:r:r;r_�s/#r_c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�BasicFilterTestzTest the bundled Filter class.c	Cs�t�d�}|jjd}z||�|�t�d�}t�d�}t�d�}t�d�}|�|���|�|���|�|���|�|���|�	ddg�W5|�|�XdS)N�	spam.eggsr�spam�spam.eggs.fish�spam.bakedbeans�r�rkrf�r�rkrg)
r�Filterr%r4�removeFilter�	addFilterrrvrZrV)r8Zfilter_�handlerr��	spam_eggs�spam_eggs_fish�spam_bakedbeansr:r:r;�test_filterNs"





�
zBasicFilterTest.test_filterc	Cs�dd�}|jjd}z||�|�t�d�}t�d�}t�d�}t�d�}|�|���|�|���|�|���|�|���|�dd	g�W5|�|�XdS)
NcSs&|j�d�}d�|dd��}|dkS)N�.�r�)r9�split�join)�record�parts�prefixr:r:r;�
filterfuncjsz8BasicFilterTest.test_callable_filter.<locals>.filterfuncrr�r�r�r�r�r�)	r%r4r�r�rrrvrZrV)r8r�r�r�r�r�r�r:r:r;�test_callable_filterfs"




�
z$BasicFilterTest.test_callable_filtercCs*t��}t�ddi�}|�|�|��dS)Nr9r�)rr��
makeLogRecordr7�filter)r8�f�rr:r:r;�test_empty_filter�sz!BasicFilterTest.test_empty_filterN)r[r\r]r^r�r�r�r:r:r:r;r�Jsr��x�w�v�u�t�s�r�q�p�orW�Silent�Taciturn�Terse�Effusive�Sociable�Verbose�	TalkativeZ	Garrulous�
Chatterbox�Boringc@seZdZdZdd�ZdS)�GarrulousFilterz)A filter which blocks garrulous messages.cCs
|jtkS�N)�levelno�	GARRULOUS�r8r�r:r:r;r��szGarrulousFilter.filterN�r[r\r]r^r�r:r:r:r;r��sr�c@seZdZdZdd�ZdS)�VerySpecificFilterz5A filter which blocks sociable and taciturn messages.cCs|jttfkSr�)r��SOCIABLE�TACITURNr�r:r:r;r��szVerySpecificFilter.filterNr�r:r:r:r;r��sr�c@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�CustomLevelsAndFiltersTestz@Test various filtering possibilities with custom logging levels.�^[\w.]+ -> (\w+): (\d+)$cCs,t�|�t��D]\}}t�||�qdSr�)r
r<�my_logging_levels�itemsrr�)r8�k�vr:r:r;r<�s
z CustomLevelsAndFiltersTest.setUpcCstD]}|�||���qdSr�)�LEVEL_RANGErsrZ)r8�loggerZlvlr:r:r;�log_at_all_levels�sz,CustomLevelsAndFiltersTest.log_at_all_levelscCs2|j�t�|�|j�|�ddddddg�dS)N�r�rj�r�rl�r�rm�r�rn�r�ro�r�rp)r%r+�VERBOSEr�rVrYr:r:r;�test_logger_filter�s�z-CustomLevelsAndFiltersTest.test_logger_filterc	CsR|jjd�t�z$|�|j�|�dddddg�W5|jjd�tj�XdS)Nrr�r�r�r�r�)r%r4r+r�rr�r�rVrYr:r:r;�test_handler_filter�s�
z.CustomLevelsAndFiltersTest.test_handler_filterc
Cs�|jjd}d}t�}|�|�zj|�|j�dddddddd	d
g	}|�|�t�}|j�|�|�|j�|�|ddd
ddddg�W5|r�|j�|�|�|�XdS)Nr)r�rd)r�rf)r�rhr�r�r�r�r�r�)r�rq)r�Z12)r�Z14)r�Z15)r�Z17)r�Z18)r�Z20)r%r4r�r�r�r�rVr�)r8r�Zspecific_filterZgarrZfirst_linesr:r:r;�test_specific_filters�s@
�
�z0CustomLevelsAndFiltersTest.test_specific_filtersN)
r[r\r]r^rFr<r�r�r�r�r:r:r:r;r��sr�c@sZeZdZdd�Zdd�Zdd�Ze�ej	dkd�d	d
��Z
e�eed�d�d
d��ZdS)�HandlerTestcCsDt��}d|_|�|jd�d|_|�|jd�|�t|jd�dS)N�genericZanothergeneric)r�Handlerr9rI�assertRaises�NotImplementedError�emit�r8rBr:r:r;�	test_nameszHandlerTest.test_namec
Cs�tjdk�rZdD]�}t��\}}t�|�|s8t�|�tjj	|dd�}|r�|j
|j}}|�|d�|�|d�t�
ddi�}|�|�t�|�|�tj�|��|�|�|�tj�|��n|�|j
d�|�|jd�|��|rt�|�qtjdk�r
d	}nd
}z4tj�|�}|�|j|j�|�|j�|��Wntk
�rXYnXdD]@}	|	dk�r�|�ttjjd
d|	�ntj�d
d|	�}|���q^tj�d�}t�
i�}|�|�|��|��tj�d�}|�|�|��|��dS)N��linux�darwin)TFT��delay����msgZTestr�z/var/run/syslogz/dev/log)�GET�POST�PUTr��	localhostz/logrrW)�sys�platform�tempfile�mkstemp�osr=�unlinkrr4�WatchedFileHandler�dev�inorIr��handle�assertFalse�path�existsr7�
SysLogHandlerZfacilityZLOG_USERZ
unixsocket�OSErrorr��
ValueError�HTTPHandlerZBufferingHandlerZshouldFlush)
r8Zexisting�fd�fnrBr�r�r�Zsockname�methodr:r:r;�test_builtin_handlerss`





�
z!HandlerTest.test_builtin_handlerscCs�t��\}}t�|�t�|�t�|�}tj|dfftj	j
|dfftj	j|dfff}tj
dkrv|tj	j|dfff7}|D]4\}}||�}|�tj�|��|��t�|�qzdS)zs
        Test that Path objects are accepted as filename arguments to handlers.

        See Issue #27493.
        �w�arBr�N)r�r�r�r=r��pathlib�Pathr�FileHandlerr4�RotatingFileHandler�TimedRotatingFileHandlerr�r�r�r7r�r�)r8r�r�ZpfnZcases�cls�argsrBr:r:r;�test_path_objectsUs


�
zHandlerTest.test_path_objects�ntz/WatchedFileHandler not appropriate for Windows.c
s&�fdd�}d}d}d�_d�_dD]�}t�dd�\}}t�|�tj|||fd�}d|_|�	�t
jj||d	�}t
�
d
�}	|�|	�znt|�D]`}
t�d�t
�dd
i�}zt���_|�|�Wq�tk
r�td�j�jf��Yq�Xq�W5|��|��tj�|��rt�|�Xq$dS)Nc	sVt|�D]H}zt�|�t���_Wntk
r8YnXt�dt�dd��qdS)Ng����Mbp?r�)	�ranger�r��time�
deletion_timer��sleep�random�randint)ZfnameZtries�_rYr:r;�remove_loopos
z*HandlerTest.test_race.<locals>.remove_loopi��FT�.logztest_logging-3-��targetr
Tr�z'%(asctime)s: %(levelname)s: %(message)s�{�G�zt?r�ZtestingzDeleted at %s, opened at %s)Zhandle_timerr�r�r�r=�	threading�Thread�daemon�startrr4r�r/r2r�r�r�r�rrrr�r��	Exception�print)r8rZ	del_countZ	log_countr�r�r�ZremoverrBr�rr�r:rYr;�	test_racels@	




��zHandlerTest.test_race�forkzTest requires os.fork().c		s�Gdd�dtj�}|�ttj�d�|��|��jjj�d�_	|�
ttj�d�|�
ttj�d�t�d�}|�
��|�tj�t���t������fdd�}tj|d	d
�}|�����t��}|dkr�z|�d�W5t�d�Xn�|�d����|��t��}|�d
�t�|tj�\}}||k�r<�q`t��|dk�rR�q`t� d��q|�d�||k�r�t�!|t"j#�t�|d�\}}|�$d�|j|ddd�dS)z>Ensure child logging locks are not held; bpo-6721 & bpo-36533.cs$eZdZ�fdd�Zdd�Z�ZS)zAHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandlercs"t���tjtdd�d�|_dS)Nz	/dev/nullZwt�r*)�super�__init__rr-�open�sub_handlerrY��	__class__r:r;r%�s
�zJHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.__init__cSs,|j��z|j�|�W5|j��XdSr�)r'�acquire�releaser�r�r:r:r;r��s
zFHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.emit�r[r\r]r%r��
__classcell__r:r:r(r;�_OurHandler�sr.rz*because we need at least one for this testrW� test_post_fork_child_no_deadlockcsFt��z.���z�����d�W5���XW5t��XdS)N��?)rrrr*r+�set�waitr:�Z+fork_happened__release_locks_and_end_threadZlocks_held__ready_to_forkZrefed_hr:r;�lock_holder_thread_fn�s
zKHandlerTest.test_post_fork_child_no_deadlock.<locals>.lock_holder_thread_fnz,test_post_fork_child_no_deadlock lock holder)rr9z#Child process did not deadlock. \o/z&Parent process returned from fork. \o/zWaiting for child process.�g�������?z
Done waiting.zchild process deadlocked.zchild process error�r�N)%rr�rIrJrr�r'r*r=r9�
assertGreater�_at_fork_reinit_lock_weaksetrr6r+r,r�Eventrrr2r�r"�_exitrvr1r�r�	monotonicrw�waitpid�WNOHANGr�kill�signal�SIGKILLrM)	r8r.Ztest_loggerr4Zlock_holder_thread�pidZ
start_timeZ
waited_pid�statusr:r3r;r/�sR


�





z,HandlerTest.test_post_fork_child_no_deadlockN)
r[r\r]r�rr�unittestZskipIfr�r9r!�hasattrr/r:r:r:r;r�s6
0r�c@seZdZdd�ZdS)�	BadStreamcCstd��dS)N�deliberate mistake)�RuntimeError�r8�datar:r:r;�write�szBadStream.writeN)r[r\r]rJr:r:r:r;rE�srEc@seZdZdd�ZdS)�TestStreamHandlercCs
||_dSr�)�error_recordr�r:r:r;�handleError�szTestStreamHandler.handleErrorN)r[r\r]rMr:r:r:r;rK�srKc@seZdZejZdZdS)�StreamWithIntNamer�N)r[r\r]rr��levelr9r:r:r:r;rN�srNc@s$eZdZdd�Zdd�Zdd�ZdS)�StreamHandlerTestc	Cs�tt��}t�i�}tj}z�|�|�|�|j|�t�t��}t	�
��$}|�|�d}|�||���W5QRXdt_t	�
�� }|�|�|�
d|���W5QRXW5|t_XdS)Nz"
RuntimeError: deliberate mistake
Fr)rKrErr��raiseExceptionsr��assertIsrLr-r�captured_stderr�assertInrGrI)r8rBr�Z	old_raise�stderrr�r:r:r;�test_error_handlings 






z%StreamHandlerTest.test_error_handlingcCsVt��}t��}|�|�}|�|tj�|�|�}|�||�|�|�}|�|�dS)z3
        Test setting the handler's stream
        N)	rr-r(r)�	setStreamrRr�rU�assertIsNone)r8rBr*�oldrRr:r:r;�test_stream_settings


z%StreamHandlerTest.test_stream_settingcCs t�t��}|�t|�d�dS)Nz<StreamHandler 2 (NOTSET)>)rr-rNrI�reprr�r:r:r;�'test_can_represent_stream_with_int_name%sz9StreamHandlerTest.test_can_represent_stream_with_int_nameN)r[r\r]rVrZr\r:r:r:r;rPsrPc@s:eZdZdZdd�Zdd�Zdd�Zdd	�Zd
dd�Zd
S)�TestSMTPServera
    This class implements a test SMTP server.

    :param addr: A (host, port) tuple which the server listens on.
                 You can specify a port value of zero: the server's
                 *port* attribute will hold the actual port number
                 used, which can be used in client connections.
    :param handler: A callable which will be called to process
                    incoming messages. The handler will be passed
                    the client address tuple, who the message is from,
                    a list of recipients and the message data.
    :param poll_interval: The interval, in seconds, used in the underlying
                          :func:`select` or :func:`poll` call by
                          :func:`asyncore.loop`.
    :param sockmap: A dictionary which will be used to hold
                    :class:`asyncore.dispatcher` instances used by
                    :func:`asyncore.loop`. This avoids changing the
                    :mod:`asyncore` module's global state.
    cCsBtjj||d|dd�|j��d|_||_d|_d|_||_	dS)NT)�mapZdecode_datarWF)
�smtpd�
SMTPServerr%�socket�getsockname�port�_handler�_thread�_quit�
poll_interval)r8�addrr�rg�sockmapr:r:r;r%As�zTestSMTPServer.__init__cCs|�||||�dS)aI
        Delegates to the handler passed in to the server's constructor.

        Typically, this will be a test case method.
        :param peer: The client (host, port) tuple.
        :param mailfrom: The address of the sender.
        :param rcpttos: The addresses of the recipients.
        :param data: The message.
        N)rd)r8�peer�mailfrom�rcpttosrIr:r:r;�process_messageJs
zTestSMTPServer.process_messagecCs0tj|j|jfd�|_}|�d�|��dS)zG
        Start the server running on a separate daemon thread.
        rTN�rr�
serve_foreverrgre�	setDaemonr�r8�tr:r:r;rVs
�
zTestSMTPServer.startcCs|jstj||jdd�qdS)a*
        Run the :mod:`asyncore` loop until normal termination
        conditions arise.
        :param poll_interval: The interval, in seconds, used in the underlying
                              :func:`select` or :func:`poll` call by
                              :func:`asyncore.loop`.
        rW)r^�countN)rf�asyncoreZloop�_map�r8rgr:r:r;ro_szTestSMTPServer.serve_foreverNcCs6d|_t�|j|�d|_|��tj|jdd�dS)z�
        Stop the thread by closing the server instance.
        Wait for the server thread to terminate.

        :param timeout: How long to wait for the server thread
                        to terminate.
        TN)r^Z
ignore_all)rfr�join_threadrer=rtZ	close_allru�r8�timeoutr:r:r;�stopjs
zTestSMTPServer.stop)N)	r[r\r]r^r%rmrrorzr:r:r:r;r],s		r]cs:eZdZdZdd�Zdd�Z�fdd�Zdd	d
�Z�ZS)�ControlMixina

    This mixin is used to start a server on a separate thread, and
    shut it down programmatically. Request handling is simplified - instead
    of needing to derive a suitable RequestHandler subclass, you just
    provide a callable which will be passed each received request to be
    processed.

    :param handler: A handler callable which will be called with a
                    single parameter - the request - in order to
                    process the request. This handler is called on the
                    server thread, effectively meaning that requests are
                    processed serially. While not quite Web scale ;-),
                    this should be fine for testing applications.
    :param poll_interval: The polling interval in seconds.
    cCs d|_||_||_t��|_dSr�)rergrdrr9�ready)r8r�rgr:r:r;r%�szControlMixin.__init__cCs0tj|j|jfd�|_}|�d�|��dS)zI
        Create a daemon thread to run the server, and start it.
        rTNrnrqr:r:r;r�s
�
zControlMixin.startcs|j��tt|��|�dS)z^
        Run the server. Set the ready flag before entering the
        service loop.
        N)r|r1r$r{rorvr(r:r;ro�s
zControlMixin.serve_foreverNcCs<|��|jdk	r&t�|j|�d|_|��|j��dS)z�
        Tell the server thread to stop, and wait for it to do so.

        :param timeout: How long to wait for the server thread
                        to terminate.
        N)�shutdownrerrw�server_closer|r?rxr:r:r;rz�s
zControlMixin.stop)N)	r[r\r]r^r%rrorzr-r:r:r(r;r{ys
	r{c@s"eZdZdZd	dd�Zdd�ZdS)
�TestHTTPServera�
    An HTTP server which is controllable using :class:`ControlMixin`.

    :param addr: A tuple with the IP address and port to listen on.
    :param handler: A handler callable which will be called with a
                    single parameter - the request - in order to
                    process the request.
    :param poll_interval: The polling interval in seconds.
    :param log: Pass ``True`` to enable log messages.
    r0FNcs<G��fdd�dt��t�||��t�|||�||_dS)Ncs2eZdZddd�Zdd�Z���fdd�Z�ZS)	z=TestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandlerNcSs|�d�r|jSt|��dS)NZdo_)�
startswith�process_request�AttributeError)r8r9�defaultr:r:r;�__getattr__�s
zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.__getattr__cSs|j�|�dSr���serverrdrYr:r:r;r��szMTestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.process_requestcs�rt�|�j|f|��dSr�)r$�log_message)r8�formatr
)�DelegatingHTTPRequestHandlerr)rsr:r;r��s���zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.log_message)N)r[r\r]r�r�r�r-r:�r�rsr(r;r��s
r�)rrr%r{�sslctx)r8rhr�rgrsr�r:r�r;r%�s
zTestHTTPServer.__init__c
Csfz(|j��\}}|jr&|jj|dd�}Wn4tk
r\}ztj�d|��W5d}~XYnX||fS)NT)Zserver_sidezGot an error:
%s
)ra�acceptr�Zwrap_socketr�r�rUrJ)r8�sockrh�er:r:r;�get_request�szTestHTTPServer.get_request)r0FN)r[r\r]r^r%r�r:r:r:r;r�s
�
rcs.eZdZdZdZddd�Z�fdd�Z�ZS)	�
TestTCPServera�
    A TCP server which is controllable using :class:`ControlMixin`.

    :param addr: A tuple with the IP address and port to listen on.
    :param handler: A handler callable which will be called with a single
                    parameter - the request - in order to process the request.
    :param poll_interval: The polling interval in seconds.
    :bind_and_activate: If True (the default), binds the server and starts it
                        listening. If False, you need to call
                        :meth:`server_bind` and :meth:`server_activate` at
                        some later time before calling :meth:`start`, so that
                        the server will set up the socket and listen on it.
    Tr0cCs2Gdd�dt�}t�||||�t�|||�dS)Nc@seZdZdd�ZdS)z;TestTCPServer.__init__.<locals>.DelegatingTCPRequestHandlercSs|j�|�dSr�r�rYr:r:r;r��szBTestTCPServer.__init__.<locals>.DelegatingTCPRequestHandler.handleN)r[r\r]r�r:r:r:r;�DelegatingTCPRequestHandler�sr�)rrr%r{)r8rhr�rg�bind_and_activater�r:r:r;r%�s

�zTestTCPServer.__init__cs"tt|���|j��d|_dS�NrW)r$r��server_bindrarbrcrYr(r:r;r��szTestTCPServer.server_bind)r0T)r[r\r]r^Zallow_reuse_addressr%r�r-r:r:r(r;r��s�

r�cs6eZdZdZd
dd�Z�fdd�Z�fdd	�Z�ZS)�
TestUDPServera0
    A UDP server which is controllable using :class:`ControlMixin`.

    :param addr: A tuple with the IP address and port to listen on.
    :param handler: A handler callable which will be called with a
                    single parameter - the request - in order to
                    process the request.
    :param poll_interval: The polling interval for shutdown requests,
                          in seconds.
    :bind_and_activate: If True (the default), binds the server and
                        starts it listening. If False, you need to
                        call :meth:`server_bind` and
                        :meth:`server_activate` at some later time
                        before calling :meth:`start`, so that the server will
                        set up the socket and listen on it.
    r0Tcs<G�fdd�dt��t�||�|�t�|||�d|_dS)Ncs&eZdZdd�Z��fdd�Z�ZS)z;TestUDPServer.__init__.<locals>.DelegatingUDPRequestHandlercSs|j�|�dSr�r�rYr:r:r;r�szBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.handlecsD|j��}|r@zt�|���Wntk
r>|jjs:�YnXdSr�)ZwfilerGr$�finishr�r��_closedrH)�DelegatingUDPRequestHandlerr)r:r;r�s
zBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.finish)r[r\r]r�r�r-r:�r�r(r;r�	sr�F)r
r	r%r{r�)r8rhr�rgr�r:r�r;r%s�zTestUDPServer.__init__cs"tt|���|j��d|_dSr�)r$r�r�rarbrcrYr(r:r;r�szTestUDPServer.server_bindcstt|���d|_dS)NT)r$r�r~r�rYr(r:r;r~!szTestUDPServer.server_close)r0T)r[r\r]r^r%r�r~r-r:r:r(r;r��s�
r��AF_UNIXc@seZdZejZdS)�TestUnixStreamServerN�r[r\r]rar��address_familyr:r:r:r;r�&sr�c@seZdZejZdS)�TestUnixDatagramServerNr�r:r:r:r;r�)sr�c@s eZdZdZdd�Zdd�ZdS)�SMTPHandlerTestgN@c
Cs
i}ttjdf|jd|�}|��tj|jf}tjj|ddd|j	d�}|�
|jdg�g|_t�
ddi�}t��|_|�|�|j�|j	�|��|�|j���|�
t|j�d	�|jd\}}}}	|�
|d�|�
|dg�|�d
|	�|�|	�d��|��dS)Nr���MbP?�meZyouZLog)ryr�u	Hello ✓rWz
Subject: Log
u

Hello ✓)r]rZHOSTrmrrcrr4ZSMTPHandler�TIMEOUTrIZtoaddrs�messagesr�rr9�handledr�r2rzr7�is_setrJrT�endswithr=)
r8rir�rhrBr�rjrkrlrIr:r:r;�
test_basic2s0��

zSMTPHandlerTest.test_basiccGs|j�|�|j��dSr�)r��appendr�r1)r8r
r:r:r;rmJszSMTPHandlerTest.process_messageN)r[r\r]r�r�rmr:r:r:r;r�.sr�c@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�MemoryHandlerTestzTests for the MemoryHandler.r�cCsFt�|�tj�dtj|j�|_t�d�|_	d|j	_
|j	�|j�dS)N�
Zmemr)r
r<rr4�
MemoryHandlerrir.�mem_hdlrr�
mem_logger�	propagater6rYr:r:r;r<Us
�zMemoryHandlerTest.setUpcCs|j��t�|�dSr�)r�r=r
rCrYr:r:r;rC]s
zMemoryHandlerTest.tearDowncCs�|j�|���|�g�|j�|���|�g�|j�|���dddg}|�|�dD]b}td�D]}|j�|���qh|�|�|j�|���|dd�t||d�D�}|�|�q\|j�|���|�|�dS)	N�r,rd�rkrf)rirg)r
��	cSsg|]}dt|�f�qS)r,)�str)�.0�ir:r:r;�
<listcomp>wsz0MemoryHandlerTest.test_flush.<locals>.<listcomp>r�)r�rwrZrVrvrur)r8�lines�nr�r:r:r;�
test_flushas&

�

zMemoryHandlerTest.test_flushcCs�|j�|���|�g�|j�|���|�g�|j�|j�|j��ddg}|�|�tj	�
dtj|jd�|_|j�
|j�|j�|���|�|�|j�|���|�|�|j�|j�|j��|�|�dS)zO
        Test that the flush-on-close configuration works as expected.
        r�r�r�FN)r�rwrZrVrvr>r�r=rr4r�rir.r6)r8r�r:r:r;�test_flush_on_close}s,


�
�


z%MemoryHandlerTest.test_flush_on_closec
CsvGdd�d�}||j�}z@|j�|�td�D]&}t�d�|j�	d�|j�
d�q.W5|jD]}t�|�q`XdS)Nc@s$eZdZdd�Zdd�Zdd�ZdS)zZMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandlercSs||_g|_dSr�)r��threads)r8r�r:r:r;r%�szcMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.__init__cSs|j�d�dSr�)r��	setTargetrYr:r:r;�removeTarget�szgMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.removeTargetcSs&tj|jd�}|j�|�|��dS)N)r)rrr�r�r�r)r8r��threadr:r:r;r��szaMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.handleN)r[r\r]r%r�r�r:r:r:r;�MockRaceConditionHandler�sr�r�rznot flushedZflushed)r�r�rrwr�rrrr�rvru)r8r�rr�rr:r:r;�&test_race_between_set_target_and_flush�s


z8MemoryHandlerTest.test_race_between_set_target_and_flushN)
r[r\r]r^rFr<rCr�r�r�r:r:r:r;r�Nsr�c@seZdZdZdd�ZdS)�ExceptionFormatterzA special exception formatter.cCsd|djS)Nz
Got a [%s]r)r[)r8�eir:r:r;�formatException�sz"ExceptionFormatter.formatExceptionN)r[r\r]r^r�r:r:r:r;r��sr�c@s�eZdZdZejZdZdZdZdZ	e�
dd�Ze�
dd	�Zd
edZ
e�
dd
�ZdZdZdZdZdd�Zdd�Zdd�Zefdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,S)-�ConfigFileTestz5Reading logging config from a .ini-style config file.�^(\w+) \+\+ (\w+)$aN
    [loggers]
    keys=root

    [handlers]
    keys=hand1

    [formatters]
    keys=form1

    [logger_root]
    level=WARNING
    handlers=hand1

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stdout,)

    [formatter_form1]
    format=%(levelname)s ++ %(message)s
    datefmt=
    a�
    [loggers]
    keys=root,parser

    [handlers]
    keys=hand1

    [formatters]
    keys=form1

    [logger_root]
    level=WARNING
    handlers=

    [logger_parser]
    level=DEBUG
    handlers=hand1
    propagate=1
    qualname=compiler.parser

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stdout,)

    [formatter_form1]
    format=%(levelname)s ++ %(message)s
    datefmt=
    a�
    [loggers]
    keys=root,parser

    [handlers]
    keys=hand1

    [formatters]
    keys=form1

    [logger_root]
    level=WARNING
    handlers=hand1

    [logger_parser]
    level=DEBUG
    handlers=
    propagate=1
    qualname=compiler.parser

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stdout,)

    [formatter_form1]
    format=%(levelname)s ++ %(message)s
    datefmt=
    z
sys.stdoutz
sys.stboutzformatter=form1zformatter=misspelled_namea
    [loggers]
    keys=root

    [handlers]
    keys=hand1

    [formatters]
    keys=form1

    [logger_root]
    level=NOTSET
    handlers=hand1

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stdout,)

    [formatter_form1]
    class=zS.ExceptionFormatter
    format=%(levelname)s:%(name)s:%(message)s
    datefmt=
    zclass=StreamHandlerzclass=logging.StreamHandlerag
    [loggers]
    keys=root,parser

    [handlers]
    keys=hand1, hand2

    [formatters]
    keys=form1, form2

    [logger_root]
    level=WARNING
    handlers=

    [logger_parser]
    level=DEBUG
    handlers=hand1
    propagate=1
    qualname=compiler.parser

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stdout,)

    [handler_hand2]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stderr,)

    [formatter_form1]
    format=%(levelname)s ++ %(message)s
    datefmt=

    [formatter_form2]
    format=%(message)s
    datefmt=
    a%
    [loggers]
    keys=root,parser,compiler

    [handlers]
    keys=hand1

    [formatters]
    keys=form1

    [logger_root]
    level=WARNING
    handlers=hand1

    [logger_compiler]
    level=DEBUG
    handlers=
    propagate=1
    qualname=compiler

    [logger_parser]
    level=DEBUG
    handlers=
    propagate=1
    qualname=compiler.parser

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    kwargs={'stream': sys.stdout,}

    [formatter_form1]
    format=%(levelname)s ++ %(message)s
    datefmt=
    z�
    [loggers]
    keys=root

    [handlers]
    keys=file

    [formatters]
    keys=

    [logger_root]
    level=DEBUG
    handlers=file

    [handler_file]
    class=FileHandler
    level=DEBUG
    args=("{tempfile}",)
    z�
    [loggers]
    keys=root

    [handlers]
    keys=screen

    [formatters]
    keys=

    [logger_root]
    level=DEBUG
    handlers=screen

    [handler_screen]
    level=DEBUG
    class=StreamHandler
    args=(sys.stdout,)
    formatter=
    cKs$t�t�|��}tjj|f|�dSr�)r(r)�textwrap�dedentr�config�
fileConfig)r8�conf�kwargs�filer:r:r;�apply_config�szConfigFileTest.apply_configc	Csbt���P}|�|j�t��}|�|���|�|���|j	dg|d�|�	g�W5QRXdS�N�rerfr#�
r�captured_stdoutr��config0rrrvrZrtrV�r8�outputr�r:r:r;�test_config0_ok�s
��zConfigFileTest.test_config0_okc	Cs�t���t}t�t�|j��}t��}|�	|�t
j�|�t
�
�}|�|���|�|���|jdg|d�|�g�W5QRXdSr�)rr�r(r)r�r�r��configparser�ConfigParserZ	read_filerr�r�rrvrZrtrV)r8r�r�Zcpr�r:r:r;�test_config0_using_cp_ok�s

��z'ConfigFileTest.test_config0_using_cp_okc	Csdt���R}|�|�t�d�}|�|���|�|���|jddg|d�|�g�W5QRXdS�N�compiler.parser�rkrdr�r#�	rr�r�rrrvrZrtrV�r8r�r�r�r:r:r;�test_config1_ok�s


��zConfigFileTest.test_config1_okcCs|�t|j|j�dSr��r�rr��config2rYr:r:r;�test_config2_failure�sz#ConfigFileTest.test_config2_failurecCs|�t|j|j�dSr��r�rr��config3rYr:r:r;�test_config3_failure�sz#ConfigFileTest.test_config3_failurec	Cs|t���j}|�|j�t��}z
t��Wntk
rFt�d�YnXtj	�
d�|�|��d�|�
g�W5QRXdS�Nzjust testingrz-ERROR:root:just testing
Got a [RuntimeError]
)rr�r��config4rrrG�	exceptionr��stdout�seekrIrGrVr�r:r:r;�test_config4_ok�s


�zConfigFileTest.test_config4_okcCs|j|jd�dS�N)r��r��config5rYr:r:r;�test_config5_okszConfigFileTest.test_config5_okcCs|j|jd�dSr�)r��config6rYr:r:r;�test_config6_ok	szConfigFileTest.test_config6_okc	Cs&t���n}|�|j�t�d�}t�d�}|�|���|�|���|�	|���|j
dddg|d�|�
g�W5QRXt����}|�|j�t�d�}|�|j
�|�|���|�|���t�d�}|�|���|�|���|�	|���|j
dd	d
dg|d�|�
g�W5QRXdS�Nr�zcompiler-hyphenatedr�r�)rcrgr#�compiler.lexer)rkrh)rerj)rkrl)rerm)rr�r��config1arrrvrZrt�criticalrV�config7r�r�r8r�r�Z
hyphenatedr:r:r;�test_config7_oksD


��


��zConfigFileTest.test_config7_okc	Cs�dd�}|���Xt�dd�\}}t�|�tjdkrB|�dd�}|jj|d�}|�	|�|�	|�W5QRXt
jjd	}|�
|||�dS)
NcSs|��t�|�dSr��r=r��remove��h1r�r:r:r;�cleanup9sz/ConfigFileTest.test_config8_ok.<locals>.cleanupr�test_logging-X-r�\z\\)r�r)�check_no_resource_warningr�r�r�r=r9�replace�config8r�r�r�rootr4r�)r8r�r�r�rr�r:r:r;�test_config8_ok7s



zConfigFileTest.test_config8_okcCsZ|�|j�t�d�}|�|j�|�|j�|�|j�|j|jdd�|�|j�dS)NZsome_pristine_loggerF)�disable_existing_loggers)r��disable_testrrr�rr7�r8r�r:r:r;�test_logger_disablingNs
z$ConfigFileTest.test_logger_disablingc
Csxt�d���}tjddd�\}}zFt�||�d��t�	|�t
jj|t
dddd	d
dd�id
�d�W5t�|�XdS)z.bpo-33802 defaults should not get interpolatedat
            [formatters]
            keys=default

            [formatter_default]

            [handlers]
            keys=console

            [handler_console]
            class=logging.StreamHandler
            args=tuple()

            [loggers]
            keys=root

            [logger_root]
            formatter=default
            handlers=console
            �
test_logging_z.ini�r��suffix�asciirWFr�z5%(asctime)s [%(process)d] [%(levelname)s] %(message)sz[%Y-%m-%d %H:%M:%S %z]zlogging.Formatter)r��datefmt�class)�versionr�
formatters)�defaultsN)r�r��stripr�r�r�r�rJ�encoder=rr�r��dict)r8Zinir�r�r:r:r;�!test_defaults_do_no_interpolationWs&
����
z0ConfigFileTest.test_defaults_do_no_interpolationN) r[r\r]r^rr�rFr��config1r�rr�r�r�r�r�r�rrr�r�r�r�r�r�r�r�r�r�rrrr:r:r:r;r��s>  ��*&+	r�c@s@eZdZdZeZdZdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
S)�SocketHandlerTestzTest for SocketHandler objects.�r�rc
Cs�t�|�d|_|_|_z$|�|j|jd�|_}|��Wn.t	k
rn}z||_WY�dSd}~XYnX|j
��tj
j}t|jt�r�|d|j�|_n||jd�|_d|_|j�|jj
d�|j�|j�t�d�|_dS)ztSet up a TCP server to receive log messages, and a SocketHandler
        pointing to that server's address and port.N�{�G�z�?r�rr)r
r<r��	sock_hdlr�server_exception�server_class�address�
handle_socketrr�r|r2rr4Z
SocketHandler�
isinstance�server_addressrNrc�
log_outputr%r>r6r�	Semaphorer��r8r�r�Zhclsr:r:r;r<�s(
�

zSocketHandlerTest.setUpc	CsFz4|jr |j�|j�|j��|jr2|j�d�W5t�|�XdS)zShutdown the TCP server.�@N)r
rCrr%r>r=r�rzrYr:r:r;rC�s
zSocketHandlerTest.tearDowncCs�|j}|�d�}t|�dkrq�t�d|�d}|�|�}t|�|kr\||�|t|��}q8t�|�}t�|�}|j	|j
d7_	|j��qdS)Nr
�>Lr�
)
�
connection�recvrJ�struct�unpack�pickle�loadsrr�r r�r�r+)r8�request�conn�chunk�slen�objr�r:r:r;r�s



zSocketHandlerTest.handle_socketcCsV|jr|�|j�t�d�}|�d�|j��|�d�|j��|�|j	d�dS)NZtcpr��eggs�
spam
eggs
)
r�skipTestrrrtr�r*rwrIr rr:r:r;�test_output�s




zSocketHandlerTest.test_outputcCs�|jr|�|j�d|j_|j�d�ztd��Wn tk
rR|j�d�YnX|j�	d�t
�
�}|�|jj|�t
�
|jj|d�|j�	d�dS)Ng@r#zDeliberate mistakez
Never sentzNever sent, eitherr�zNor this)rr3rZ
retryStartr�rzrGr%r�rtrr7Z	retryTimer)r8�nowr:r:r;�
test_noserver�szSocketHandlerTest.test_noserverN)r[r\r]r^r�rrr<rCrr4r6r:r:r:r;r�srcCs*tjddd�\}}t�|�t�|�|S)Nrz.sockr	)r�r�r�r=r�)r�r�r:r:r;�_get_temp_domain_socket�s

r7zUnix sockets requiredc@s.eZdZdZeed�reZdd�Zdd�Z	dS)�UnixSocketHandlerTestz)Test for SocketHandler with unix sockets.r�cCst�|_t�|�dSr�)r7rrr<rYr:r:r;r<�szUnixSocketHandlerTest.setUpcCst�|�t�|j�dSr�)rrCrr�rrYr:r:r;rC�s
zUnixSocketHandlerTest.tearDownN)
r[r\r]r^rDrar�rr<rCr:r:r:r;r8�s

r8c@s8eZdZdZeZdZdd�Zdd�Zdd�Z	d	d
�Z
dS)�DatagramHandlerTestzTest for DatagramHandler.rc
Cs�t�|�d|_|_|_z$|�|j|jd�|_}|��Wn.t	k
rn}z||_WY�dSd}~XYnX|j
��tj
j}t|jt�r�|d|j�|_n||jd�|_d|_|j�|jj
d�|j�|j�t��|_dS)zvSet up a UDP server to receive log messages, and a DatagramHandler
        pointing to that server's address and port.Nrr�rr)r
r<r�rrrr�handle_datagramrr�r|r2rr4ZDatagramHandlerrrrNrcr r%r>r6rr9r�r"r:r:r;r<�s(
�

zDatagramHandlerTest.setUpc	CsFz4|jr|j�d�|jr2|j�|j�|j��W5t�|�XdS)zShutdown the UDP server.r#N)r
rCr�rzrr%r>r=rYr:r:r;rCszDatagramHandlerTest.tearDowncCsTt�dd�}|jt|�d�}t�|�}t�|�}|j|j	d7_|j
��dS)Nr$rr%)r(�pack�packetrJr*r+rr�r r�r�r1)r8r,r/r<r0r�r:r:r;r:!s

z#DatagramHandlerTest.handle_datagramcCs`|jr|�|j�t�d�}|�d�|j��|j��|�d�|j��|�|j	d�dS)NZudpr�r1r2)
rr3rrrtr�r2r?rIr rr:r:r;r4)s





zDatagramHandlerTest.test_outputN�r[r\r]r^r�rrr<rCr:r4r:r:r:r;r9�sr9c@s.eZdZdZeed�reZdd�Zdd�Z	dS)�UnixDatagramHandlerTestz,Test for DatagramHandler using Unix sockets.r�cCst�|_t�|�dSr�)r7rr9r<rYr:r:r;r<=szUnixDatagramHandlerTest.setUpcCst�|�t�|j�dSr�)r9rCrr�rrYr:r:r;rCBs
z UnixDatagramHandlerTest.tearDownN�
r[r\r]r^rDrar�rr<rCr:r:r:r;r>5s

r>c@s8eZdZdZeZdZdd�Zdd�Zdd�Z	d	d
�Z
dS)�SysLogHandlerTestz!Test for SysLogHandler using UDP.rc
Cs�t�|�d|_|_|_z$|�|j|jd�|_}|��Wn.t	k
rn}z||_WY�dSd}~XYnX|j
��tj
j}t|jt�r�||jd|jf�|_n||j�|_d|_|j�|jj
d�|j�|j�t��|_dS)ztSet up a UDP server to receive log messages, and a SysLogHandler
        pointing to that server's address and port.Nrrr)r
r<r��sl_hdlrrrrr:rr�r|r2rr4r�rrrNrcr r%r>r6rr9r�r"r:r:r;r<Ms(
�

zSysLogHandlerTest.setUpc	CsFz4|jr|j�d�|jr2|j�|j�|j��W5t�|�XdS)zShutdown the server.r#N)r
rCr�rzrAr%r>r=rYr:r:r;rCgszSysLogHandlerTest.tearDowncCs|j|_|j��dSr�)r<r r�r1)r8r,r:r:r;r:rsz!SysLogHandlerTest.handle_datagramcCs�|jr|�|j�t�d�}|�d�|j��|�|jd�|j�	�d|j
_|�d�|j��|�|jd�|j�	�d|j
_|�d�|j��|�|jd�dS)NZslh�späms
<11>spämFs	<11>spämuhäm-s<11>häm-späm)
rr3rrrtr�r2rIr r?rAZ
append_nul�identrr:r:r;r4vs 








zSysLogHandlerTest.test_outputNr=r:r:r:r;r@Fsr@c@s.eZdZdZeed�reZdd�Zdd�Z	dS)�UnixSysLogHandlerTestz)Test for SysLogHandler with Unix sockets.r�cCst�|_t�|�dSr�)r7rr@r<rYr:r:r;r<�szUnixSysLogHandlerTest.setUpcCst�|�t�|j�dSr�)r@rCrr�rrYr:r:r;rC�s
zUnixSysLogHandlerTest.tearDownNr?r:r:r:r;rD�s

rDz$IPv6 support required for this test.cs4eZdZdZeZdZ�fdd�Z�fdd�Z�Z	S)�IPv6SysLogHandlerTestz&Test for SysLogHandler with IPv6 host.)z::1rcstj|j_tt|���dSr�)ra�AF_INET6rr�r$rEr<rYr(r:r;r<�s
zIPv6SysLogHandlerTest.setUpcstj|j_tt|���dSr�)ra�AF_INETrr�r$rErCrYr(r:r;rC�s
zIPv6SysLogHandlerTest.tearDown)
r[r\r]r^r�rrr<rCr-r:r:r(r;rE�s
rEc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�HTTPHandlerTestzTest for HTTPHandler.cCst�|�t��|_dS)ztSet up an HTTP server to receive log messages, and a HTTPHandler
        pointing to that server's address and port.N)r
r<rr9r�rYr:r:r;r<�s
zHTTPHandlerTest.setUpcCsr|j|_t|j�|_|jdkrRz t|jd�}|j�|�|_Wnd|_YnX|�	d�|�
�|j��dS)Nr�zContent-Length��)
�commandrr��log_data�intZheadersZrfilerP�	post_dataZ
send_responseZend_headersr�r1)r8r,Zrlenr:r:r;�handle_request�s

zHTTPHandlerTest.handle_requestc	Cs�t�d�}|j}|�|jjd�dD�]�}d}|r�zddl}Wntk
rXd}Yq�Xtj�	t
�}tj�|d�}|�|j
�}|�|�|j|d�}	nd}d}	t||jd|d�|_}
|
��|
j��d	|
j}|o�|}tjj|d
||	dd�|_d|_|�|j�d
D]�}
|
|j_|j��d}|�|�|j��|�|jjd
�|�|j |
�|
dk�rnt!|jj"�}nt!|j#�$d��}|�|ddg�|�|ddg�|�|d|g��q
|j�%d�|j�|j�|j�&�q&dS)NZhttprrrzkeycert.pem)Zcafiler)r�zlocalhost:%dz/frob)�foo�bar)�secure�contextZcredentials)r�r�rBr��utf-8r9�funcNamer4r�r#)'rrr%r>r4�ssl�ImportErrorr�r��dirname�__file__r�Z
SSLContextZPROTOCOL_TLS_SERVERZload_cert_chainZcreate_default_contextrrNr�rr|r2Zserver_portr�Zh_hdlrrKr6rr�r?rtrIrJrZqueryrM�decoderzr=)r8r�r%rQrhrUr��hereZlocalhost_certrRr��hostZ
secure_clientrr��dr:r:r;r4�sb



�


�



zHTTPHandlerTest.test_outputN)r[r\r]r^r<rNr4r:r:r:r;rH�s
rHc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
MemoryTestz*Test memory persistence of logger objects.cCst�|�i|_dS)z8Create a dict to remember potentially destroyed objects.N)r
r<�
_survivorsrYr:r:r;r<�s
zMemoryTest.setUpcGs.|D]$}t|�t|�f}t�|�|j|<qdS)zKWatch the given objects for survival, by creating weakrefs to
        them.N)�idr[�weakref�refr^)r8r
r0�keyr:r:r;�_watch_for_survivalszMemoryTest._watch_for_survivalcCs\t��g}|j��D] \\}}}|�dkr|�|�q|rX|�dt|�d�|�f�dS)z;Assert that all objects watched for survival have survived.Nz;%d objects should have survived but have been destroyed: %sz, )�gcZcollectr^r�r�rMrJr�)r8ZdeadZid_�repr_rar:r:r;�_assertTruesurvivals
�zMemoryTest._assertTruesurvivalcCs�|j�tj�t�d�}|�|�|�tj�|j�|���|�|���|�	dg�~|�
�t�d�}|�|���|�	ddg�dS)NrO)rOr,rf)rOr,rg)r%r+rrkrrcr,rwrZrVrf)r8rOrPr:r:r;�test_persistent_loggerss"

�
�z"MemoryTest.test_persistent_loggersN)r[r\r]r^r<rcrfrgr:r:r:r;r]�s
r]c@seZdZdd�Zdd�ZdS)�EncodingTestc	Cs�t�d�}t�dd�\}}t�|�d}zptj	|dd�}|�
|�z|�|�W5|�|�|��Xt
|dd�}z|�|����|�W5|��XW5tj�|�r�t�|�XdS)N�testrztest_logging-1-ufoo€rS)�encoding)rrr�r�r�r=r��isfiler�rr6r>rur&rIrP�rstrip)r8rsr�r�rIr�r�r:r:r;�test_encoding_plain_file-s"




z%EncodingTest.test_encoding_plain_filec	Cs�t�d�}d}t�d�}d|_t��}||d�}t�|�}|�|�z|�|�W5|�	|�|�
�X|��}|�
|d�dS)Nriuдо свидания�cp1251�stricts�� �������
)rr�codecs�	getwriterrjr(�BytesIOr-r6r>r=rurGrI)r8rs�messageZwriter_classr*�writerr�rUr:r:r;�test_encoding_cyrillic_unicodeGs






z+EncodingTest.test_encoding_cyrillic_unicodeN)r[r\r]rmrur:r:r:r;rh,srhc@seZdZdd�Zdd�ZdS)�WarningsTestc	Cs�t����t�d�|�tjd�tjdtd�t��}t�	|�}t�
d�}|�|�t�d�|�
|�|��}|��|�|�d�d�t��}t�d	td
d|d�|��}|��|�|d
�W5QRXdS)NTF�always)�category�py.warningszI'm warning you...z UserWarning: I'm warning you...
r�Explicit�dummy.py�*z
Dummy linez0dummy.py:42: UserWarning: Explicit
  Dummy line
)�warnings�catch_warningsr�captureWarningsr��filterwarnings�UserWarningr(r)r-rr6�warnr>rGr=r7�find�showwarningrI)r8r*rBr�rUZa_filer:r:r;�
test_warnings_s.






��zWarningsTest.test_warningsc	Cs~t���lt�d�|�tjd�t�d�}|�|jg�t�dt	dd�|�t
|j�d�|�|jdtj�W5QRXdS)	NTFryrzr{r|rWr)
r}r~rrr�rrIr4r�r�rJ�assertIsInstance�NullHandlerrr:r:r;�test_warnings_no_handlersws


z&WarningsTest.test_warnings_no_handlersN)r[r\r]r�r�r:r:r:r;rv]srvcCst�||�Sr�)rr/)r�rr:r:r;�
formatFunc�sr�c@seZdZddd�ZdS)�myCustomFormatterNcCsdSr�r:)r8�fmtrr:r:r;r%�szmyCustomFormatter.__init__)N)r[r\r]r%r:r:r:r;r��sr�cCst��Sr�)rr-r:r:r:r;�handlerFunc�sr�c@seZdZdS)�
CustomHandlerN�r[r\r]r:r:r:r;r��sr�c
@seZdZdZejZdZddddiidddd	d
d�iddgd
�d�Zddddiidddd	d
d�idddgd
�iddid�Zddddiidddd	d
d�idddiiddgd
�d�Z	ddddiidddd	dd�idddgd
�iddid�Z
ddddiiddddd
d�idddgd
�iddid�Zddddiidddd	d
d�idddgd
�iddid�Zddddiidddd	d
d�idddgd
�iddid�Z
ddeddd�idddd	d
d�id	dgd
�d�Zdedd�eddd�edd�d�ddd	d
d�deid�d	dgd
�d�Zddddiideddd	d
d�idddgd
�iddid�Zddddiideddd	d
dd �idddgd
�iddid�Zddddiidddd	d
d�id!ddgd
�iddid�Zdd"dddiidddd	d
d�iddgd
�id#�ddid$�Zdd%dddiidddd	d
d�iddgd
�id#�ddid$�Zddddiiddddd
d�idddgd
�idd	id�Zdd%dddiiddd&iid'�Zdd%ddd&iiddd&iid'�Zddddiid(d)diidddd	d
d(gd*�iddd(gd+�iddgd
�d,�Zddddiidddd	d
d�id-dd.idddgd
�iddid/�Zdddiidddd	d
d�id-dd.idddgd
�iddid0�Zd1dddiidddd	d
d�id-dd.idddgd
�iddid/�Zddddiidddd	d
d2d3d4�d5�iddgd
�d�Zdd6d7d8d9�iddd6d:�d;d<d6d=dd>�d?�d@ddAgdBdC�idD�Z ddeddd"dE�idddd	d
d�idFddgdBdC�idD�Z!ddeddd"dG�idddd	d
d�idFddgdBdC�idD�Z"ddedHdd"dG�idddd	d
d�idFddgdBdC�idD�Z#ddedd"dE�idddd	d
d�idFddgdBdC�idD�Z$dIdJ�Z%dKdL�Z&efdMdN�Z'dOdP�Z(dQdR�Z)dSdT�Z*dUdV�Z+dWdX�Z,dYdZ�Z-d[d\�Z.d]d^�Z/d_d`�Z0dadb�Z1dcdd�Z2dedf�Z3dgdh�Z4didj�Z5dkdl�Z6dmdn�Z7dodp�Z8dqdr�Z9d�dtdu�Z:dvdw�Z;dxdy�Z<dzd{�Z=d|d}�Z>d~d�Z?d�d��Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFdsS)��ConfigDictTestz)Reading logging config from a dictionary.r�rW�form1r�z%(levelname)s ++ %(message)s�hand1zlogging.StreamHandlerr�zext://sys.stdout)r
�	formatterrOr*ri�rOr4)rrr4rr�r,rO)rrr4�loggersrzext://sys.stdboutZNTOSETZWRANINGZmisspelled_namez.ExceptionFormatterz"%(levelname)s:%(name)s:%(message)s)�()r�z.formatFunc)r�Zform2Zform3r�)r�Zhand2z.CustomHandlerzinvalid parameter name)r
r�rOr*ror�F)�compilerr�)rrrr4r�rTrk)rZincrementalr4r�Zfilt1r9)r
r�rOr*�filters)rOr�)rrr�r4r�rzcfg://true_formatterszcfg://handler_configs[hand1])r�true_formatters�handler_configsrr4r�r)r�r�rr4r�rr�rP�!
)rO�
terminator)r
r�rOr*r��mySimpleFormatterz1%(asctime)s (%(name)s) %(levelname)s: %(message)s�$)r��style)r
rOr�zlogging.handlers.MemoryHandler��
fileGlobal)r
Zcapacityr�rrO)r��bufferGlobal�mymoduler��true)rOr4r�)rrr4r�)r�r��validate�my_test_logger_custom_formatter)r
r�r�z.myCustomFormattercCstj�|�dSr�)rr�Z
dictConfig)r8r�r:r:r;r�xszConfigDictTest.apply_configc	Csbt���P}|�|j�t��}|�|���|�|���|j	dg|d�|�	g�W5QRXdSr�r�r�r:r:r;r�{s
��zConfigDictTest.test_config0_okc	Csdt���R}|�|�t�d�}|�|���|�|���|jddg|d�|�g�W5QRXdSr�r�r�r:r:r;r��s


��zConfigDictTest.test_config1_okcCs|�t|j|j�dSr�r�rYr:r:r;r��sz#ConfigDictTest.test_config2_failurecCs|�t|j|j�dSr�)r�rr��config2arYr:r:r;�test_config2a_failure�sz$ConfigDictTest.test_config2a_failurecCs|�t|j|j�dSr�)r�rr��config2brYr:r:r;�test_config2b_failure�sz$ConfigDictTest.test_config2b_failurecCs|�t|j|j�dSr�r�rYr:r:r;r��sz#ConfigDictTest.test_config3_failurec	Cstt���b}|�|j�z
t��Wntk
r>t�d�YnXtj�	d�|�
|��d�|�g�W5QRXdSr�)
rr�r�r�rGrr�r�r�r�rIrGrV�r8r�r:r:r;r��s


�zConfigDictTest.test_config4_okc	Cstt���b}|�|j�z
t��Wntk
r>t�d�YnXtj�	d�|�
|��d�|�g�W5QRXdSr�)
rr�r��config4arGrr�r�r�r�rIrGrVr�r:r:r;�test_config4a_ok�s


�zConfigDictTest.test_config4a_okcCs|j|jd�dSr�r�rYr:r:r;r��szConfigDictTest.test_config5_okcCs|�t|j|j�dSr�)r�rr�r�rYr:r:r;�test_config6_failure�sz#ConfigDictTest.test_config6_failurec	Cs�t���T}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�W5QRXt���j}|�|j
�t�d�}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�W5QRXdS)Nr�r�r�r#r��rkrg�rerh)
rr�r�rrrrvrZrtrVr�r7rr�r:r:r;r��s4

��


��zConfigDictTest.test_config7_okc	Cs�t���T}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�W5QRXt����}|�|j
�t�d�}|�|j�|�|���|�|���t�d�}|�|���|�|���|j	dddd	g|d�|�	g�W5QRXdS)
Nr�r�r�r#r�r�r��rkrj�rerl)
rr�r�rrrrvrZrtrVrr�rr�r:r:r;�test_config_8_ok�s<

��


��zConfigDictTest.test_config_8_okc	Cs&t���n}|�|j�t�d�}t�d�}|�|���|�|���|�	|���|j
dddg|d�|�
g�W5QRXt����}|�|j�t�d�}|�|j
�|�|���|�|���t�d�}|�|���|�|���|�	|���|j
dd	d
dg|d�|�
g�W5QRXdSr�)rr�r�r�rrrvrZrtr�rV�config8ar�rr�r:r:r;�test_config_8a_oksD


��


��z ConfigDictTest.test_config_8a_okc	Cs�t����}|�|j�t�d�}|�|���|jg|d�|�|j	�|�|���|jg|d�|�|j
�|�|���|jdg|d�W5QRXdS)Nr�r#r�)rr�r��config9rrrvrZrV�config9a�config9br�r:r:r;�test_config_9_ok6s

��zConfigDictTest.test_config_9_okc	Cs�t����}|�|j�t�d�}|�|���t�d�}|�|���t�d�}|�|���t�d�}|�|���|j	ddg|d�W5QRXdS�Nr�r�r�zcompiler.parser.codegen)rirdr�r#)
rr�r��config10rrrurZrtrVr�r:r:r;�test_config_10_okHs 




��z ConfigDictTest.test_config_10_okcCs|�|j�dSr�)r��config11rYr:r:r;�test_config11_ok[szConfigDictTest.test_config11_okcCs|�t|j|j�dSr�)r�rr��config12rYr:r:r;�test_config12_failure^sz$ConfigDictTest.test_config12_failurecCs|�t|j|j�dSr�)r�rr��config13rYr:r:r;�test_config13_failureasz$ConfigDictTest.test_config13_failurec	Csht���V}|�|j�tjd}|�|jd�|�|jd�t�	d�|�
|���d��W5QRXdS)Nr�rPr�ZExclamationz
Exclamation!
)
rr�r��config14rrrIrOr�rur7rGr�)r8r�rBr:r:r;�test_config14_okds


zConfigDictTest.test_config14_okc	Cs�dd�}|���Pt�dd�\}}t�|�ddd|d�id	dgid
�}|�|�|�|�W5QRXtjjd}|�	|||�dS)NcSs|��t�|�dSr�r�r�r:r:r;r�osz0ConfigDictTest.test_config15_ok.<locals>.cleanuprr�rWr�zlogging.FileHandler)r
�filenamer4�rr4rr)
r�r�r�r�r=r�rrr4r�)r8r�r�r�r�r�r:r:r;�test_config15_okms$

����
zConfigDictTest.test_config15_okNc
Cs�|�d�}tj�d|�}|��|j��|j}|j��z�t�tj
tj�}|�d�|�d|f�t�dt|��}||}d}t|�}	|	dkr�|�||d��}
||
7}|	|
8}	q�|��W5|j�d�tj�	�t
�|d�XdS)NrSrr#r�r$)rrr��listenrr|r2rcr?Z
stopListeningrrwrarG�SOCK_STREAM�
settimeout�connectr(r;rJ�sendr=)r8�textZverifyrrrcr�r/rUZ	sentsofar�left�sentr:r:r;�setup_via_listener�s,





z!ConfigDictTest.setup_via_listenerc	Cs�t����}|�t�|j��t�d�}|�|�	��t�d�}|�|�	��t�d�}|�|�	��t�d�}|�
|�	��|jddg|d�W5QRXdSr�)rr�r��json�dumpsr�rrrurZrtrVr�r:r:r;�test_listen_config_10_ok�s 




��z'ConfigDictTest.test_listen_config_10_okc	Cslt���Z}|�t�tj��t�d�}|�	|�
��|�|�
��|jddg|d�|�g�W5QRXdSr�)
rr�r�r�r�r�rrrrvrZrtrVr�r:r:r;�test_listen_config_1_ok�s

��z&ConfigDictTest.test_listen_config_1_okc	Csbdd�}dd�}t�d�}t�tj�}t���.}|�||�|�	|�
��|�|�
��W5QRX|jg|d�|jddgd	d
�t���6}|�|�t�d�}|�	|�
��|�|�
��W5QRX|jddg|d�|jddgd	d
�t���B}|�|ddd
�|�t�d�}|�	|�
��|�|�
��W5QRX|jddg|d�|jddgd	d
�dS)NcSsdSr�r:��stuffr:r:r;�verify_fail�sz6ConfigDictTest.test_listen_verify.<locals>.verify_failcSs|ddd�S)Nr�r:r�r:r:r;�verify_reverse�sz9ConfigDictTest.test_listen_verify.<locals>.verify_reverser�r#r�r�r�)rQr�r�r�r�r�)
rrr�r�r�rrr�r�rvrZrtrV)r8r�r�r�Zto_sendr�r:r:r;�test_listen_verify�sb

��


����

����z!ConfigDictTest.test_listen_verifycCs|�t|j|j�dSr�)r�r�r��out_of_orderrYr:r:r;�test_out_of_order
sz ConfigDictTest.test_out_of_ordercCs\t�|j�}d|ddd<|�|�t�d�jd}|�|jtj	�|�|j
jtj�dS)Nz-${asctime} (${name}) ${levelname}: ${message}rr�r�r�r)
r�deepcopyr�r�rrr4r�rr�r��_style�StringTemplateStyle�r8r�r�r:r:r;�#test_out_of_order_with_dollar_style
s

�z2ConfigDictTest.test_out_of_order_with_dollar_stylecCs.|�|j�t�d�jd}|�|jt�dS�Nr�r)r��custom_formatter_class_validaterrr4r�r�r��r8r�r:r:r;�)test_custom_formatter_class_with_validate
sz8ConfigDictTest.test_custom_formatter_class_with_validatecCs.|�|j�t�d�jd}|�|jt�dSr�)r�� custom_formatter_class_validate2rrr4r�r�r�r�r:r:r;�*test_custom_formatter_class_with_validate2
sz9ConfigDictTest.test_custom_formatter_class_with_validate2cCsF|j��}d|ddd<|�|�t�d�jd}|�|jt�dS)Nr�rr�r�r�r)	r�rr�rrr4r�r�r�r�r:r:r;�9test_custom_formatter_class_with_validate2_with_wrong_fmt
s


zHConfigDictTest.test_custom_formatter_class_with_validate2_with_wrong_fmtcCs|�t|j|j�dSr�)r�r�r�� custom_formatter_class_validate3rYr:r:r;�*test_custom_formatter_class_with_validate3%
sz9ConfigDictTest.test_custom_formatter_class_with_validate3cCs|�t|j|j�dSr�)r�r�r��custom_formatter_with_functionrYr:r:r;�,test_custom_formatter_function_with_validate(
sz;ConfigDictTest.test_custom_formatter_function_with_validatecCs�ddddgddd�dd	d
dgdgd
ddgd�}tj�|�}|�|�d�d�|�|�d�d�|�|�d�d�|�|�d�d�|�|�d�d�|�|�d�d�|�d�}|�|�d�dddg�|�t|jd�|�t|jd�|�t|jd�dS)N)rWr��r�b�cr�r�)r\r�)�g)rBr��jr��lrxr��ozcfg://alist�p)ZatupleZalistZadictZnest1Znest2Znest3zcfg://atuple[1]r�zcfg://alist[1]zcfg://nest1[1][0]rBzcfg://nest2[1][1]z
cfg://adict.dzcfg://adict[f]zcfg://nest3rWzcfg://nosuchzcfg://!zcfg://adict[2])	rr�ZBaseConfiguratorrI�convert�popr��KeyErrorr�)r8r\Zbcr�r:r:r;�test_baseconfig+
s&�
zConfigDictTest.test_baseconfigc	s�ddlm�G�fdd�dtj�}�dddg�}|dd	gd
�}dd||d
�iddgd�d�}t���}|�|�t�d�W5QRX|�|�	�d�dS)Nr��
namedtuplecs*eZdZ��fdd�Z�fdd�Z�ZS)z1ConfigDictTest.test_namedtuple.<locals>.MyHandlercst�j||�||_dSr�)r$r%�resource)r8r�r
r�)r)r�r:r;r%F
sz:ConfigDictTest.test_namedtuple.<locals>.MyHandler.__init__cs$|jd|jj��7_t��|�S�N� )r�r��typer$r�r�r(r:r;r�J
sz6ConfigDictTest.test_namedtuple.<locals>.MyHandler.emitr,r:r�r(r;�	MyHandlerE
sr��Resourcer��labelsZmy_typer)r�r�rWZ	myhandler)r�r�rkr�r�zsome logzsome log my_type
)
�collectionsr�rr-rrSr�rvrIrG)r8r�r�r�r�rUr:r�r;�test_namedtupleA
s 	��
�


zConfigDictTest.test_namedtuple)N)Gr[r\r]r^rr�rFr�rr�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr:r:r:r;r��s�����	������	��������	��������	��������	��������	��������	��������	�����������#����	��������
��������	��������
��	������
��	������	��������������������
����#���������!������������������ �����
����������!����	�������	�������	�������	���!+	
>
	r�c@seZdZdd�Zdd�ZdS)�ManagerTestcsng�G�fdd�dtj�}t�d�}|�t|jt�|�|�|�d�}|�d�t�d�|�	�dg�dS)NcseZdZd�fdd�	ZdS)z6ManagerTest.test_manager_loggerclass.<locals>.MyLoggerNcs��|�dSr��r�)r8rOr�r
�exc_info�extra�Zloggedr:r;�_loge
sz;ManagerTest.test_manager_loggerclass.<locals>.MyLogger._log)NN)r[r\r]rr:rr:r;�MyLoggerd
srrizshould appear in loggedzshould not appear in logged)
r�Logger�Managerr��	TypeError�setLoggerClassrLrrurI)r8r�manr�r:rr;�test_manager_loggerclassa
s




z$ManagerTest.test_manager_loggerclasscCs,t�d�}t�}|�|�|�|j|�dSr�)rr
�object�setLogRecordFactoryrI�logRecordFactory)r8r
rSr:r:r;�test_set_log_record_factoryq
s

z'ManagerTest.test_set_log_record_factoryN)r[r\r]rrr:r:r:r;r`
src@seZdZdd�ZdS)�ChildLoggerTestcCs�t��}t�d�}t�d�}|�d�}|�d�}|�|t�d��|�|t�d��|�d�}|�d�}|�d�}|�|t�d��|�|t�d��|�||�dS)	N�abczdef.ghiZxyzzuvw.xyz�defZghi�abc.defzabc.def.ghi)rr�getChildrR)r8r��l1�l2�c1�c2Zc3r:r:r;�test_child_loggersx
s






z"ChildLoggerTest.test_child_loggersN)r[r\r]rr:r:r:r;rw
src@seZdZdS)�DerivedLogRecordNr�r:r:r:r;r�
src@s$eZdZdd�Zdd�Zdd�ZdS)�LogRecordFactoryTestcCsBGdd�dtj�}t�|�|t�|_|j�|j�t��|_	dS)Nc@seZdZdd�Zdd�ZdS)z2LogRecordFactoryTest.setUp.<locals>.CheckingFiltercSs
||_dSr�)r	)r8r	r:r:r;r%�
sz;LogRecordFactoryTest.setUp.<locals>.CheckingFilter.__init__cSs,t|�}||jk	r(d||jf}t|��dS)Nz)Unexpected LogRecord type %s, expected %sT)r�r	r)r8r�rrr�r:r:r;r��
s
�z9LogRecordFactoryTest.setUp.<locals>.CheckingFilter.filterN)r[r\r]r%r�r:r:r:r;�CheckingFilter�
sr)
rr�r
r<rr�r%r��getLogRecordFactory�orig_factory)r8rr:r:r;r<�
s


zLogRecordFactoryTest.setUpcCs(|j�|j�t�|�t�|j�dSr�)r%r�r�r
rCrrr!rYr:r:r;rC�
s
zLogRecordFactoryTest.tearDowncCs@|�t|jj|���t�t�|j�|���|�	dg�dS)N)rrerf)
r�rr%rurZrrrrtrVrYr:r:r;�test_logrecord_class�
s�
�z)LogRecordFactoryTest.test_logrecord_classN)r[r\r]r<rCr"r:r:r:r;r�
src@s�eZdZdZdd�Zdd�Zdd�Zdd	�Ze�	e
ejd
�d�dd
��Z
e�	e
ejd
�d�dd��Ze�	e
ejd
�d�dd��ZdS)�QueueHandlerTestr�cCs`t�|�t�d�|_tj�|j�|_d|_t�	d�|_
d|j
_|j
�tj
�|j
�|j�dS)Nr�ZqueF)r
r<�queue�Queuerr4�QueueHandler�que_hdlrr9r�
que_loggerr�r+rir6rYr:r:r;r<�
s
zQueueHandlerTest.setUpcCs|j��t�|�dSr�)r'r=r
rCrYr:r:r;rC�
s
zQueueHandlerTest.tearDowncCs�|j�|���|�tj|jj�|j�|���|�tj|jj�|��}|j�|�|j��}|�	t
|tj��|�
|j|jj�|�
|j|jf|df�dSr�)r(rwrZr�r$�Empty�
get_nowaitrvrur7rr�	LogRecordrIr9r�r
)r8r�rIr:r:r;�test_queue_handler�
s
z#QueueHandlerTest.test_queue_handlercCsx|��}t�tj�}d}|j|j||d�}t�|j�}|j�	|�|j
�|�|j�
�}|�||j�|�||j�dS)Nz {name} -> {levelname}: {message})r9�	levelnamers)rZrr�rir�r9r/r0r'r2r(rur$r*rIr�rs)r8r�r-Zlog_format_strZ
formatted_msgr�Z
log_recordr:r:r;�test_formatting�
s�
z QueueHandlerTest.test_formatting�
QueueListenerz5logging.handlers.QueueListener required for this testcCstt�t���}tj�|j|�}|��z4|j	�
|���|j	�|���|j	�
|���W5|��X|�|jtjdd��|�|jtjdd��|�|jtjdd��|��t�t���}|�tj�tjj|j|dd�}|��z4|j	�
|���|j	�|���|j	�
|���W5|��X|�|jtjdd��|�|jtjdd��|�|jtjd	d��|��dS)
Nrd)r�rsrfrgT)Zrespect_handler_levelrhrjrl)rZTestHandlerZMatcherrr4r/r$rrzr(rurZrtr�r7�matchesrirercr=r+r�)r8r��listenerr:r:r;�test_queue_listener�
s6
�
z$QueueHandlerTest.test_queue_listenerc
Cs�tj�|j|j�}|��zddWn:tk
r`}z|}|jj|�	�|d�W5d}~XYnX|�
�|�|j�
����d�d�dS)NrWr�rZ	Traceback)rr4r/r$r.r�ZeroDivisionErrorr(r�rZrzrIr*rGrrs)r8r1r��excr:r:r;�&test_queue_listener_with_StreamHandler�
s&z7QueueHandlerTest.test_queue_listener_with_StreamHandlercCsd|j�|j�|j�|j�tj�|j	|j�}|�
�|j�d�|��|�
|j����d�dS)Nrtzque -> ERROR: error)r'r2r1r(r6r.rr4r/r$rrtrzrIr*rGr)r8r1r:r:r;�*test_queue_listener_with_multiple_handlers
sz;QueueHandlerTest.test_queue_listener_with_multiple_handlersN)r[r\r]rFr<rCr,r.rC�
skipUnlessrDrr4r2r6r7r:r:r:r;r#�
s"

�
!�
�r#r/)�patchc@sleZdZdZdZedd��Ze�e	j
jd�dd��Ze�e	j
jd�dd	��Z
ed
d��Zdd
�Zdd�ZdS)�QueueListenerTestz~
        Tests based on patch submitted for issue #27930. Ensure that
        QueueListener handles all log messages.
        �cCs�t�d|�}|�tj�tj�|�}|�|�tj�|�}|��|�	d�|�	d�|�	d�|�	d�|�	d�|�
�|�|�|��dS)z�
            Creates a logger with a QueueHandler that logs to a queue read by a
            QueueListener. Starts the listener, logs five messages, and stops
            the listener.
            ztest_logger_with_id_%s�one�twoZthreeZfourZfiveN)
rrr+r,r4r&r6r/rrvrzr>r=)�	log_queuerCr�r�r1r:r:r;�
setup_and_log#s






zQueueListenerTest.setup_and_logr�cCsJt|j�D]$}t��}|�|d|��|f�q
|�|jd|jd�dS�N�%s_%sr�z&correct number of handled log messages)r�repeatr$r%r?r_rI�
call_count�r8Zmock_handler�r>r:r:r;�#test_handle_called_with_queue_queue;s�z5QueueListenerTest.test_handle_called_with_queue_queuecCsbt��t|j�D]4}t��}|�|d|��|f�|��|�	�q|�
|jd|jd�dSr@)r�*skip_if_broken_multiprocessing_synchronizerrB�multiprocessingr%r?r_r=rwrIrCrDr:r:r;� test_handle_called_with_mp_queueCs
�z2QueueListenerTest.test_handle_called_with_mp_queueccs0z|��VqWntjk
r*gYSXdSr�)r*r$r))r>r:r:r;�get_all_from_queuePsz$QueueListenerTest.get_all_from_queuecCs�t��t|j�D]n}t��}|�|d|��|f�t|�	|��}|�
�|��gtj
jjgg}|�||ddd�|D��qdS)a
            Five messages are logged then the QueueListener is stopped. This
            test then gets everything off the queue. Failure of this test
            indicates that messages were not registered on the queue until
            _after_ the QueueListener stopped.
            rAz&Found unexpected messages in queue: %scSs"g|]}t|tj�r|jn|�qSr:)rrr+r�)r�rxr:r:r;r�ms�zJQueueListenerTest.test_no_messages_in_queue_after_stop.<locals>.<listcomp>N)rrFrrBrGr%r?r_�listrIr=rwrr4r/�	_sentinelrT)r8r�r$r�rSr:r:r;�$test_no_messages_in_queue_after_stopXs	���z6QueueListenerTest.test_no_messages_in_queue_after_stopc	CsFt��}tj�|�}|��|��|�t��|�	�W5QRXdSr�)
r$r%rr4r/rrzr�r��	task_done)r8r>r1r:r:r;�test_calls_task_done_after_stoppsz1QueueListenerTest.test_calls_task_done_after_stopN)r[r\r]r^rB�staticmethodr?r9rrr4r/rErHrIrLrNr:r:r:r;r:s



r:c@s eZdZdd�ZeZdd�ZdS)�UTCcCstSr�)�ZERO�r8�dtr:r:r;�	utcoffset~sz
UTC.utcoffsetcCsdS)NrPr:rRr:r:r;�tzname�sz
UTC.tznameN)r[r\r]rT�dstrUr:r:r:r;rP}srPc@sVeZdZdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)�
FormatterTestc	Cs0dtjtj�ddd�dddddd�|_i|_dS)	Nzformatter.testr��toz	dummy.extr|zMessage with %d %s)r�Zplaceholders)r9rO�pathname�linenor�funcr�r
)rr,r�r�r��common�variantsrYr:r:r;r<�s�
zFormatterTest.setUpNcCs,t|j�}|dk	r"|�|j|�t�|�Sr�)rr\r@r]rr�)r8r9�resultr:r:r;�
get_record�s
zFormatterTest.get_recordc
OsLz|j|f|�|�Wn0|k
rF}z|�||j�W5d}~XYnXdSr�)r�rIrs)r8r�rsr
r�r�r:r:r;�assert_error_message�sz"FormatterTest.assert_error_messagecCs�|��}t�d�}|�|�|�d�t�d�}|�t|j|�|�|���t�d�}|�	|���t�d�}|�	|���t�d�}|�	|���dS)Nz${%(message)s}z${Message with 2 placeholders}z
%(random)s�%(asctime)sz%(asctime)-15sz%(asctime)#15s�
r_rr/rIr�r�r�r��usesTimer7�r8r�r�r:r:r;�test_percent�s




zFormatterTest.test_percentcCs�|��}tjddd�}|�|�|�d�tjddd�}|�t|j|�tjddd�}|�|���tjddd�}|�	|���tjddd�}|�	|���tjd	dd�}|�	|���dS)
Nz
$%{message}%$�{�r��$%Message with 2 placeholders%$z{random}z	{message}�	{asctime}z{asctime!s:15}z{asctime:15}rbrdr:r:r;�test_braces�szFormatterTest.test_bracescCs|��}tjddd�}|�|�|�d�tjddd�}|�|�|�d�tjddd�}|�|�|�d�tjddd�}|�t|j|�|�|���tjd	dd�}|�	|���tjd
dd�}|�	|���tjddd�}|�|���tjddd�}|�	|���dS)N�
${message}r�rgzMessage with 2 placeholdersz$messagez$$%${message}%$$rhz	${random}z
${asctime}z$asctimez${asctime}--rbrdr:r:r;�test_dollars�s$zFormatterTest.test_dollarscCst�d�}|�|jd�t�d�}|�|jd�t�d�}|�|jd�t�d�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjd	dd�}|�|jd	�tjd
dd�}|�|jd
�tjddd�}|�|jd�tjddd�}|�|jd�tjd
dd�}|�|jd
�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd �|�ttjd!�|jtd"tjd#dd�|jtd$tjd%dd�|�td&�|jttjd'dd�|jtd(tjd)dd�|jtd*tjd+dd�|jttjd,dd�|jttjd-dd�|jttjd.dd�|jttjd/dd�|jtd0tjd1dd�|jtd0tjd2dd�|jttjd3dd�|jttjd4dd�|jttjd5dd�|jttjd6dd�|jttjd7dd�|jttjd8dd�|jttjd9dd�|jttjd:dd�|jttjd;dd�|jtd<tjd=dd�|jtd<tjd>dd�|jtd<tjd?dd�|jtd$tjddd�|jttjd%dd�|jtd$tjd@dd�|jttjdAdd�dS)BNzM%(levelname)-15s - %(message) 5s - %(process)03d - %(module) - %(asctime)*.3sz1%(asctime)*s - %(asctime)*.3s - %(process)-34.33oz%(process)#+027.23Xz
%(foo)#.*gz5$%{message}%$ - {asctime!a:15} - {customfield['key']}rfrgz{process:.2f} - {custom.f:.4f}z{customfield!s:#<30}z{message!r}z{message!s}z{message!a}z{process!r:4.2}z8{process!s:<#30,.12f}- {custom:=+#30,.1d} - {module:^30}z{process!s:{w},.{p}}z{foo:12.{p}}z{foo:{w}.6}z{foo[0].bar[1].baz}z{foo[k1].bar[k2].baz}z{12[k1].bar[k2].baz}z${asctime} - $messager�z$bar $$z	$bar $$$$z%(asctime)Zz%(asctime)bz%(asctime)*z
%(asctime)*3sz%(asctime)_rirkz
%(foo)#12.3*fz%(foo)0*.8*fz+invalid field name/expression: 'name-thing'z{name-thing}zinvalid format: no fieldsrazinvalid conversion: 'Z'z{asctime!s:#30,15f}z7invalid format: expected ':' after conversion specifierz{asctime!aa:15}zbad specifier: '.2ff'z{process:.2ff}z
{process:.2Z}z{process!s:<##30,12g}z{process!s:<#30#,12g}z{process!s:{{w}},{{p}}}z,invalid format: unmatched '{' in format specz{processzprocess}z{{foo!r:4.2}z
{{foo!r:4.2}}z	{foo/bar}z{foo:{{w}}.{{p}}}}z{foo!X:{{w}}.{{p}}}z{foo!a:random}z{foo!a:ran{dom}z{foo!a:ran{d}om}z
{foo.!a:d}z$invalid format: bare '$' not allowedz$bar $$$zbar $zfoo $.rOz	${asctime)rr/rI�_fmtr�r�r`�r8r�r:r:r;�test_format_validate�s(



������������z"FormatterTest.test_format_validatecCs|�ttjddd�dS)N�x)r�r�rr/rYr:r:r;�test_invalid_stylemsz FormatterTest.test_invalid_stylec
Cs�|��}t�dddddddt�}t�|�d����|_d|_t	�
d�}tj|_|�
|�|�d	�|�
|�|d
�d�|�|�|�
|jd	�dS)Ni�r
��r�r�{�%(asctime)s %(message)sz1993-04-21 08:03:00,123z%Y:%dz1993:21)r_�datetime�utcr�mktimeZ
astimezoneZ	timetuple�created�msecsrr/�gmtime�	converterrI�
formatTimer��asctime)r8r�rSr�r:r:r;�	test_timeps

zFormatterTest.test_time)N)r[r\r]r<r_r`rerjrlrorqrr:r:r:r;rW�s
rWc@seZdZdd�Zdd�ZdS)�TestBufferingFormattercCsdt|�S)Nz[(%d)�rJ�r8�recordsr:r:r;�formatHeadersz#TestBufferingFormatter.formatHeadercCsdt|�S)Nz(%d)]r�r�r:r:r;�formatFooter�sz#TestBufferingFormatter.formatFooterN)r[r\r]r�r�r:r:r:r;r�~sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�BufferingFormatterTestcCs"t�ddi�t�ddi�g|_dS)Nr�r<r=)rr�r�rYr:r:r;r<�s�zBufferingFormatterTest.setUpcCs2t��}|�d|�g��|�d|�|j��dS)NrZonetwo)r�BufferingFormatterrIr�r�rnr:r:r;�test_default�sz#BufferingFormatterTest.test_defaultcCsDt�}|�d|�|j��t�d�}t|�}|�d|�|j��dS)Nz[(2)onetwo(2)]z
<%(message)s>z[(2)<one><two>(2)])r�rIr�r�rr/)r8r�Zlfr:r:r;�test_custom�s

z"BufferingFormatterTest.test_customN)r[r\r]r<r�r�r:r:r:r;r��sr�c@seZdZdd�ZdS)�
ExceptionTestcCs�|j}t�}|�|�ztd��Wntjddd�YnX|�|�|��|jd}|�	|j
�d��|�	|j
�d��|�	|j
�d��|�	|j
�d	��dS)
NrFZfailedT��
stack_inforz#Traceback (most recent call last):
z!
RuntimeError: deliberate mistake�Stack (most recent call last):
z,logging.exception('failed', stack_info=True))r%�RecordingHandlerr6rGrr�r>r=r�r7�exc_textr�r�r�)r8r�rBr:r:r;r.�s


zExceptionTest.test_formattingN)r[r\r]r.r:r:r:r;r��sr�c@seZdZdd�ZdS)�LastResortTestc	Cs,|j}|�|j�tj}tj}z�t���:}|�	d�|�
|��d�|�d�|�
|��d�W5QRXdt_t���$}|�d�d}|�
|��|�W5QRXt��� }|�d�|�
|��d�W5QRXd|j
_dt_t��� }|�d�|�
|��d�W5QRXW5|�|j�|t_|t_XdS)NzThis should not appearrz
Final chance!zFinal chance!
z-No handlers could be found for logger "root"
F)r%r>r.r�
lastResortrQr6rrSrwrIrGrur�emittedNoHandlerWarning)r8rZold_lastresortZold_raise_exceptionsrUr�r:r:r;�test_last_resort�s4








zLastResortTest.test_last_resortN)r[r\r]r�r:r:r:r;r��sr�c@seZdZdd�Zdd�ZdS)�FakeHandlerc	Cs$dD]}t|||�|||��qdS)N)r*�flushr=r+)�setattr�record_call)r8�
identifier�calledrr:r:r;r%�szFakeHandler.__init__cs���fdd�}|S)Ncs��d�����dS)Nz{} - {})r�r�r:�r�r��method_namer:r;�inner�sz&FakeHandler.record_call.<locals>.innerr:)r8r�r�r�r�r:r�r;r��szFakeHandler.record_callN)r[r\r]r%r�r:r:r:r;r��sr�cs$eZdZ�fdd�Zdd�Z�ZS)r�cstt|�j||�g|_dSr�)r$r�r%r�)r8r
r�r(r:r;r%�szRecordingHandler.__init__cCs|j�|�dS)z&Keep track of all the emitted records.N)r�r�r�r:r:r;r��szRecordingHandler.handle)r[r\r]r%r�r-r:r:r(r;r��sr�cs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Z�ZS)"�ShutdownTestz#Test suite for the shutdown method.cs.tt|���g|_tj}|�ttd|�dS)NrQ)r$r�r<r�rrQr�r�)r8Zraise_exceptionsr(r:r;r<�szShutdownTest.setUpcs�fdd�}|S)Ncs
���dSr�r:r:�rtr:r;r��sz'ShutdownTest.raise_error.<locals>.innerr:)r8rtr�r:r�r;�raise_error�szShutdownTest.raise_errorcCsvtd|j�}td|j�}td|j�}ttjj|||g�}tjt|�d�ddddd	d
ddd
dddg}|�||j�dS)NrrWr���handlerListz2 - acquirez	2 - flushz	2 - closez2 - releasez1 - acquirez	1 - flushz	1 - closez1 - releasez0 - acquirez	0 - flushz	0 - close�0 - release)	r�r�r^rr`rar}rJrI)r8Zhandler0Zhandler1Zhandler2r4rSr:r:r;�test_no_failure�s �zShutdownTest.test_no_failurecCsRtd|j�}t|||�|��tj�|�g}tjt|�d�|�	d|jd�dS)Nrr�r�r�)
r�r�r�r�rr`rar}rJrI)r8rrtr�r4r:r:r;�_test_with_failure_in_methods
z)ShutdownTest._test_with_failure_in_methodcCs|�dt�dS�Nr*�r�r�rYr:r:r;�test_with_ioerror_in_acquiresz)ShutdownTest.test_with_ioerror_in_acquirecCs|�dt�dS�Nr�r�rYr:r:r;�test_with_ioerror_in_flushsz'ShutdownTest.test_with_ioerror_in_flushcCs|�dt�dS�Nr=r�rYr:r:r;�test_with_ioerror_in_closesz'ShutdownTest.test_with_ioerror_in_closecCs|�dt�dSr��r�r�rYr:r:r;�test_with_valueerror_in_acquiresz,ShutdownTest.test_with_valueerror_in_acquirecCs|�dt�dSr�r�rYr:r:r;�test_with_valueerror_in_flush!sz*ShutdownTest.test_with_valueerror_in_flushcCs|�dt�dSr�r�rYr:r:r;�test_with_valueerror_in_close$sz*ShutdownTest.test_with_valueerror_in_closecCsdt_|�dt�dS)NFr*�rrQr��
IndexErrorrYr:r:r;�.test_with_other_error_in_acquire_without_raise'sz;ShutdownTest.test_with_other_error_in_acquire_without_raisecCsdt_|�dt�dS)NFr�r�rYr:r:r;�,test_with_other_error_in_flush_without_raise+sz9ShutdownTest.test_with_other_error_in_flush_without_raisecCsdt_|�dt�dS)NFr=r�rYr:r:r;�,test_with_other_error_in_close_without_raise/sz9ShutdownTest.test_with_other_error_in_close_without_raisecCsdt_|�t|jdt�dS)NTr*�rrQr�r�r�rYr:r:r;�+test_with_other_error_in_acquire_with_raise3s

�z8ShutdownTest.test_with_other_error_in_acquire_with_raisecCsdt_|�t|jdt�dS)NTr�r�rYr:r:r;�)test_with_other_error_in_flush_with_raise8s

�z6ShutdownTest.test_with_other_error_in_flush_with_raisecCsdt_|�t|jdt�dS)NTr=r�rYr:r:r;�)test_with_other_error_in_close_with_raise=s

�z6ShutdownTest.test_with_other_error_in_close_with_raise)r[r\r]r^r<r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r-r:r:r(r;r��s"	r�c@sxeZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
ejdd��Zdd�ZdS)�ModuleLevelMiscTestz)Test suite for some module level methods.cCs�tjjj}|�|d�|�tj|�t�d�|�tjjjd�|�ttjd�Gdd�d�}|�ttj|��t�d�t��|�tjjjtj	�dS)Nr�SZ
doesnotexistsc@seZdZdS)z;ModuleLevelMiscTest.test_disable.<locals>._NotAnIntOrStringNr�r:r:r:r;�_NotAnIntOrStringRsr��WARN)
rrrrArIr�r�r�rrc)r8�old_disabler�r:r:r;�test_disableGs


z ModuleLevelMiscTest.test_disableNcs�g�t�|td�fdd��t�}tj�|�tt|�}|dk	rN||d|�n
|d|�|�t|j	�d�|j	d}|�|�
�d|�|dk	r�|ntt|���}|�|j|�|��g�dS)N�basicConfigcs��||f�Sr�r)r�kw�r�r:r;�<lambda>a�z/ModuleLevelMiscTest._test_log.<locals>.<lambda>ztest me: %rrWr)
rr9rr�rr6r"rIrJr��
getMessage�upperr�)r8rrO�	recording�
log_methodr�Zexpected_levelr:r�r;�	_test_log^s 

�


zModuleLevelMiscTest._test_logcCs|�dtj�dS�Nrs)r�rrerYr:r:r;�test_logvszModuleLevelMiscTest.test_logcCs|�d�dS�Nrw�r�rYr:r:r;�
test_debugyszModuleLevelMiscTest.test_debugcCs|�d�dS�Nrvr�rYr:r:r;�	test_info|szModuleLevelMiscTest.test_infocCs|�d�dS�Nrur�rYr:r:r;�test_warningsz ModuleLevelMiscTest.test_warningcCs|�d�dS�Nrtr�rYr:r:r;�
test_error�szModuleLevelMiscTest.test_errorcCs|�d�dS�Nr�r�rYr:r:r;�
test_critical�sz!ModuleLevelMiscTest.test_criticalcCs^|�ttjt�Gdd�dtj�}t�|�|�t��|�t�tj�|�t��tj�dS)Nc@seZdZdS)z;ModuleLevelMiscTest.test_set_logger_class.<locals>.MyLoggerNr�r:r:r:r;r�sr)r�rrrrr	rI�getLoggerClass)r8rr:r:r;�test_set_logger_class�s
z)ModuleLevelMiscTest.test_set_logger_classc	s�g�G�fdd�dt���}t�|�t�d�}|��dg�t��}t�|�}|�|�zh|�tj
�|�d�|�|����d�|�d�|�d�|�tj�|�d�|�|��d�W5|�	|�|�
�t�tj�XdS)Ncs&eZdZdejf��fdd�	Z�ZS)z@ModuleLevelMiscTest.test_subclass_logger_cache.<locals>.MyLoggerrcst��||���d�dS)N�initialized)r$r%r�)r8r9rO)r)rsr:r;r%�szIModuleLevelMiscTest.test_subclass_logger_cache.<locals>.MyLogger.__init__)r[r\r]rr�r%r-r:�rsr(r;r�srZjust_some_loggerr�Zhellorr)rr�rrrIr(r)r-r6r>r=r	r+r,rwrGr�truncater�rk)r8rr�r*rBr:r�r;�test_subclass_logger_cache�s(








z.ModuleLevelMiscTest.test_subclass_logger_cachecCs8d}td|�\}}}|��}|�d|�|�d|�dS)Na&if 1:
            import logging

            class A:
                def __del__(self):
                    try:
                        raise ValueError("some error")
                    except Exception:
                        logging.exception("exception in __del__")

            a = A()�-czexception in __del__zValueError: some error)rrYrT�r8�code�rc�out�errr:r:r;�test_logging_at_shutdown�s
z,ModuleLevelMiscTest.test_logging_at_shutdowncCs8d}td|�\}}}|��}|�d|�|�|d�dS)Nz�if 1:
            import logging

            def rec():
                logging.error("foo")
                rec()

            rec()r�z#Cannot recover from stack overflow.rW)rrYZassertNotInrIr�r:r:r;�test_recursion_error�s
z(ModuleLevelMiscTest.test_recursion_error)N)r[r\r]r^r�r�r�r�r�r�r�r�r�r�rZrequires_type_collectingr�r�r:r:r:r;r�Cs

r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
LogRecordTestcCs6t�i�}t|�}|�|�d��|�|�d��dS)Nz<LogRecord: �>)rr�r�r7r�r�)r8r�rUr:r:r;�test_str_rep�s
zLogRecordTest.test_str_repcCsjt�}t��}|�|�ddi}t�d|�|�|jdj|�|�|jdj	d�|�
|�|��dS)NZlessZmorezless is %(less)srzless is more)r�rrr6rurRr�r
rIrsr>r=)r8rBr�r\r:r:r;�
test_dict_arg�s

zLogRecordTest.test_dict_argcCs\t�i�}|�|jd�z*ddl}t�i�}|�|j|��j�Wntk
rVYnXdS)N�MainProcessr)rr�rI�processNamerG�current_processr9rV)r8r��mpr:r:r;�test_multiprocessing�s

z"LogRecordTest.test_multiprocessingcCs�t�i�}|j}||j�||j�||j�||j�tj}tj}tj	}zNdt_dt_dt_	t�i�}|j
}||j�||j�||j�||j�W5|t_|t_|t_	XdS)NF)rr��assertIsNotNoner��
threadName�processr��
logThreads�logProcesses�logMultiprocessingrX)r8r�ZNOT_NONEZlog_threadsZ
log_processesZlog_multiprocessing�NONEr:r:r;�
test_optional�s,








zLogRecordTest.test_optionalN)r[r\r]r�r�r�r�r:r:r:r;r��s
r�cs�eZdZdZ�fdd�Z�fdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd1d#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z�ZS)2�BasicConfigTestz#Test suite for logging.basicConfig.csVtt|���tjj|_tj��|_tj	dd�|_
tjj|_|�
|j�gtj_dSr�)r$r�r<rrr4rrrrrrOr'r�r�rYr(r:r;r<s

zBasicConfigTest.setUpcs<tjjdd�D]}tj�|�|��qtt|���dSr�)rrr4r>r=r$r�rCr�r(r:r;rCs
zBasicConfigTest.tearDowncCsJttjd|j�tj��tj�|j�|jtj	dd�<tj�
|j�dS)Nr4)r�rrr4rr?r@rrrr+r'rYr:r:r;r�s

zBasicConfigTest.cleanupcCs�t��|�ttjj�d�tjjd}|�|tj�|�|jt	j
�|j}|�|jj
tj�|�|j�|�|jtj�|�tjj|j�dS)NrWr)rr�rIrJrr4r�r-r*r�rUr�r�rm�BASIC_FORMATrXr�PercentStylerOr')r8r�r�r:r:r;�test_no_kwargs%szBasicConfigTest.test_no_kwargsc	CsRt���@}tjtjdd�t�d�tj�d�|�|�	��
�d�W5QRXdS)Nrf�r*r��Log an errorr�ERROR:root:Log an error�rr�rr�r�r�rtr�rIrGrr�r:r:r;�test_strformatstyle9s

�z#BasicConfigTest.test_strformatstylec	CsRt���@}tjtjdd�t�d�tj�d�|�|�	��
�d�W5QRXdS)Nr�r�r�rr�r�r�r:r:r;�test_stringtemplatestyleAs

�z(BasicConfigTest.test_stringtemplatestylecCs�dd�}tjdd�|�ttjj�d�tjjd}|�|tj�t�dd�}|�|jj	|jj	�|�|jj
|jj
�|�|||d�dS)NcSs|��|��t�|�dSr�r��r�Zh2r�r:r:r;r�Ksz.BasicConfigTest.test_filename.<locals>.cleanup�test.log)r�rWrr)rr�rIrJrr4r�rr*�moder9r��r8r�r�rSr:r:r;�
test_filenameIszBasicConfigTest.test_filenamecCsVdd�}tjddd�tjjd}t�dd�}|�|jj|jj�|�|||d�dS)NcSs|��|��t�|�dSr�r�r�r:r:r;r�]sz.BasicConfigTest.test_filemode.<locals>.cleanupr�wb�r��filemoder)	rr�rr4rrIr*rr�rr:r:r;�
test_filemode[szBasicConfigTest.test_filemodecCs`t��}|�|j�tj|d�|�ttjj	�d�tjj	d}|�
|tj�|�|j|�dS)Nr#rWr)
r(r)r�r=rr�rIrJrr4r�r-r*)r8r*r�r:r:r;�test_streamiszBasicConfigTest.test_streamcCs.tjdd�tjjdj}|�|jjd�dS)Nz%(asctime)s - %(message)s)r�r)rr�rr4r�rIr�rm�r8r�r:r:r;�test_formatsszBasicConfigTest.test_formatcCs,tjdd�tjjdj}|�|jd�dS)NrP)rr)rr�rr4r�rIrr	r:r:r;�test_datefmtyszBasicConfigTest.test_datefmtcCs.tjdd�tjjdj}|�|jtj�dS)Nr�rgr)rr�rr4r�r�r�r�r	r:r:r;�
test_styleszBasicConfigTest.test_stylecCsTtjj}|�tjj|�tjdd�|�tjjd�tjdd�|�tjjd�dS)N�9)rO�:)rrrOr�r+r�rI)r8�	old_levelr:r:r;�
test_level�szBasicConfigTest.test_levelcCsp|j}t��g}tj}|ttjd|d�|ttjd|d�|ttj||d�|ttjtjd�tjddd�dS)Nr)r�r*)r�r4)r*r4)Zloglevelrr)r�rr-r�rUr�r�rk)r8r�r4r*r:r:r;�test_incompatible�s

�
�
�z!BasicConfigTest.test_incompatiblecCs�t��t�tj�t��g}t��}|d�|�tj|d�|�|dtjj	d�|�|dtjj	d�|�|dtjj	d�|�
|dj�|�
|dj�|�|dj|�|�|dj|dj�dS)Nr�)r4rrW)rr-r�r�r/r2r�rRrr4r�r�)r8r4r�r:r:r;�
test_handlers�s
�zBasicConfigTest.test_handlerscCs�t��}t��}t�|�g}t�|�g}tjtj|d�t�d�t�d�t�d�|�	t
tjj�d�tjtj
|dd�t�d�t�d�t�d�|�	t
tjj�d�|�	|����d�|�	|����d	�dS)
Nr�r�rvrwrWT)rOr4�forcezWARNING:root:warnz WARNING:root:warn
INFO:root:info)r(r)rr-r�rirurvrwrIrJrr4rkrGr)r8Z
old_string_ioZ
new_string_ioZold_handlersZnew_handlersr:r:r;�
test_force�s,



�


��zBasicConfigTest.test_forceNcsfg�tj����fdd�}t��td|�tt|�}|dk	rH||d�n|d����difg�dS)Ncs<��tjj}tj�d���tjj|���||f�dS)N�d)rrrOr+r�r�)rr�r�r�Zold_basic_configr8r:r;�my_basic_config�s
z2BasicConfigTest._test_log.<locals>.my_basic_configr�ztest mer:)rr�rr9r"rI)r8rrOrr�r:rr;r��s
zBasicConfigTest._test_logcCs|�dtj�dSr�)r�rrirYr:r:r;r��szBasicConfigTest.test_logcCs|�d�dSr�r�rYr:r:r;r��szBasicConfigTest.test_debugcCs|�d�dSr�r�rYr:r:r;r��szBasicConfigTest.test_infocCs|�d�dSr�r�rYr:r:r;r��szBasicConfigTest.test_warningcCs|�d�dSr�r�rYr:r:r;r��szBasicConfigTest.test_errorcCs|�d�dSr�r�rYr:r:r;r��szBasicConfigTest.test_critical)N)r[r\r]r^r<rCr�r�r�r�rrrr
rrrrrrr�r�r�r�r�r�r�r-r:r:r(r;r�s0	


r�csLeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)�LoggerAdapterTestcs�tt|���tjdd��t�|_tj|_|j�	|j�|�
|jj|j�|�
|jj��fdd�}|�
|�|�
tj
�tj|jdd�|_dS)Ncs�tjdd�<dSr�)rrr:�Zold_handler_listr:r;r��sz(LoggerAdapterTest.setUp.<locals>.cleanup�r�r)r$rr<rrr�r�rr�r6r�r>r=r}rr�adapter)r8r�r(rr;r<�s
zLoggerAdapterTest.setUpc
Cs�d}d}zddWn6tk
rJ}z|}|j�||j�W5d}~XYnX|�t|jj�d�|jjd}|�|jtj	�|�|j
|�|�|j|jf�|�|j|j
||jf�dS�Nztesting exception: %rrWr)r4rr�r�rIrJr�r�rrer�r
rr)�
__traceback__�r8r�r5r�r�r:r:r;�test_exceptions"�z LoggerAdapterTest.test_exceptionc
Cs�zddWn&tk
r2}z|}W5d}~XYnX|jjd|d�|�t|jj�d�|jjd}|�|j|j||j	f�dS)NrWrz
exc_info testr3)
r4rr�rIrJr�r�rr)r)r8r�r5r�r:r:r;�test_exception_excinfos�z(LoggerAdapterTest.test_exception_excinfocCshd}|j�||j�|�t|jj�d�|jjd}|�|jtj�|�|j	|�|�|j
|jf�dS)Nzcritical test! %rrWr)rr�r�rIrJr�r�rrcr�r
)r8r�r�r:r:r;r�szLoggerAdapterTest.test_criticalcCsD|jjjj}d|jjj_|�t|jjjd|�|�|j�d��dS)N�!rA� )rr�rrAr�r�r��isEnabledFor�r8r�r:r:r;�test_is_enabled_for(s�z%LoggerAdapterTest.test_is_enabled_forcCsN|�|j���|jjD]}|j�|�q|�|j���|�|j���dSr�)r7rr3r�r4r>r�r�r:r:r;�test_has_handlers/s
z#LoggerAdapterTest.test_has_handlerscCsLGdd�dtj�}d}||jdd�}||dd�}d|_|�t|�t|��|�tj||j�|�t	|jj
�d�|jj
d}|�|jtj�|�|jd|���|�|j
|jf�|j}|�|j|�|�|jj|�t�}z6||_|�|j|�|�|j|�|�|jj|�W5||_X|�|j|�|�|j|�|�|jj|�dS)	Nc@seZdZdZdd�ZdS)z.LoggerAdapterTest.test_nested.<locals>.Adapter�AdaptercSs|j�d|��|fSr�)r�)r8r�r�r:r:r;r�<sz6LoggerAdapterTest.test_nested.<locals>.Adapter.processN)r[r\r]r�r�r:r:r:r;r'9sr'zAdapters can be nested, yo.rZAdapterAdapterrWrzAdapter AdapterAdapter )rrrr�r�rIr[rsrcr�rJr�r�r�r
rrRr)r8r'r�rZadapter_adapterr�Zorig_managerZtemp_managerr:r:r;�test_nested8s2zLoggerAdapterTest.test_nested)r[r\r]r<rr r�r%r&r(r-r:r:r(r;r�s

	rcs�eZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Z�ZS)#�
LoggerTestcsbtt|���t�|_tjdd�|_|j�|j�|�	|jj
|j�|�	|jj�|�	tj�dS)NZblah�r9)
r$r)r<r�r�rr	r�r6r�r>r=r}rYr(r:r;r<\szLoggerTest.setUpcCs|�t|jjt��dSr�)r�rr�r+rrYr:r:r;�test_set_invalid_levelesz!LoggerTest.test_set_invalid_levelc
Cs�d}d}zddWn6tk
rJ}z|}|j�||j�W5d}~XYnX|�t|jj�d�|jjd}|�|jtj	�|�|j
|�|�|j|jf�|�|j|j
||jf�dSr)r4r�r�r�rIrJr�r�rrer�r
rr)rrr:r:r;rhs"�zLoggerTest.test_exceptionc	Cs2t�tdd��|�t|jjdd�W5QRXdS)NrQTrp�test message)r�	swap_attrrr�rr�rsrYr:r:r;�!test_log_invalid_level_with_raiseysz,LoggerTest.test_log_invalid_level_with_raisec	Cs,t�tdd��|j�dd�W5QRXdS)NrQFrpr,)rr-rr�rsrYr:r:r;�test_log_invalid_level_no_raise}sz*LoggerTest.test_log_invalid_level_no_raisecsPg�t�|tjd�fdd��|jjdd�|�t��d�|�d�d�dS)	N�print_stackcs��|���Sr�)r�rG)r�r�r�r:r;r��r�z=LoggerTest.test_find_caller_with_stack_info.<locals>.<lambda>Tr�rWr�r)rr9r�	tracebackr��
findCallerrIrJrYr:r�r;� test_find_caller_with_stack_info�s
�z+LoggerTest.test_find_caller_with_stack_infocsd���fdd���fdd���fdd�}�jj}|���|djd	�|dj}�d7�|���|djd
���|dj|�|dj}�d7�|���|djd���|dj|�|dj}�d7�|���|djd���|dj|�dS)
NrWcs�jjd�d�dS)Nri)�
stacklevel)r�rur:)r8�	the_levelr:r;�	innermost�sz>LoggerTest.test_find_caller_with_stacklevel.<locals>.innermostcs
��dSr�r:r:)r6r:r;r��sz:LoggerTest.test_find_caller_with_stacklevel.<locals>.innercs
��dSr�r:r:)r�r:r;�outer�sz:LoggerTest.test_find_caller_with_stacklevel.<locals>.outerr�r6r�r7� test_find_caller_with_stacklevel)r�r�rIrTrZr7)r8r7r�rZr:)r�r6r8r5r;r8�s,


z+LoggerTest.test_find_caller_with_stacklevelc
Cs�d}d}d}}}}}}}	t�|||||||||	�	}
dt|
j���D]0}|di}|jt|jj|||||||||	d�qPdS)N�	my record�
)rsr~�
some value�r�sinfo)	r�_logRecordFactoryrN�__dict__�keysr�r�r��
makeRecord)
r8r9rOr��lnor�r
rr[r=�rvrbrr:r:r;�%test_make_record_with_extra_overwrite�s&��z0LoggerTest.test_make_record_with_extra_overwritecCs\d}d}d}}}}}}}	ddi}
|jj||||||||
|	d�	}|�d|j�dS)Nr9r:Z	valid_keyr;r<)r�rArTr?)r8r9rOr�rBr�r
rr[r=rr^r:r:r;�(test_make_record_with_extra_no_overwrite�s�z3LoggerTest.test_make_record_with_extra_no_overwritecCs>|�|j���|jjD]}|j�|�q|�|j���dSr�)r7r�r3r4r>r�r�r:r:r;r&�szLoggerTest.test_has_handlerscCs"t�d�}d|_|�|���dS)Nz
blah.childF)rrr�r�r3)r8Zchild_loggerr:r:r;�test_has_handlers_no_propagate�s
z)LoggerTest.test_has_handlers_no_propagatecCs>|jjj}d|jj_|�t|jjd|�|�|j�d��dS)N�rA�)r�rrAr�r�r�r#r$r:r:r;r%�s

zLoggerTest.test_is_enabled_forcCs`|jj}|jjj}d|j_d|jj_|�t|jd|�|�t|jjd|�|�|j�d��dS)NTrrrrArH)r�rrrAr�r�r�r#)r8Zold_disabledr�r:r:r;�#test_is_enabled_for_disabled_logger�s

z.LoggerTest.test_is_enabled_for_disabled_loggercCs�t��}|�|tj�|�|t�d��|�|t�d��|�|t�d�j�|�|t�d�j�|�|t�d�j�|�|t�d��|�|t�d�j�dS)NrrO�foo.bar�)rrrRr�parentZassertIsNot)r8rr:r:r;�test_root_logger_aliases�sz#LoggerTest.test_root_logger_aliasescCs$|�ttjt�|�ttjd�dS)Nsfoo)r�rrr�anyrYr:r:r;�test_invalid_names�szLoggerTest.test_invalid_namescCsNttjd�D]:}dD]0}t�|�}t�||�}t�|�}|�||�qqdS)NrW)rrrOrJzbaz.bar)rr*�HIGHEST_PROTOCOLrrr�r+rR)r8�protor9r�rUZ	unpickledr:r:r;�
test_pickling�s

zLoggerTest.test_picklingcCs6|j}t�d�}t�d�}|�tj�|�|��tj�|�|ji�|�|�	tj��|�
|�	tj��|�|jtjdtjdi�|�|ji�|�|�	tj��|�|ji�|�|�	tj��|�|jtjdi�|�tj�|�|��tj�|�|ji�|�
|�	tj��|�tj
�|�|��tj�|�|ji�|�|ji�|�|ji�|�
|�	tj��|�|�	tj��|�
|�	tj��|�|�	tj��|�|�	tj��t��|�|��tj�|�|ji�|�|ji�|�|ji�|�
|�	tj��|�
|�	tj��|�
|�	tj��dS)NrrTF)r%rrr+rerIr&�_cacher7r#r�r,rcr�rA)r8rr#r$r:r:r;�test_caching�sH

zLoggerTest.test_caching)r[r\r]r<r+rr.r/r3r8rDrEr&rFr%rIrMrOrRrTr-r:r:r(r;r)Zs"	

	r)c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�BaseFileTestz1Base class for handler tests that write log filescCs0t�|�t�dd�\}|_t�|�g|_dS)Nrztest_logging-2-)r
r<r�r�r�r�r=�rmfiles)r8r�r:r:r;r<2s

zBaseFileTest.setUpcCs>|jD]}t�|�qtj�|j�r0t�|j�t�|�dSr�)rVr�r�r�r�r�r
rC)r8r�r:r:r;rC8s

zBaseFileTest.tearDowncCs*|jtj�|�d|d�|j�|�dS)z7Assert a log file is there and register it for deletionzLog file %r does not existr6N)r7r�r�r�rVr�)r8r�r:r:r;�
assertLogFile?s�zBaseFileTest.assertLogFileN)r[r\r]r^r<rCrWr:r:r:r;rU/srUc@seZdZdd�ZdS)�FileHandlerTestcCsxt�|j�tj|jdd�}|�|j�|�tj�	|j��|�
t�i��|�|j�|�
tj�	|j��|��dS)NTr�)r�r�r�rrrXr*r�r�r�r�r�r�r7r=)r8�fhr:r:r;�
test_delayGszFileHandlerTest.test_delayN)r[r\r]rZr:r:r:r;rXFsrXc@sBeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zej	dd��Z
d
S)�RotatingFileHandlerTestc
Cst�dtjdd|��ddd�S)Nr�r�rW)rr+r,rZrYr:r:r;�next_recRs�z RotatingFileHandlerTest.next_reccCs.tjj|jdd�}|�|�d��|��dS)Nr��maxBytes)rr4rr�r��shouldRolloverr=�r8�rhr:r:r;�test_should_not_rolloverVsz0RotatingFileHandlerTest.test_should_not_rollovercCs2tjj|jdd�}|�|�|����|��dS)NrWr])rr4rr�r7r_r\r=r`r:r:r;�test_should_rollover\sz,RotatingFileHandlerTest.test_should_rollovercCs4tj�|j�}|�|���|�|j�|��dSr�)rr4rr�r�r\rWr=r`r:r:r;�test_file_createdasz)RotatingFileHandlerTest.test_file_createdcCs�dd�}tjj|jddd�}||_|�|���|�|j�|�|���|�||jd��|�|���|�||jd��|�t	j
�||jd���|��dS)	NcSs|dS)Nz.testr:r*r:r:r;�namerjsz>RotatingFileHandlerTest.test_rollover_filenames.<locals>.namerr�rW��backupCountr^�.1�.2�.3)
rr4rr�rer�r\rWr�r�r�r�r=)r8rerar:r:r;�test_rollover_filenamesis�z/RotatingFileHandlerTest.test_rollover_filenamesc	Cs�dd�}dd�}tjj|jddd�}||_||_|��}|�|�|�|j�|��}|�|�||jd�}|�|�t	j
}t|d	��0}|��}	t
�|	�}
|�|
�d
�|j|�W5QRX|�|���||jd�}|�|�t|d	��0}|��}	t
�|	�}
|�|
�d
�|j|�W5QRX|�|���||jd�}t|d	��0}|��}	t
�|	�}
|�|
�d
�|j|�W5QRX|�t	j�||jd���|��dS)
NcSs|dS)Nz.gzr:r*r:r:r;rezsz3RotatingFileHandlerTest.test_rotator.<locals>.namerc
SsXt|d��:}|��}t�|d�}t|d��}|�|�W5QRXW5QRXt�|�dS)N�rbr�r)r&rP�zlib�compressrJr�r�)�source�destZsfrI�
compressed�dfr:r:r;�rotator}sz5RotatingFileHandlerTest.test_rotator.<locals>.rotatorr�rWrfrhrlrrirj)rr4rr�rsrer\r�rWr��linesepr&rPrm�
decompressrIrYr�r�r�r�r=)r8rersraZm1Zm2r��newliner�rqrIr:r:r;�test_rotatorxsH�



"

"
"z$RotatingFileHandlerTest.test_rotatorN)r[r\r]r\rbrcrdrkrZ
requires_zlibrwr:r:r:r;r[Qsr[c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TimedRotatingFileHandlerTestc
s�tjj|jddd�}t�d�}|�|�t�ddi�}|�|�|�|j�t	�
d�t�ddi�}|�|�|��d	}tj�
�}d
}t|�D]D}|tj|d�}	|j|	�d��tj���}|r�|j���q�q�d
|}
|�s�tj�|j�\}��fdd�t�|�D�}td|�d�tjd�td|tjd�|D]B}
td|
�tj�||
�}t|d��}t|���W5QRX�q<|j||
d�dS)N�SrW)rgrur�ztesting - initialg�������?ztesting - after delayFi,�Zsecondsz.%Y-%m-%d_%H-%M-%Sz,No rotated files found, went back %d secondscsg|]}|���r|�qSr:)r�)r�r��r�r:r;r��s
z>TimedRotatingFileHandlerTest.test_rollover.<locals>.<listcomp>z
Test time: %sz%Y-%m-%d %H-%M-%S�r�zThe only matching files are: %szContents of %s:r�r6)rr4rr�r/r2r�r�rWrrr=rvr5r�	timedelta�strftimer�r�r�rVr�r��listdirr r�rUr�r&rPr7)r8rYr�Zr1Zr2�foundr5�GO_BACK�secs�prevr�Zdn�filesr�r�Ztfr:r{r;�
test_rollover�sD�





z*TimedRotatingFileHandlerTest.test_rollovercCsR|j}|ttjj|jddd�|ttjj|jddd�|ttjj|jddd�dS)N�XTr��WZW7)r�r�rr4rr�)r8r�r:r:r;�test_invalid�s 
�
�
�z)TimedRotatingFileHandlerTest.test_invalidcCsxd}t�ddd�}tjj|jdddd|d�}z<|�|�}|�||d�|�|d�}|�||d	�W5|��XdS)
Nr��MIDNIGHTrWT��when�intervalrgrw�atTime��жi@�)	rvrrr4rr�r=�computeRolloverrI)r8�currentTimer�rarRr:r:r;�"test_compute_rollover_daily_attime�s �
z?TimedRotatingFileHandlerTest.test_compute_rollover_daily_attimec		Cs2tt���}||d}t�ddd�}t�|�j}td�D]�}tjj|j	d|ddd|d�}z�||krtd||}n||}|d9}|d	7}||7}|�|�}||kr�td
tj
�tdt��|�||�||kr�|d7}|�|d
�}||k�rtd
tj
�tdt��|�||�W5|�
�Xq:dS)N�Qr�rr5zW%drWTr�r�zfailed in timezone: %dzlocal vars: %si�:	r�)rLrrvr{�tm_wdayrrr4rr�r=r�r �timezone�localsrI)	r8r�Ztodayr�ZwdayZdayrarSrRr:r:r;�#test_compute_rollover_weekly_attime�sB�

z@TimedRotatingFileHandlerTest.test_compute_rollover_weekly_attimeN)r[r\r]r�r�r�r�r:r:r:r;rx�s*	rxcKstjf|�tjdd�S)NrWrz)rvr})r�r:r:r;r�sr�)ryrW)�M�<)�Hi)�Dr�)r�r�ZW0r
�)ZdaysZhourscCsRtjj|j|dddd�}d}|�|�}||k�r:|dk�r:z�|jrNt�|�}n
t�|�}|d}|d}|d	}	tjj	|d
|d
|	}
||
}t
d||jftjd�t
d
|tjd�t
d|tjd�t
d|	tjd�t
d|
tjd�t
d|tjd�Wn0t
k
�r8t
dt��dtjd�YnX|�||�|��dS)NrWrT)r�r�rgrwgr�r�r
r�r�z
t: %s (%s)r|zcurrentHour: %szcurrentMinute: %szcurrentSecond: %szr: %sz
result: %sz exception in diagnostic code: %s)rr4rr�r�rwrr{�	localtimeZ	_MIDNIGHTr r�rUrrrIr=)r8r��exprar�rRrrZcurrentHourZ
currentMinuteZ
currentSecondr�r^r:r:r;�test_compute_rolloversH�



��� r�ztest_compute_rollover_%sz>win32evtlog/win32evtlogutil/pywintypes required for this test.c@seZdZdd�ZdS)�NTEventLogHandlerTestc
Csd}t�d|�}t�|�}ztj�d�}Wn:tjk
rd}z|jdkrRt	�
d���W5d}~XYnXt�ddi�}|�|�|�
�|�|t�|��tjtjB}d}d}	t�|||	�}
|
D].}|jdkr�q�t�||�}|d	kr�q�d
}q�q�d|	}|j||d�dS)
NZApplicationZtest_loggingr�z#Insufficient privileges to run testr�zTest Log MessageFrzTest Log Message
Tz3Record not found in event log, went back %d recordsr6)�win32evtlogZOpenEventLogZGetNumberOfEventLogRecordsrr4ZNTEventLogHandler�
pywintypesrt�winerrorrCZSkipTestr�r�r=Z
assertLessZEVENTLOG_BACKWARDS_READZEVENTLOG_SEQUENTIAL_READZReadEventLogZ
SourceName�win32evtlogutilZSafeFormatMessager7)r8ZlogtypeZelhZnum_recsrBr�r��flagsr�r��eventsr�r:r:r;r�Ds:



�
z NTEventLogHandlerTest.test_basicN)r[r\r]r�r:r:r:r;r�Bsr�c@seZdZdd�ZdS)�MiscTestCasec
Cs2ddddddddd	d
ddd
h
}tj|t|d�dS)Nr�r�r��currentframer��StrFormatStyler��Filterer�PlaceHolderr
�
RootLoggerrr)�	blacklist)rZcheck__all__r)r8r�r:r:r;�test__all__gs�zMiscTestCase.test__all__N)r[r\r]r�r:r:r:r;r�fsr��LC_ALLrc'Csvtttttttttt	t
ttt
ttttttttttttttttttt t!t"t#t$t%t&g'}t't(j)d�rh|�*t+�t,j-|�dS)Nr/).r_r�r�r�r�r�rr9r]rhrvr�rrWr�rPrrr#r�r�r�rr)r�rXr[r�r�r�r@rErHr�rxr8r>rDr�rDrr4r�r:rZrun_unittest)Ztestsr:r:r;�	test_mainssV�
r��__main__)N)�r^rZlogging.handlersZlogging.configrpr�rrvrr*r(rdr�r�r$rrDr?rar(r�r�Ztest.support.script_helperrrrirr�rrrCr}r`rtZhttp.serverrrr_Zurllib.parserr�socketserverr	r
rrr�r�r�rVrmZTestCaser
r_r�ZSILENTr�ZTERSEZEFFUSIVEr�r�Z	TALKATIVEr�Z
CHATTERBOXZBORINGrr�r�r�r�r�r�r�rrEr-rKrNrPr`r]r{rr�r�rDr�r�r�r�r/r�r�rr7r8r8r9r>r@rDZIPV6_ENABLEDrErHr]rhrvr�r�r�r�r�rrr+rrr#r4rGZ
unittest.mockr9r:r}rQZtzinforPrwrWr�r�r�r�r�r�r�r�r�r�r�r�rr)rUrXr[rxr�r�r�r�r�r�r�Zrun_with_localer�r[r:r:r:r;�<module>spmF�
Y_,M5)/ hJY@C�M41(
W#i`
	w'W5dlVTn�!
#




F1le Man4ger