B
    u9aÀ’ ã               @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZ ddlmZ ddlZddlZddlZddlZddlZddlZddl Z ddl!m"Z"m#Z# ddl$Z$ddl%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z, yddl-Z-ddl.Z.ddl/Z/W n" e0k
rv   d Z- Z.Z/Y nX yddl1Z1W n e0k
rš   Y nX G dd	„ d	ej2ƒZ3G d
d„ de3ƒZ4G dd„ de3ƒZ5dZ6dZ7dZ8dZ9dZ:dZ;dZ<dZ=dZ>dZ?e@e?e6d ƒZAe6de7de8de9de:de;de<de=d e>d!e?d"i
ZBG d#d$„ d$ejCƒZDG d%d&„ d&ejCƒZEG d'd(„ d(e3ƒZFG d)d*„ d*e3ƒZGG d+d,„ d,eHƒZIG d-d.„ d.ejJƒZKG d/d0„ d0eHƒZLG d1d2„ d2e3ƒZMG d3d4„ d4e$jNƒZOG d5d6„ d6eHƒZPG d7d8„ d8ePe"ƒZQG d9d:„ d:ePe+ƒZRG d;d<„ d<ePe)ƒZSeTed=ƒr:G d>d?„ d?eRƒZUG d@dA„ dAeSƒZVG dBdC„ dCe3ƒZWG dDdE„ dEe3ƒZXG dFdG„ dGejYƒZZG dHdI„ dIe3ƒZ[G dJdK„ dKe3ƒZ\dLdM„ Z]e ^eTed=ƒdN¡G dOdP„ dPe\ƒƒZ_G dQdR„ dRe3ƒZ`e ^eTed=ƒdN¡G dSdT„ dTe`ƒƒZaG dUdV„ dVe3ƒZbe ^eTed=ƒdN¡G dWdX„ dXebƒƒZce ^ejddY¡G dZd[„ d[ebƒƒZeG d\d]„ d]e3ƒZfG d^d_„ d_e3ƒZgG d`da„ dae3ƒZhG dbdc„ dce3ƒZid¶ddde„Zjdfdg„ ZkG dhdi„ diejJƒZlG djdk„ dke3ƒZmG dldm„ dme3ƒZnG dndo„ doe3ƒZoG dpdq„ dqejpƒZqG drds„ dse3ƒZrG dtdu„ due3ƒZseTejtdvƒr0ddluZuddwlvmwZw G dxdy„ dye3ƒZxe yd¡ZzG dzd{„ d{ej{ƒZ|e|ƒ Z}G d|d}„ d}ej2ƒZ~G d~d„ dejƒZ€G d€d„ dej2ƒZG d‚dƒ„ dƒe3ƒZ‚G d„d…„ d…e3ƒZƒG d†d‡„ d‡ƒZ„G dˆd‰„ d‰ej…ƒZ†G dŠd‹„ d‹e3ƒZ‡G dŒd„ de3ƒZˆG dŽd„ de3ƒZ‰G dd‘„ d‘ej2ƒZŠG d’d“„ d“ej2ƒZ‹G d”d•„ d•e3ƒZŒG d–d—„ d—e3ƒZG d˜d™„ d™eƒZŽG dšd›„ d›eƒZG dœd„ deƒZdždŸ„ Z‘xHd d¡d¢d£d¤d¥e‘d¦d§d¨ffD ](\Z’Z“e’e“fd©dª„Z”e•ed«e’ e”ƒ q’W e ^e-d¬¡G d­d®„ d®e3ƒƒZ–G d¯d°„ d°ej2ƒZ—e ˜d±d²¡d³d´„ ƒZ™ešdµkre™ƒ  dS )·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>   e Zd ZdZdZdZdZdd„ Zdd„ Zdd
d„Z	dd„ Z
d	S )ÚBaseTestzBase class for logging tests.z&%(name)s -> %(levelname)s: %(message)sz^([\w.]+) -> (\w+): (\d+)$r   c             C   s  t  ¡ | _t ¡ jj}t ¡  zrtj 	¡ | _
tjdd… | _| 	¡  | _}tj 	¡ | _tj 	¡ | _i  | _}x |D ]}t|| ddƒ||< qrW W dt ¡  X t d¡| _t d¡| _t d¡| _| j ¡ | _t ¡ | _| j tj¡ t | j¡| _ t !| j"¡| _#| j  $| j#¡ | j %¡ r6| jj&| jj& }t'd| ƒ‚| j %¡ r^| jj&| jj& }t'd| ƒ‚| j (| j ¡ |  )| j %¡ ¡ |  )| j %¡ ¡ dS )zxSetup the default logging stream to an internal StringIO instance,
        so that we can examine log output as we want.NÚdisabledu   Â«Ã—Â»u   Ä¿Ã–GÚ zUnexpected handlers: %s)*r   Zthreading_setupÚ_threading_keyÚloggingÚ	getLoggerÚmanagerÚ
loggerDictÚ_acquireLockÚ	_handlersÚcopyÚsaved_handlersÚ_handlerListÚsaved_handler_listÚsaved_loggersÚ_nameToLevelÚsaved_name_to_levelÚ_levelToNameÚsaved_level_to_nameÚlogger_statesÚgetattrÚ_releaseLockÚ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)ÚselfZlogger_dictr   r    ÚnameZhlist© r:   ú"/usr/lib/python3.7/test_logging.pyÚsetUpM   s@    




zBaseTest.setUpc             C   s8  | j  ¡  | j | j¡ x,| jjrD| jjd }| j |¡ | ¡  qW | j | j¡ t 	¡  z¸tj
 ¡  tj
 | j¡ tj ¡  tj | j¡ tj ¡  tj | j¡ | jtjdd…< t ¡ j}d|_|j}| ¡  | | j¡ | j}x*| jD ] }|| dk	rî|| | j| _qîW W dt ¡  X |  ¡  tj| jŽ  dS )zJRemove our logging stream, and restore the original logging
        level.r   N) r*   Úcloser%   ÚremoveHandlerr.   r4   r+   r'   r   r   r   ÚclearÚupdater   r   r   r   r   r   r   r   r   Údisabler   r   r    r   r"   Z
doCleanupsr   Zthreading_cleanupr   )r8   Úhr   r   r    r9   r:   r:   r;   ÚtearDownw   s8    






zBaseTest.tearDownNc       	      C   s    |p| j }t |p| j¡}| ¡  ¡ }|  t|ƒt|ƒ¡ xFt||ƒD ]8\}}| 	|¡}|sj|  
d| ¡ |  t| ¡ ƒ|¡ qFW | ¡ }|rœ|  
d| ¡ dS )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)	r8   Zexpected_valuesr*   ÚpatZactual_linesÚactualÚexpectedÚmatchÚsr:   r:   r;   Úassert_log_lines™   s    

zBaseTest.assert_log_linesc             C   s   |  j d7  _ d| j  S )zMGenerate a message consisting solely of an auto-incrementing
        integer.é   z%d)Úmessage_num)r8   r:   r:   r;   Únext_message«   s    zBaseTest.next_message)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r0   rF   rX   r<   rC   rV   rY   r:   r:   r:   r;   r   E   s   *"
r   c               @   sP   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Z	dS )ÚBuiltinLevelsTestz*Test builtin levels and their inheritance.c             C   s4  | j }t d¡}| tj¡ t t d¡i ¡}| tj¡ t d¡}| tj¡ | tj	|ƒ ¡ | 
|ƒ ¡ | tj	|ƒ ¡ | 
|ƒ ¡ | |ƒ ¡ | |ƒ ¡ | tj	|ƒ ¡ | 
|ƒ ¡ | |ƒ ¡ | |ƒ ¡ | |ƒ ¡ | |ƒ ¡ | |ƒ ¡ | |ƒ ¡ | |ƒ ¡ |  dddddd	d
ddddg¡ d S )NÚERRÚINFÚDEB)r_   ÚCRITICALÚ1)r_   ÚERRORÚ2)r`   rb   Ú3)r`   rd   Ú4)r`   ÚWARNINGÚ5)r`   ÚINFOÚ6)ra   rb   Ú7)ra   rd   Ú8)ra   rh   Ú9)ra   rj   Ú10)ra   r,   Ú11)rY   r   r   r+   rd   ÚLoggerAdapterrj   r,   Úlogrb   ÚerrorÚwarningÚinfoÚdebugrV   )r8   Úmr_   r`   ra   r:   r:   r;   Ú	test_flatµ   sD    

zBuiltinLevelsTest.test_flatc             C   s„   | j }t d¡}| tj¡ t d¡}| tj¡ | tj|ƒ ¡ | |ƒ ¡ | 	|ƒ ¡ | 
|ƒ ¡ | |ƒ ¡ |  ddg¡ d S )Nr`   zINF.ERR)zINF.ERRrb   rc   )zINF.ERRrd   re   )rY   r   r   r+   rj   rd   rr   rb   rs   rt   ru   rv   rV   )r8   rw   r`   ÚINF_ERRr:   r:   r;   Útest_nested_explicitä   s    

z&BuiltinLevelsTest.test_nested_explicitc             C   sê   | j }t d¡}| tj¡ t d¡}| tj¡ t d¡}t d¡}t d¡}| tj|ƒ ¡ | |ƒ ¡ | 	|ƒ ¡ | 
|ƒ ¡ | tj|ƒ ¡ | |ƒ ¡ | |ƒ ¡ | 	|ƒ ¡ | 
|ƒ ¡ | |ƒ ¡ |  dddd	d
dg¡ d S )Nr`   zINF.ERRz	INF.UNDEFzINF.ERR.UNDEFÚUNDEF)z	INF.UNDEFrb   rc   )z	INF.UNDEFrd   re   )z	INF.UNDEFrh   rf   )z	INF.UNDEFrj   rg   )zINF.ERR.UNDEFrb   ri   )zINF.ERR.UNDEFrd   rk   )rY   r   r   r+   rj   rd   rr   rb   rs   rt   ru   rv   rV   )r8   rw   r`   ry   Z	INF_UNDEFZINF_ERR_UNDEFr{   r:   r:   r;   Útest_nested_inheritedû   s2    




z'BuiltinLevelsTest.test_nested_inheritedc             C   s–   | j }t d¡}t d¡}t d¡}| tj¡ | tj|ƒ ¡ | |ƒ ¡ | tj|ƒ ¡ | |ƒ ¡ | |ƒ ¡ | |ƒ ¡ |  	ddddg¡ d S )Nr`   zINF.BADPARENT.UNDEFzINF.BADPARENT)zINF.BADPARENT.UNDEFrb   rc   )zINF.BADPARENT.UNDEFrj   re   )zINF.BADPARENTrb   rf   )zINF.BADPARENTrj   rg   )
rY   r   r   r+   rj   rr   ÚFATALru   rv   rV   )r8   rw   r`   Z
GRANDCHILDZCHILDr:   r:   r;   Útest_nested_with_virtual_parent  s     


z1BuiltinLevelsTest.test_nested_with_virtual_parentc             C   s,   |   t d¡tj¡ |   t tj¡d¡ dS )z&See issue #22386 for more information.rj   N)rI   r   ÚgetLevelNamerj   )r8   r:   r:   r;   Útest_regression_223868  s    z'BuiltinLevelsTest.test_regression_22386c             C   s8   t  t jd¡ |  t jt jd¡ |  t  t j¡d¡ dS )z&See issue #29220 for more information.r   rj   N)r   ÚaddLevelNamerj   Ú
addCleanuprI   r   )r8   r:   r:   r;   Útest_regression_29220=  s    z'BuiltinLevelsTest.test_regression_29220c             C   s   t  d¡}|  |t j¡ d S )Nr}   )r   r   rI   r}   )r8   Zfatalr:   r:   r;   Útest_issue27935C  s    
z!BuiltinLevelsTest.test_issue27935c             C   s`   t  t jd¡ |  t jt jd¡ |  t  t j¡d¡ |  t  t j¡d¡ |  t  d¡t j¡ dS )z&See issue #29220 for more information.r   rj   ÚNOTSETN)r   r   rj   r‚   rI   r   r…   )r8   r:   r:   r;   rƒ   G  s
    N)rZ   r[   r\   r]   rx   rz   r|   r~   r€   rƒ   r„   r:   r:   r:   r;   r^   ²   s   /#r^   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚBasicFilterTestzTest the bundled Filter class.c          	   C   s¤   t  d¡}| jjd }z|| |¡ t  d¡}t  d¡}t  d¡}t  d¡}| |  ¡ ¡ | |  ¡ ¡ | |  ¡ ¡ | |  ¡ ¡ |  ddg¡ W d | 	|¡ X d S )Nz	spam.eggsr   Úspamzspam.eggs.fishzspam.bakedbeans)z	spam.eggsrj   re   )zspam.eggs.fishrj   rf   )
r   ÚFilterr%   r4   Ú	addFilterr   ru   rY   rV   ÚremoveFilter)r8   Zfilter_Úhandlerr‡   Ú	spam_eggsÚspam_eggs_fishÚspam_bakedbeansr:   r:   r;   Útest_filterS  s     





zBasicFilterTest.test_filterc          	   C   s¢   dd„ }| j jd }z|| |¡ t d¡}t d¡}t d¡}t d¡}| |  ¡ ¡ | |  ¡ ¡ | |  ¡ ¡ | |  ¡ ¡ |  dd	g¡ W d | |¡ X d S )
Nc             S   s&   | j  d¡}d |d d… ¡}|dkS )NÚ.é   z	spam.eggs)r9   ÚsplitÚjoin)ÚrecordÚpartsÚprefixr:   r:   r;   Ú
filterfunco  s    z8BasicFilterTest.test_callable_filter.<locals>.filterfuncr   r‡   z	spam.eggszspam.eggs.fishzspam.bakedbeans)z	spam.eggsrj   re   )zspam.eggs.fishrj   rf   )	r%   r4   r‰   r   r   ru   rY   rV   rŠ   )r8   r—   r‹   r‡   rŒ   r   rŽ   r:   r:   r;   Útest_callable_filterk  s     




z$BasicFilterTest.test_callable_filterc             C   s*   t  ¡ }t  ddi¡}|  | |¡¡ d S )Nr9   z	spam.eggs)r   rˆ   ÚmakeLogRecordr7   Úfilter)r8   ÚfÚrr:   r:   r;   Útest_empty_filterˆ  s    z!BasicFilterTest.test_empty_filterN)rZ   r[   r\   r]   r   r˜   r   r:   r:   r:   r;   r†   O  s   r†   éx   éw   év   éu   ét   és   ér   éq   ép   éo   rW   ÚSilentÚTaciturnÚTerseÚEffusiveÚSociableÚVerboseÚ	TalkativeZ	GarrulousÚ
ChatterboxÚBoringc               @   s   e Zd ZdZdd„ ZdS )ÚGarrulousFilterz)A filter which blocks garrulous messages.c             C   s
   |j tkS )N)ÚlevelnoÚ	GARRULOUS)r8   r”   r:   r:   r;   rš   ·  s    zGarrulousFilter.filterN)rZ   r[   r\   r]   rš   r:   r:   r:   r;   r±   ³  s   r±   c               @   s   e Zd ZdZdd„ ZdS )ÚVerySpecificFilterz5A filter which blocks sociable and taciturn messages.c             C   s   |j ttgkS )N)r²   ÚSOCIABLEÚTACITURN)r8   r”   r:   r:   r;   rš   ¾  s    zVerySpecificFilter.filterN)rZ   r[   r\   r]   rš   r:   r:   r:   r;   r´   º  s   r´   c               @   s<   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚCustomLevelsAndFiltersTestz@Test various filtering possibilities with custom logging levels.z^[\w.]+ -> (\w+): (\d+)$c             C   s0   t  | ¡ x t ¡ D ]\}}t ||¡ qW d S )N)r   r<   Úmy_logging_levelsÚitemsr   r   )r8   ÚkÚvr:   r:   r;   r<   É  s    
z CustomLevelsAndFiltersTest.setUpc             C   s"   xt D ]}| ||  ¡ ¡ qW d S )N)ÚLEVEL_RANGErr   rY   )r8   ÚloggerZlvlr:   r:   r;   Úlog_at_all_levelsÎ  s    
z,CustomLevelsAndFiltersTest.log_at_all_levelsc             C   s2   | j  t¡ |  | j ¡ |  ddddddg¡ d S )N)r­   ri   )r¬   rk   )r«   rl   )rª   rm   )r©   rn   )r¨   ro   )r%   r+   ÚVERBOSEr¾   rV   )r8   r:   r:   r;   Útest_logger_filterÒ  s    z-CustomLevelsAndFiltersTest.test_logger_filterc          	   C   sR   | j jd  t¡ z$|  | j ¡ |  dddddg¡ W d | j jd  tj¡ X d S )Nr   )r¬   rk   )r«   rl   )rª   rm   )r©   rn   )r¨   ro   )r%   r4   r+   rµ   r¾   rV   r   r…   )r8   r:   r:   r;   Útest_handler_filterà  s    z.CustomLevelsAndFiltersTest.test_handler_filterc          
   C   s¬   | j jd }d }tƒ }| |¡ zj|  | j ¡ dddddddd	d
g	}|  |¡ tƒ }| j  |¡ |  | j ¡ |  |dddddddg ¡ W d |rœ| j  |¡ | |¡ X d S )Nr   )r°   rc   )r¯   re   )r®   rg   )r­   ri   )r¬   rk   )r«   rl   )rª   rm   )r©   rn   )r¨   ro   )r°   rp   )r¯   Z12)r®   Z14)r­   Z15)r«   Z17)rª   Z18)r¨   Z20)r%   r4   r±   r‰   r¾   rV   r´   rŠ   )r8   r‹   Zspecific_filterZgarrZfirst_linesr:   r:   r;   Útest_specific_filtersð  s<    

z0CustomLevelsAndFiltersTest.test_specific_filtersN)
rZ   r[   r\   r]   rF   r<   r¾   rÀ   rÁ   rÂ   r:   r:   r:   r;   r·   Â  s   r·   c               @   sZ   e Zd Zdd„ Zdd„ Zdd„ Ze ej	dkd¡d	d
„ ƒZ
e eedƒ d¡dd„ ƒZdS )ÚHandlerTestc             C   sD   t  ¡ }d|_|  |jd¡ d|_|  |jd¡ |  t|jd ¡ d S )NÚgenericZanothergeneric)r   ÚHandlerr9   rI   ÚassertRaisesÚNotImplementedErrorÚemit)r8   rB   r:   r:   r;   Ú	test_name  s    zHandlerTest.test_namec       
      C   sþ  t jdkr^xîdD ]æ}t ¡ \}}t |¡ |s:t |¡ tjj	|dd}|rÆ|j
|j }}|  |d¡ |  |d¡ t ddi¡}| |¡ t |¡ |  tj |¡¡ | |¡ |  tj |¡¡ n|  |j
d¡ |  |jd¡ | ¡  |rt |¡ qW t jdkrd	}nd
}y4tj |¡}|  |j|j¡ |  |j¡ | ¡  W n tk
r\   Y nX xHdD ]@}	|	dkrŠ|  ttjjdd|	¡ ntj dd|	¡}| ¡  qdW tj d¡}t i ¡}|  | |¡¡ | ¡  tj d¡}|  | |¡¡ | ¡  d S )N)ÚlinuxÚdarwin)TFT)ÚdelayéÿÿÿÿÚmsgZTestrË   z/var/run/syslogz/dev/log)ÚGETÚPOSTÚPUTrÑ   Ú	localhostz/logr   rW   )ÚsysÚplatformÚtempfileÚmkstempÚosr=   Úunlinkr   r4   ÚWatchedFileHandlerÚdevÚinorI   r™   ÚhandleÚassertFalseÚpathÚexistsr7   ÚSysLogHandlerZfacilityZLOG_USERZ
unixsocketÚOSErrorrÆ   Ú
ValueErrorÚHTTPHandlerZBufferingHandlerZshouldFlush)
r8   ZexistingÚfdÚfnrB   rÚ   rÛ   rœ   ZsocknameÚmethodr:   r:   r;   Útest_builtin_handlers$  sZ    








z!HandlerTest.test_builtin_handlersc             C   s¸   t  ¡ \}}t |¡ t |¡ t |¡}tj|dfftj	j
|dfftj	j|dfff}tjdkrv|tj	j|dfff7 }x<|D ]4\}}||Ž }|  tj |¡¡ | ¡  t |¡ q|W dS )zs
        Test that Path objects are accepted as filename arguments to handlers.

        See Issue #27493.
        ÚwÚarB   )rÊ   rË   N)rÕ   rÖ   r×   r=   rØ   ÚpathlibZPathr   ÚFileHandlerr4   ÚRotatingFileHandlerÚTimedRotatingFileHandlerrÓ   rÔ   rÙ   r7   rÞ   rß   )r8   rä   rå   ZpfnZcasesÚclsÚargsrB   r:   r:   r;   Útest_path_objectsZ  s    



zHandlerTest.test_path_objectsÚntz/WatchedFileHandler not appropriate for Windows.c          
      s2  ‡ fdd„}d}d}d ˆ _ d ˆ _x
dD ] }t dd¡\}}t |¡ tj|||fd}d|_| 	¡  t
jj||d	}t
 d
¡}	| |	¡ zrxlt|ƒD ]`}
t d¡ t
 ddi¡}yt ¡ ˆ _ | |¡ W q˜ tk
rö   tdˆ jˆ j f ƒ ‚ Y q˜X q˜W W d | ¡  | ¡  tj |¡r(t |¡ X q(W d S )Nc          	      sZ   xTt |ƒD ]H}yt | ¡ t ¡ ˆ _W n tk
r:   Y nX t dt dd¡ ¡ q
W d S )Ngü©ñÒMbp?r   é   )	Úranger×   rØ   ÚtimeÚdeletion_timerá   ÚsleepÚrandomZrandint)ZfnameZtriesÚ_)r8   r:   r;   Úremove_loopt  s    
z*HandlerTest.test_race.<locals>.remove_loopiô  )FTz.logztest_logging-3-)Útargetrï   T)rÌ   z'%(asctime)s: %(levelname)s: %(message)sg{®Gázt?rÎ   ZtestingzDeleted at %s, opened at %s)Zhandle_timerõ   rÕ   rÖ   r×   r=   Ú	threadingÚThreadZdaemonÚstartr   r4   rÙ   r/   r2   ró   rô   rö   r™   rÜ   Ú	ExceptionÚprintr“   rÞ   rß   rØ   )r8   rù   Z	del_countZ	log_countrÌ   rä   rå   ZremoverrB   r›   rø   rœ   r:   )r8   r;   Ú	test_raceq  s<    	




zHandlerTest.test_raceÚforkzTest requires os.fork().c       	   	      s°  G dd„ dt jƒ}|  tt jƒd¡ |ƒ ‰|  ˆjjj¡ dˆ_	|  
tt jƒd¡ |  
tt jƒd¡ t  d¡}| ˆ¡ | t j¡ t ¡ ‰t ¡ ‰ ‡ ‡‡fdd„}tj|d	d
}| ¡  ˆ ¡  t ¡ }|dkrðz| d¡ W dt d¡ X n¼| d¡ ˆ  ¡  | ¡  t ¡ }xL| d¡ t |tj¡\}}||kr<P t ¡ | dkrPP t  d¡ qW | d¡ ||krœt !|t"j#¡ t |d¡\}}|  $d¡ | j|ddd dS )z>Ensure child logging locks are not held; bpo-6721 & bpo-36533.c                   s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )zAHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandlerc                s"   t ƒ  ¡  tjtddƒd| _d S )Nz	/dev/nullZwt)r*   )ÚsuperÚ__init__r   r-   ÚopenÚsub_handler)r8   )Ú	__class__r:   r;   r  ¦  s    
zJHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.__init__c             S   s,   | j  ¡  z| j  |¡ W d | j  ¡  X d S )N)r  ÚacquirerÈ   Úrelease)r8   r”   r:   r:   r;   rÈ   «  s    
zFHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.emit)rZ   r[   r\   r  rÈ   Ú__classcell__r:   r:   )r  r;   Ú_OurHandler¥  s   r
  r   z*because we need at least one for this testrW   Ú test_post_fork_child_no_deadlockc                  sF   t  ¡  z.ˆ ¡  zˆ ¡  ˆ  d¡ W d ˆ ¡  X W d t  ¡  X d S )Ng      à?)r   r   r  ÚsetÚwaitr  r"   r:   )Ú+fork_happened__release_locks_and_end_threadÚlocks_held__ready_to_forkÚrefed_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)rú   r9   z#Child process did not deadlock. \o/Nz&Parent process returned from fork. \o/zWaiting for child process.é   gš™™™™™©?zDone waiting.zchild process deadlocked.zchild process error)rÎ   )%r   rÅ   rI   rJ   r   r‚   r  r*   r=   r9   ÚassertGreaterZ_at_fork_reinit_lock_weaksetr   r6   r+   r,   rû   ÚEventrü   rý   r  r×   r  ru   Ú_exitr  r“   rô   Z	monotonicrv   ÚwaitpidÚWNOHANGrö   ÚkillÚsignalÚSIGKILLrM   )	r8   r
  Ztest_loggerr  Zlock_holder_threadÚpidZ
start_timeZ
waited_pidÚstatusr:   )r  r  r  r;   r  ¢  sR    







z,HandlerTest.test_post_fork_child_no_deadlockN)rZ   r[   r\   rÉ   rç   rð   ÚunittestZskipIfr×   r9   r   Úhasattrr  r:   r:   r:   r;   rÃ     s
   61rÃ   c               @   s   e Zd Zdd„ ZdS )Ú	BadStreamc             C   s   t dƒ‚d S )Nzdeliberate mistake)ÚRuntimeError)r8   Údatar:   r:   r;   Úwriteú  s    zBadStream.writeN)rZ   r[   r\   r"  r:   r:   r:   r;   r  ù  s   r  c               @   s   e Zd Zdd„ ZdS )ÚTestStreamHandlerc             C   s
   || _ d S )N)Úerror_record)r8   r”   r:   r:   r;   ÚhandleErrorþ  s    zTestStreamHandler.handleErrorN)rZ   r[   r\   r%  r:   r:   r:   r;   r#  ý  s   r#  c               @   s   e Zd ZejZdZdS )ÚStreamWithIntNamer‘   N)rZ   r[   r\   r   r…   Úlevelr9   r:   r:   r:   r;   r&    s   r&  c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚStreamHandlerTestc          	   C   s¶   t tƒ ƒ}t i ¡}tj}zŽ| |¡ |  |j|¡ t tƒ ¡}t	 
¡ $}| |¡ d}|  || ¡ ¡ W d Q R X dt_t	 
¡  }| |¡ |  d| ¡ ¡ W d Q R X W d |t_X d S )Nz"
RuntimeError: deliberate mistake
Fr   )r#  r  r   r™   ÚraiseExceptionsrÜ   ÚassertIsr$  r-   r   Úcaptured_stderrÚassertInrG   rI   )r8   rB   rœ   Z	old_raiseÚstderrrÎ   r:   r:   r;   Útest_error_handling  s     






z%StreamHandlerTest.test_error_handlingc             C   sV   t  ¡ }t ¡ }| |¡}|  |tj¡ | |¡}|  ||¡ | |¡}|  |¡ dS )z3
        Test setting the handler's stream
        N)	r   r-   r(   r)   Z	setStreamr*  rÓ   r-  ÚassertIsNone)r8   rB   r*   ÚoldrR   r:   r:   r;   Útest_stream_setting  s    


z%StreamHandlerTest.test_stream_settingc             C   s    t  tƒ ¡}|  t|ƒd¡ d S )Nz<StreamHandler 2 (NOTSET)>)r   r-   r&  rI   Úrepr)r8   rB   r:   r:   r;   Ú'test_can_represent_stream_with_int_name*  s    z9StreamHandlerTest.test_can_represent_stream_with_int_nameN)rZ   r[   r\   r.  r1  r3  r:   r:   r:   r;   r(    s   r(  c               @   s:   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zddd„Zd
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.
    c             C   s<   t jj| |d |dd | j ¡ d | _|| _d | _|| _d S )NT)ÚmapZdecode_datarW   )	ÚsmtpdÚ
SMTPServerr  ÚsocketÚgetsocknameÚportÚ_handlerÚ_threadÚpoll_interval)r8   Úaddrr‹   r=  Úsockmapr:   r:   r;   r  F  s    zTestSMTPServer.__init__c             C   s   |   ||||¡ dS )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)r;  )r8   ÚpeerÚmailfromÚrcpttosr!  r:   r:   r;   Úprocess_messageN  s    
zTestSMTPServer.process_messagec             C   s0   t j| j| jfd | _}| d¡ | ¡  dS )zG
        Start the server running on a separate daemon thread.
        )rú   rï   TN)rû   rü   Úserve_foreverr=  r<  Ú	setDaemonrý   )r8   Útr:   r:   r;   rý   Z  s    
zTestSMTPServer.startc             C   s   t j|| jd dS )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`.
        )r5  N)ÚasyncoreZloopÚ_map)r8   r=  r:   r:   r;   rD  c  s    zTestSMTPServer.serve_foreverNc             C   s0   |   ¡  t | j|¡ d| _tj| jdd dS )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.
        NT)r5  Z
ignore_all)r=   r   Újoin_threadr<  rG  Z	close_allrH  )r8   Útimeoutr:   r:   r;   Ústopm  s    zTestSMTPServer.stop)N)	rZ   r[   r\   r]   r  rC  rý   rD  rK  r:   r:   r:   r;   r4  1  s   	
r4  c                   s:   e Zd ZdZdd„ Zdd„ Z‡ fdd„Zdd	d
„Z‡  ZS )Ú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.
    c             C   s    d | _ || _|| _t ¡ | _d S )N)r<  r=  r;  rû   r  Úready)r8   r‹   r=  r:   r:   r;   r  ‹  s    zControlMixin.__init__c             C   s0   t j| j| jfd | _}| d¡ | ¡  dS )zI
        Create a daemon thread to run the server, and start it.
        )rú   rï   TN)rû   rü   rD  r=  r<  rE  rý   )r8   rF  r:   r:   r;   rý   ‘  s    
zControlMixin.startc                s   | j  ¡  tt| ƒ |¡ dS )z^
        Run the server. Set the ready flag before entering the
        service loop.
        N)rM  r  r  rL  rD  )r8   r=  )r  r:   r;   rD  š  s    
zControlMixin.serve_foreverNc             C   s<   |   ¡  | jdk	r&t | j|¡ d| _|  ¡  | j ¡  dS )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)Úshutdownr<  r   rI  Úserver_closerM  r?   )r8   rJ  r:   r:   r;   rK  ¢  s    
zControlMixin.stop)N)	rZ   r[   r\   r]   r  rý   rD  rK  r	  r:   r:   )r  r;   rL  {  s
   	rL  c               @   s"   e Zd ZdZd	dd„Zdd„ ZdS )
Ú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.
    ç      à?FNc                s<   G ‡ ‡fdd„dt ƒ‰ t | |ˆ ¡ t | ||¡ || _d S )Nc                   s2   e Zd Zddd„Zdd„ Z‡‡ ‡fdd„Z‡  ZS )	z=TestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandlerNc             S   s   |  d¡r| jS t|ƒ‚d S )NZdo_)Ú
startswithÚprocess_requestÚAttributeError)r8   r9   Údefaultr:   r:   r;   Ú__getattr__¾  s    
zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.__getattr__c             S   s   | j  | ¡ d S )N)Úserverr;  )r8   r:   r:   r;   rS  Ã  s    zMTestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.process_requestc                s   ˆrt ˆ | ƒj|f|žŽ  d S )N)r  Úlog_message)r8   Úformatrï   )ÚDelegatingHTTPRequestHandlerr  rr   r:   r;   rX  Æ  s    zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.log_message)N)rZ   r[   r\   rV  rS  rX  r	  r:   )rZ  rr   )r  r;   rZ  ½  s   
rZ  )r   r   r  rL  Ússlctx)r8   r>  r‹   r=  rr   r[  r:   )rZ  rr   r;   r  »  s    zTestHTTPServer.__init__c          
   C   sf   y(| j  ¡ \}}| jr&| jj|dd}W n4 tk
r\ } ztj d| ¡ ‚ W d d }~X Y nX ||fS )NT)Zserver_sidezGot an error:
%s
)r8  Zacceptr[  Zwrap_socketrá   rÓ   r-  r"  )r8   Úsockr>  Úer:   r:   r;   Úget_requestÎ  s    zTestHTTPServer.get_request)rQ  FN)rZ   r[   r\   r]   r  r^  r:   r:   r:   r;   rP  °  s   
 
rP  c                   s.   e Zd ZdZdZddd„Z‡ fdd„Z‡  ZS )	Ú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.
    Tç      à?c             C   s2   G dd„ dt ƒ}t | |||¡ t | ||¡ d S )Nc               @   s   e Zd Zdd„ ZdS )z;TestTCPServer.__init__.<locals>.DelegatingTCPRequestHandlerc             S   s   | j  | ¡ d S )N)rW  r;  )r8   r:   r:   r;   rÜ   î  s    zBTestTCPServer.__init__.<locals>.DelegatingTCPRequestHandler.handleN)rZ   r[   r\   rÜ   r:   r:   r:   r;   ÚDelegatingTCPRequestHandlerì  s   ra  )r   r   r  rL  )r8   r>  r‹   r=  Úbind_and_activatera  r:   r:   r;   r  ê  s    
zTestTCPServer.__init__c                s"   t t| ƒ ¡  | j ¡ d | _d S )NrW   )r  r_  Úserver_bindr8  r9  r:  )r8   )r  r:   r;   rc  ô  s    zTestTCPServer.server_bind)r`  T)rZ   r[   r\   r]   Zallow_reuse_addressr  rc  r	  r:   r:   )r  r;   r_  Ù  s
    
	r_  c                   s6   e Zd ZdZd
dd„Z‡ fdd„Z‡ fdd	„Z‡  ZS )Ú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.
    ç      à?Tc                s<   G ‡ fdd„dt ƒ‰ t | |ˆ |¡ t | ||¡ d| _d S )Nc                   s&   e Zd Zdd„ Z‡‡ fdd„Z‡  ZS )z;TestUDPServer.__init__.<locals>.DelegatingUDPRequestHandlerc             S   s   | j  | ¡ d S )N)rW  r;  )r8   r:   r:   r;   rÜ     s    zBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.handlec                sD   | j  ¡ }|r@ytˆ | ƒ ¡  W n tk
r>   | jjs:‚ Y nX d S )N)ZwfilerG   r  Úfinishrá   rW  Ú_closed)r8   r!  )ÚDelegatingUDPRequestHandlerr  r:   r;   rf    s    
zBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.finish)rZ   r[   r\   rÜ   rf  r	  r:   )rh  )r  r;   rh    s   rh  F)r
   r	   r  rL  rg  )r8   r>  r‹   r=  rb  r:   )rh  r;   r  	  s    zTestUDPServer.__init__c                s"   t t| ƒ ¡  | j ¡ d | _d S )NrW   )r  rd  rc  r8  r9  r:  )r8   )r  r:   r;   rc    s    zTestUDPServer.server_bindc                s   t t| ƒ ¡  d| _d S )NT)r  rd  rO  rg  )r8   )r  r:   r;   rO  #  s    zTestUDPServer.server_close)re  T)rZ   r[   r\   r]   r  rc  rO  r	  r:   r:   )r  r;   rd  ø  s
    
rd  ÚAF_UNIXc               @   s   e Zd ZejZdS )ÚTestUnixStreamServerN)rZ   r[   r\   r8  ri  Úaddress_familyr:   r:   r:   r;   rj  (  s   rj  c               @   s   e Zd ZejZdS )ÚTestUnixDatagramServerN)rZ   r[   r\   r8  ri  rk  r:   r:   r:   r;   rl  +  s   rl  c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚSMTPHandlerTestg      N@c       
      C   s
  i }t tjdf| jd|ƒ}| ¡  tj|jf}tjj|ddd| j	d}|  
|jdg¡ g | _t ddi¡}t ¡ | _| |¡ | j | j	¡ | ¡  |  | j ¡ ¡ |  
t| jƒd	¡ | jd \}}}}	|  
|d¡ |  
|dg¡ |  d
|	¡ |  |	 d¡¡ | ¡  d S )Nr   gü©ñÒMbP?ÚmeZyouZLog)rJ  rÎ   u	   Hello âœ“rW   z
Subject: Log
u   

Hello âœ“)r4  r   ZHOSTrC  rý   r:  r   r4   ZSMTPHandlerÚTIMEOUTrI   ZtoaddrsÚmessagesr™   rû   r  ÚhandledrÜ   r  rK  r7   Zis_setrJ   r,  Úendswithr=   )
r8   r?  rW  r>  rB   rœ   r@  rA  rB  r!  r:   r:   r;   Ú
test_basic4  s,    


zSMTPHandlerTest.test_basicc             G   s   | j  |¡ | j ¡  d S )N)rp  Úappendrq  r  )r8   rï   r:   r:   r;   rC  L  s    zSMTPHandlerTest.process_messageN)rZ   r[   r\   ro  rs  rC  r:   r:   r:   r;   rm  0  s   rm  c               @   s4   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚMemoryHandlerTestzTests for the MemoryHandler.z^[\w.]+ -> (\w+): (\d+)$c             C   sF   t  | ¡ tj dtj| j¡| _t d¡| _	d| j	_
| j	 | j¡ d S )Né
   Zmemr   )r   r<   r   r4   ÚMemoryHandlerrh   r.   Úmem_hdlrr   Ú
mem_loggerÚ	propagater6   )r8   r:   r:   r;   r<   W  s    

zMemoryHandlerTest.setUpc             C   s   | j  ¡  t | ¡ d S )N)rx  r=   r   rC   )r8   r:   r:   r;   rC   _  s    
zMemoryHandlerTest.tearDownc             C   sæ   | j  |  ¡ ¡ |  g ¡ | j  |  ¡ ¡ |  g ¡ | j  |  ¡ ¡ dddg}|  |¡ xndD ]f}x tdƒD ]}| j  |  ¡ ¡ qlW |  |¡ | j  |  ¡ ¡ |dd„ t||d ƒD ƒ }|  |¡ q^W | j  |  ¡ ¡ |  |¡ d S )	N)r,   rc   )rj   re   )rh   rf   )rò   é   é	   c             S   s   g | ]}d t |ƒf‘qS )r,   )Ústr)Ú.0Úir:   r:   r;   ú
<listcomp>y  s    z0MemoryHandlerTest.test_flush.<locals>.<listcomp>rv  )ry  rv   rY   rV   ru   rt   ró   )r8   ÚlinesÚnr  r:   r:   r;   Ú
test_flushc  s$    




zMemoryHandlerTest.test_flushc             C   sÞ   | j  |  ¡ ¡ |  g ¡ | j  |  ¡ ¡ |  g ¡ | j  | j¡ | j ¡  ddg}|  |¡ tj	 
dtj| jd¡| _| j  | j¡ | j  |  ¡ ¡ |  |¡ | j  |  ¡ ¡ |  |¡ | j  | j¡ | j ¡  |  |¡ dS )zO
        Test that the flush-on-close configuration works as expected.
        )r,   rc   )rj   re   rv  FN)ry  rv   rY   rV   ru   r>   rx  r=   r   r4   rw  rh   r.   r6   )r8   r  r:   r:   r;   Útest_flush_on_close  s(    






z%MemoryHandlerTest.test_flush_on_closeN)	rZ   r[   r\   r]   rF   r<   rC   rƒ  r„  r:   r:   r:   r;   ru  P  s   ru  c               @   s   e Zd ZdZdd„ ZdS )ÚExceptionFormatterzA special exception formatter.c             C   s   d|d j  S )Nz
Got a [%s]r   )rZ   )r8   Zeir:   r:   r;   ÚformatException   s    z"ExceptionFormatter.formatExceptionN)rZ   r[   r\   r]   r†  r:   r:   r:   r;   r…  ž  s   r…  c               @   sÒ   e Zd ZdZejZdZdZdZdZ	e 
dd¡Ze 
dd	¡Zd
e  d Ze 
dd¡ZdZdZdZdZdd„ Zdd„ Zdd„ Zefdd„Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,S )-ÚConfigFileTestz5Reading logging config from a .ini-style config file.z^(\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.stboutzformatter=form1zformatter=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=
    zclass=StreamHandlerzclass=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=
    c             K   s$   t  t |¡¡}tjj|f|Ž d S )N)r(   r)   ÚtextwrapÚdedentr   ÚconfigÚ
fileConfig)r8   ÚconfÚkwargsÚfiler:   r:   r;   Úapply_config£  s    zConfigFileTest.apply_configc          	   C   sb   t  ¡ P}|  | j¡ t ¡ }| |  ¡ ¡ | |  ¡ ¡ | j	dg|d |  	g ¡ W d Q R X d S )N)rd   re   )r*   )
r   Úcaptured_stdoutr  Úconfig0r   r   ru   rY   rs   rV   )r8   Úoutputr½   r:   r:   r;   Útest_config0_ok§  s    
zConfigFileTest.test_config0_okc          	   C   s†   t  ¡ t}t t | j¡¡}t ¡ }| 	|¡ t
j |¡ t
 ¡ }| |  ¡ ¡ | |  ¡ ¡ | jdg|d |  g ¡ W d Q R X d S )N)rd   re   )r*   )r   r  r(   r)   rˆ  r‰  r‘  ÚconfigparserZConfigParserZ	read_filer   rŠ  r‹  r   ru   rY   rs   rV   )r8   r’  rŽ  Zcpr½   r:   r:   r;   Útest_config0_using_cp_ok¶  s    

z'ConfigFileTest.test_config0_using_cp_okc          	   C   sd   t  ¡ R}|  |¡ t d¡}| |  ¡ ¡ | |  ¡ ¡ | jddg|d |  g ¡ W d Q R X d S )Nzcompiler.parser)rj   rc   )rd   re   )r*   )	r   r  r  r   r   ru   rY   rs   rV   )r8   rŠ  r’  r½   r:   r:   r;   Útest_config1_okÈ  s    


zConfigFileTest.test_config1_okc             C   s   |   t| j| j¡ d S )N)rÆ   rþ   r  Úconfig2)r8   r:   r:   r;   Útest_config2_failure×  s    z#ConfigFileTest.test_config2_failurec             C   s   |   t| j| j¡ d S )N)rÆ   rþ   r  Úconfig3)r8   r:   r:   r;   Útest_config3_failureÛ  s    z#ConfigFileTest.test_config3_failurec          	   C   s|   t  ¡ j}|  | j¡ t ¡ }y
tƒ ‚W n tk
rF   t d¡ Y nX tj	 
d¡ |  | ¡ d¡ |  g ¡ W d Q R X d S )Nzjust testingr   z-ERROR:root:just testing
Got a [RuntimeError]
)r   r  r  Úconfig4r   r   r   Ú	exceptionrÓ   ÚstdoutÚseekrI   rG   rV   )r8   r’  r½   r:   r:   r;   Útest_config4_okß  s    


zConfigFileTest.test_config4_okc             C   s   | j | jd d S )N)rŠ  )r–  Úconfig5)r8   r:   r:   r;   Útest_config5_okî  s    zConfigFileTest.test_config5_okc             C   s   | j | jd d S )N)rŠ  )r–  Úconfig6)r8   r:   r:   r;   Útest_config6_okñ  s    zConfigFileTest.test_config6_okc          	   C   s&  t  ¡ n}|  | j¡ t d¡}t d¡}| |  ¡ ¡ | |  ¡ ¡ | 	|  ¡ ¡ | j
dddg|d |  
g ¡ W d Q R X t  ¡ ˜}|  | j¡ t d¡}|  |j¡ | |  ¡ ¡ | |  ¡ ¡ t d¡}| |  ¡ ¡ | |  ¡ ¡ | 	|  ¡ ¡ | j
dd	d
dg|d |  
g ¡ W d Q R X d S )Nzcompiler.parserzcompiler-hyphenated)rj   rc   )rd   re   )rb   rf   )r*   zcompiler.lexer)rj   rg   )rd   ri   )rj   rk   )rd   rl   )r   r  r  Úconfig1ar   r   ru   rY   rs   ÚcriticalrV   Úconfig7rÝ   r   )r8   r’  r½   Ú
hyphenatedr:   r:   r;   Útest_config7_okô  s<    





zConfigFileTest.test_config7_okc          	   C   sŒ   dd„ }|   ¡ X t dd¡\}}t |¡ tjdkrB| dd¡}| jj|d}|  	|¡ |  	|¡ W d Q R X t
jjd	 }|  |||¡ d S )
Nc             S   s   |   ¡  t |¡ d S )N)r=   r×   Úremove)Úh1rå   r:   r:   r;   Úcleanup!  s    z/ConfigFileTest.test_config8_ok.<locals>.cleanupz.logztest_logging-X-rñ   ú\z\\)rÕ   r   )Úcheck_no_resource_warningrÕ   rÖ   r×   r=   r9   ÚreplaceÚconfig8rY  r  r   Úrootr4   r‚   )r8   r«  rä   rå   r¯  r‹   r:   r:   r;   Útest_config8_ok  s    



zConfigFileTest.test_config8_okc             C   sZ   |   | j¡ t d¡}|  |j¡ |   | j¡ |  |j¡ | j | jdd |  |j¡ d S )NZsome_pristine_loggerF)Údisable_existing_loggers)r  Údisable_testr   r   rÝ   r   r7   )r8   r½   r:   r:   r;   Útest_logger_disabling6  s    
z$ConfigFileTest.test_logger_disablingc          
   C   sx   t  d¡ ¡ }tjddd\}}zFt || d¡¡ t |¡ t	j
j|tdddd	d
ddœidd W dt |¡ X dS )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ÚasciirW   FrÄ   z5%(asctime)s [%(process)d] [%(levelname)s] %(message)sz[%Y-%m-%d %H:%M:%S %z]zlogging.Formatter)rY  ÚdatefmtÚclass)Úversionr²  Ú
formatters)ÚdefaultsN)rˆ  r‰  ÚstriprÕ   rÖ   r×   r"  Úencoder=   r   rŠ  r‹  ÚdictrØ   )r8   Zinirä   rå   r:   r:   r;   Ú!test_defaults_do_no_interpolation?  s     

z0ConfigFileTest.test_defaults_do_no_interpolationN) rZ   r[   r\   r]   r   r­  rF   r‘  Úconfig1r¤  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‡  ¤  s8     *&+	r‡  c               @   s@   e Zd ZdZeZdZdd„ Zdd„ Zdd„ Z	d	d
„ Z
dd„ ZdS )ÚSocketHandlerTestzTest for SocketHandler objects.)rÒ   r   c          
   C   sÞ   t  | ¡ d | _ | _| _y$|  | j| jd¡ | _}| ¡  W n( t	k
rh } z
|| _dS d}~X Y nX |j
 ¡  tjj}t|jtƒr˜|d|jƒ| _n||jdƒ| _d| _| j | jjd ¡ | j | j¡ t d¡| _dS )ztSet up a TCP server to receive log messages, and a SocketHandler
        pointing to that server's address and port.Ng{®Gáz„?rÒ   r   r   )r   r<   rW  Ú	sock_hdlrÚserver_exceptionÚserver_classÚaddressÚhandle_socketrý   rá   rM  r  r   r4   ZSocketHandlerÚ
isinstanceÚserver_addressrN   r:  Ú
log_outputr%   r>   r6   rû   Z	Semaphorerq  )r8   rW  r]  Úhclsr:   r:   r;   r<   r  s$    

zSocketHandlerTest.setUpc          	   C   sF   z4| j r | j | j ¡ | j  ¡  | jr2| j d¡ W dt | ¡ X dS )zShutdown the TCP server.g       @N)rÃ  r%   r>   r=   rW  rK  r   rC   )r8   r:   r:   r;   rC   Œ  s    
zSocketHandlerTest.tearDownc             C   sœ   |j }x| d¡}t|ƒdk r P t d|¡d }| |¡}x&t|ƒ|k r`|| |t|ƒ ¡ }q<W t |¡}t |¡}|  j	|j
d 7  _	| j ¡  qW d S )Nrò   z>Lr   Ú
)Z
connectionZrecvrJ   ÚstructÚunpackÚpickleÚloadsr   r™   rÊ  rÎ   rq  r  )r8   ÚrequestZconnÚchunkÚslenÚobjr”   r:   r:   r;   rÇ  —  s    



zSocketHandlerTest.handle_socketc             C   sV   | j r|  | j ¡ t d¡}| d¡ | j ¡  | d¡ | j ¡  |  | j	d¡ d S )NZtcpr‡   Úeggsz
spam
eggs
)
rÄ  ÚskipTestr   r   rs   rq  r  rv   rI   rÊ  )r8   r½   r:   r:   r;   Útest_output¦  s    




zSocketHandlerTest.test_outputc             C   sž   | j r|  | j ¡ d| j_| j d¡ ytdƒ‚W n  tk
rR   | j d¡ Y nX | j 	d¡ t
 
¡ }|  | jj|¡ t
 | jj| d ¡ | j 	d¡ d S )Ng      @g       @zDeliberate mistakez
Never sentzNever sent, eithergü©ñÒMbP?zNor this)rÄ  rÖ  rÃ  Z
retryStartrW  rK  r   r%   rœ  rs   rô   r  Z	retryTimerö   )r8   Únowr:   r:   r;   Útest_noserver±  s    zSocketHandlerTest.test_noserverN)rZ   r[   r\   r]   r_  rÅ  rÆ  r<   rC   rÇ  r×  rÙ  r:   r:   r:   r;   rÂ  k  s   rÂ  c              C   s*   t jddd\} }t | ¡ t |¡ |S )Nrµ  z.sock)r–   r¶  )rÕ   rÖ   r×   r=   r©  )rä   rå   r:   r:   r;   Ú_get_temp_domain_socketÄ  s    

rÚ  zUnix sockets requiredc               @   s.   e Zd ZdZeedƒreZdd„ Zdd„ Z	dS )ÚUnixSocketHandlerTestz)Test for SocketHandler with unix sockets.ri  c             C   s   t ƒ | _t | ¡ d S )N)rÚ  rÆ  rÂ  r<   )r8   r:   r:   r;   r<   Ô  s    zUnixSocketHandlerTest.setUpc             C   s   t  | ¡ t | j¡ d S )N)rÂ  rC   r   rØ   rÆ  )r8   r:   r:   r;   rC   Ù  s    
zUnixSocketHandlerTest.tearDownN)
rZ   r[   r\   r]   r  r8  rj  rÅ  r<   rC   r:   r:   r:   r;   rÛ  Ì  s
   
rÛ  c               @   s8   e Zd ZdZeZdZdd„ Zdd„ Zdd„ Z	d	d
„ Z
dS )ÚDatagramHandlerTestzTest for DatagramHandler.)rÒ   r   c          
   C   sÜ   t  | ¡ d | _ | _| _y$|  | j| jd¡ | _}| ¡  W n( t	k
rh } z
|| _dS d}~X Y nX |j
 ¡  tjj}t|jtƒr˜|d|jƒ| _n||jdƒ| _d| _| j | jjd ¡ | j | j¡ t ¡ | _dS )zvSet up a UDP server to receive log messages, and a DatagramHandler
        pointing to that server's address and port.Ng{®Gáz„?rÒ   r   r   )r   r<   rW  rÃ  rÄ  rÅ  rÆ  Úhandle_datagramrý   rá   rM  r  r   r4   ZDatagramHandlerrÈ  rÉ  rN   r:  rÊ  r%   r>   r6   rû   r  rq  )r8   rW  r]  rË  r:   r:   r;   r<   ä  s$    

zDatagramHandlerTest.setUpc          	   C   sF   z4| j r| j  d¡ | jr2| j | j¡ | j ¡  W dt | ¡ X dS )zShutdown the UDP server.g       @N)rW  rK  rÃ  r%   r>   r=   r   rC   )r8   r:   r:   r;   rC   þ  s    zDatagramHandlerTest.tearDownc             C   sT   t  dd¡}|jt|ƒd … }t |¡}t |¡}|  j|j	d 7  _| j
 ¡  d S )Nz>Lr   rÌ  )rÍ  ÚpackÚpacketrJ   rÏ  rÐ  r   r™   rÊ  rÎ   rq  r  )r8   rÑ  rÓ  rß  rÔ  r”   r:   r:   r;   rÝ  	  s    

z#DatagramHandlerTest.handle_datagramc             C   s`   | j r|  | j ¡ t d¡}| d¡ | j ¡  | j ¡  | d¡ | j ¡  |  | j	d¡ d S )NZudpr‡   rÕ  z
spam
eggs
)
rÄ  rÖ  r   r   rs   rq  r  r?   rI   rÊ  )r8   r½   r:   r:   r;   r×    s    





zDatagramHandlerTest.test_outputN)rZ   r[   r\   r]   rd  rÅ  rÆ  r<   rC   rÝ  r×  r:   r:   r:   r;   rÜ  Ý  s   rÜ  c               @   s.   e Zd ZdZeedƒreZdd„ Zdd„ Z	dS )ÚUnixDatagramHandlerTestz,Test for DatagramHandler using Unix sockets.ri  c             C   s   t ƒ | _t | ¡ d S )N)rÚ  rÆ  rÜ  r<   )r8   r:   r:   r;   r<   %  s    zUnixDatagramHandlerTest.setUpc             C   s   t  | ¡ t | j¡ d S )N)rÜ  rC   r   rØ   rÆ  )r8   r:   r:   r;   rC   *  s    
z UnixDatagramHandlerTest.tearDownN)
rZ   r[   r\   r]   r  r8  rl  rÅ  r<   rC   r:   r:   r:   r;   rà    s
   
rà  c               @   s8   e Zd ZdZeZdZdd„ Zdd„ Zdd„ Z	d	d
„ Z
dS )ÚSysLogHandlerTestz!Test for SysLogHandler using UDP.)rÒ   r   c          
   C   sâ   t  | ¡ d | _ | _| _y$|  | j| jd¡ | _}| ¡  W n( t	k
rh } z
|| _dS d}~X Y nX |j
 ¡  tjj}t|jtƒr ||jd |jfƒ| _n||jƒ| _d| _| j | jjd ¡ | j | j¡ t ¡ | _dS )ztSet up a UDP server to receive log messages, and a SysLogHandler
        pointing to that server's address and port.Ng{®Gáz„?r   r   )r   r<   rW  Úsl_hdlrrÄ  rÅ  rÆ  rÝ  rý   rá   rM  r  r   r4   rà   rÈ  rÉ  rN   r:  rÊ  r%   r>   r6   rû   r  rq  )r8   rW  r]  rË  r:   r:   r;   r<   5  s$    

zSysLogHandlerTest.setUpc          	   C   sF   z4| j r| j  d¡ | jr2| j | j¡ | j ¡  W dt | ¡ X dS )zShutdown the server.g       @N)rW  rK  râ  r%   r>   r=   r   rC   )r8   r:   r:   r;   rC   O  s    zSysLogHandlerTest.tearDownc             C   s   |j | _| j ¡  d S )N)rß  rÊ  rq  r  )r8   rÑ  r:   r:   r;   rÝ  Z  s    z!SysLogHandlerTest.handle_datagramc             C   sª   | j r|  | j ¡ t d¡}| d¡ | j ¡  |  | jd¡ | j 	¡  d| j
_| d¡ | j ¡  |  | jd¡ | j 	¡  d| j
_| d¡ | j ¡  |  | jd¡ d S )NZslhu   spÃ¤ms
   <11>spÃ¤m Fs	   <11>spÃ¤mu   hÃ¤m-s   <11>hÃ¤m-spÃ¤m)rÄ  rÖ  r   r   rs   rq  r  rI   rÊ  r?   râ  Z
append_nulÚident)r8   r½   r:   r:   r;   r×  ^  s     








zSysLogHandlerTest.test_outputN)rZ   r[   r\   r]   rd  rÅ  rÆ  r<   rC   rÝ  r×  r:   r:   r:   r;   rá  .  s   rá  c               @   s.   e Zd ZdZeedƒreZdd„ Zdd„ Z	dS )ÚUnixSysLogHandlerTestz)Test for SysLogHandler with Unix sockets.ri  c             C   s   t ƒ | _t | ¡ d S )N)rÚ  rÆ  rá  r<   )r8   r:   r:   r;   r<   y  s    zUnixSysLogHandlerTest.setUpc             C   s   t  | ¡ t | j¡ d S )N)rá  rC   r   rØ   rÆ  )r8   r:   r:   r;   rC   ~  s    
zUnixSysLogHandlerTest.tearDownN)
rZ   r[   r\   r]   r  r8  rl  rÅ  r<   rC   r:   r:   r:   r;   rä  q  s
   
rä  z$IPv6 support required for this test.c                   s4   e Zd ZdZeZdZ‡ fdd„Z‡ fdd„Z‡  Z	S )ÚIPv6SysLogHandlerTestz&Test for SysLogHandler with IPv6 host.)z::1r   c                s   t j| j_tt| ƒ ¡  d S )N)r8  ZAF_INET6rÅ  rk  r  rå  r<   )r8   )r  r:   r;   r<   ‹  s    
zIPv6SysLogHandlerTest.setUpc                s   t j| j_tt| ƒ ¡  d S )N)r8  ÚAF_INETrÅ  rk  r  rå  rC   )r8   )r  r:   r;   rC     s    
zIPv6SysLogHandlerTest.tearDown)
rZ   r[   r\   r]   rd  rÅ  rÆ  r<   rC   r	  r:   r:   )r  r;   rå  ‚  s
   rå  c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚHTTPHandlerTestzTest for HTTPHandler.c             C   s   t  | ¡ t ¡ | _dS )ztSet up an HTTP server to receive log messages, and a HTTPHandler
        pointing to that server's address and port.N)r   r<   rû   r  rq  )r8   r:   r:   r;   r<   –  s    
zHTTPHandlerTest.setUpc             C   sr   |j | _ t|jƒ| _| j dkrRy t|jd ƒ}|j |¡| _W n   d | _Y nX | 	d¡ | 
¡  | j ¡  d S )NrÐ   zContent-LengthéÈ   )Úcommandr   rÞ   Úlog_dataÚintZheadersZrfilerP   Ú	post_dataZsend_responseZend_headersrq  r  )r8   rÑ  Zrlenr:   r:   r;   Úhandle_requestœ  s    

zHTTPHandlerTest.handle_requestc          	   C   sì  t  d¡}| j}| | jjd ¡ xÂdD ]¸}d}|rœydd l}W n tk
r\   d }Y q¤X tj 	t
¡}tj |d¡}| |j¡}| |¡ |j|d}	nd }d }	t|| jd|d | _}
|
 ¡  |
j ¡  d	|
j }|oÞ|}t jj|d
||	dd| _d | _| | j¡ x´dD ]¬}|| j_| j ¡  d}| |¡ | j ¡  |  | jjd
¡ |  | j |¡ |dkrtt!| jj"ƒ}nt!| j# $d¡ƒ}|  |d dg¡ |  |d dg¡ |  |d |g¡ qW | j %d¡ | j | j¡ | j &¡  q*W d S )NZhttpr   )FT)rÒ   r   zkeycert.pem)Zcafileg{®Gáz„?)r[  zlocalhost:%dz/frob)ÚfooÚbar)ÚsecureÚcontextZcredentials)rÏ   rÐ   u   spÃ¤mrÏ   zutf-8r9   ZfuncNamer×  rÎ   g       @)'r   r   r%   r>   r4   ÚsslÚImportErrorr×   rÞ   ÚdirnameÚ__file__r“   Z
SSLContextZPROTOCOL_TLS_SERVERZload_cert_chainZcreate_default_contextrP  rí  rW  rý   rM  r  Zserver_portrã   Zh_hdlrrê  r6   ræ   rq  r?   rs   rI   ré  r   Zqueryrì  ÚdecoderK  r=   )r8   r½   r%   rð  r>  rò  r[  ÚhereZlocalhost_certrñ  rW  ZhostZsecure_clientræ   rÎ   Údr:   r:   r;   r×  ©  s\    











zHTTPHandlerTest.test_outputN)rZ   r[   r\   r]   r<   rí  r×  r:   r:   r:   r;   rç  “  s   rç  c               @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú
MemoryTestz*Test memory persistence of logger objects.c             C   s   t  | ¡ i | _dS )z8Create a dict to remember potentially destroyed objects.N)r   r<   Ú
_survivors)r8   r:   r:   r;   r<   ä  s    
zMemoryTest.setUpc             G   s2   x,|D ]$}t |ƒt|ƒf}t |¡| j|< qW dS )zKWatch the given objects for survival, by creating weakrefs to
        them.N)Úidr2  ÚweakrefÚrefrú  )r8   rï   rÔ  Úkeyr:   r:   r;   Ú_watch_for_survivalé  s    
zMemoryTest._watch_for_survivalc             C   s`   t  ¡  g }x.| j ¡ D ] \\}}}|ƒ dkr| |¡ qW |r\|  dt|ƒd |¡f ¡ dS )z;Assert that all objects watched for survival have survived.Nz;%d objects should have survived but have been destroyed: %sz, )ÚgcZcollectrú  r¹   rt  rM   rJ   r“   )r8   ZdeadZid_Úrepr_rý  r:   r:   r;   Ú_assertTruesurvivalð  s    
zMemoryTest._assertTruesurvivalc             C   sŒ   | j  tj¡ t d¡}|  |¡ | tj¡ | j  |  ¡ ¡ | |  ¡ ¡ |  	dg¡ ~|  
¡  t d¡}| |  ¡ ¡ |  	ddg¡ d S )Nrî  )rî  r,   re   )rî  r,   rf   )r%   r+   r   rj   r   rÿ  r,   rv   rY   rV   r  )r8   rî  rï  r:   r:   r;   Útest_persistent_loggersü  s    


z"MemoryTest.test_persistent_loggersN)rZ   r[   r\   r]   r<   rÿ  r  r  r:   r:   r:   r;   rù  à  s
   rù  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚEncodingTestc          	   C   s¶   t  d¡}t dd¡\}}t |¡ d}zpt j|dd}| |¡ z| |¡ W d | 	|¡ | ¡  X t
|dd}z|  | ¡  ¡ |¡ W d | ¡  X W d tj |¡r°t |¡ X d S )NÚtestz.logztest_logging-1-u   fooÂ€zutf-8)Úencoding)r   r   rÕ   rÖ   r×   r=   rë   r6   rt   r>   r  rI   rP   ÚrstriprÞ   Úisfiler©  )r8   rr   rä   rå   r!  r‹   r›   r:   r:   r;   Útest_encoding_plain_file  s"    




z%EncodingTest.test_encoding_plain_filec          	   C   s€   t  d¡}d}t d¡}d|_t ¡ }||dƒ}t  |¡}| |¡ z| 	|¡ W d | 
|¡ | ¡  X | ¡ }|  |d¡ d S )Nr  u   Ð´Ð¾ ÑÐ²Ð¸Ð´Ð°Ð½Ð¸ÑÚcp1251Ústricts   äî ñâèäàíèÿ
)r   r   ÚcodecsÚ	getwriterr  r(   ÚBytesIOr-   r6   rt   r>   r=   rG   rI   )r8   rr   ÚmessageZwriter_classr*   Úwriterr‹   rU   r:   r:   r;   Útest_encoding_cyrillic_unicode/  s    






z+EncodingTest.test_encoding_cyrillic_unicodeN)rZ   r[   r\   r	  r  r:   r:   r:   r;   r    s   r  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚWarningsTestc          	   C   sÒ   t  ¡ À t d¡ |  tjd¡ t jdtd t ¡ }t 	|¡}t 
d¡}| |¡ t  d¡ | |¡ | ¡ }| ¡  |  | d¡d¡ t ¡ }t  d	td
d|d¡ | ¡ }| ¡  |  |d¡ W d Q R X d S )NTFÚalways)Úcategoryzpy.warningszI'm warning you...z UserWarning: I'm warning you...
r   ÚExplicitzdummy.pyé*   z
Dummy linez0dummy.py:42: UserWarning: Explicit
  Dummy line
)ÚwarningsÚcatch_warningsr   ÚcaptureWarningsr‚   ÚfilterwarningsÚUserWarningr(   r)   r-   r   r6   Úwarnr>   rG   r=   r  ÚfindÚshowwarningrI   )r8   r*   rB   r½   rU   Za_filer:   r:   r;   Útest_warningsG  s(    






zWarningsTest.test_warningsc          	   C   s~   t  ¡ l t d¡ |  tjd¡ t d¡}|  |jg ¡ t  dt	dd¡ |  t
|jƒd¡ |  |jd tj¡ W d Q R X d S )	NTFzpy.warningsr  zdummy.pyr  rW   r   )r  r  r   r  r‚   r   rI   r4   r  r  rJ   ÚassertIsInstanceÚNullHandler)r8   r½   r:   r:   r;   Útest_warnings_no_handlers_  s    


z&WarningsTest.test_warnings_no_handlersN)rZ   r[   r\   r  r"  r:   r:   r:   r;   r  E  s   r  c             C   s   t  | |¡S )N)r   r/   )rY  r¸  r:   r:   r;   Ú
formatFuncm  s    r#  c               C   s   t  ¡ S )N)r   r-   r:   r:   r:   r;   ÚhandlerFuncp  s    r$  c               @   s   e Zd ZdS )ÚCustomHandlerN)rZ   r[   r\   r:   r:   r:   r;   r%  s  s   r%  c            
   @   sè  e Zd ZdZejZdZddddiidddd	d
dœiddgdœdœZddddiidddd	d
dœidddgdœiddidœZddddiidddd	d
dœidddiiddgdœdœZ	ddddiidddd	ddœidddgdœiddidœZ
ddddiiddddd
dœidddgdœiddidœZddddiidddd	d
dœidddgdœiddidœZddddiidddd	d
dœidddgdœiddidœZdde d ddœidddd	d
dœid	dgdœdœZdeddœe d ddœeddœdœddd	d
dœdeidœd	dgdœdœZddddiide d dd	d
dœidddgdœiddidœZddddiide d dd	d
dd œidddgdœiddidœZddddiidddd	d
dœid!ddgdœiddidœZdd"dddiidddd	d
dœiddgdœi d#œddid$œZdd%dddiidddd	d
dœiddgdœi d#œddid$œZddddiiddddd
dœidddgdœidd	idœZdd%dddiiddd&iid'œZdd%ddd&iiddd&iid'œZddddiid(d)diidddd	d
d(gd*œiddd(gd+œiddgdœd,œZddddiidddd	d
dœid-dd.idddgdœiddid/œZdddiidddd	d
dœid-dd.idddgdœiddid0œZd1dddiidddd	d
dœid-dd.idddgdœiddid/œZddddiidddd	d
d2d3d4œd5œiddgdœdœZdd6d7d8d9œiddd6d:œd;d<d6d=dd>œd?œd@ddAgdBdCœidDœZ dEdF„ Z!dGdH„ Z"efdIdJ„Z#dKdL„ Z$dMdN„ Z%dOdP„ Z&dQdR„ Z'dSdT„ Z(dUdV„ Z)dWdX„ Z*dYdZ„ Z+d[d\„ Z,d]d^„ Z-d_d`„ Z.dadb„ Z/dcdd„ Z0dedf„ Z1dgdh„ Z2didj„ Z3dkdl„ Z4dmdn„ Z5d|dpdq„Z6drds„ Z7dtdu„ Z8dvdw„ Z9dxdy„ Z:dzd{„ Z;doS )}ÚConfigDictTestz)Reading logging config from a dictionary.z^(\w+) \+\+ (\w+)$rW   Úform1rY  z%(levelname)s ++ %(message)sÚhand1zlogging.StreamHandlerr…   zext://sys.stdout)r¹  Ú	formatterr'  r*   rh   )r'  r4   )rº  r»  r4   r°  zcompiler.parserr,   r'  )rº  r»  r4   Úloggersr°  zext://sys.stdboutZNTOSETZWRANINGZmisspelled_namez.ExceptionFormatterz"%(levelname)s:%(name)s:%(message)s)z()rY  z.formatFunc)r'  Zform2Zform3z())r(  Zhand2z.CustomHandlerzinvalid parameter name)r¹  r)  r'  r*   rn   zcompiler.lexerF)Úcompilerzcompiler.lexer)rº  r²  r»  r4   r*  r°  Trj   )rº  Zincrementalr4   r*  Zfilt1r9   )r¹  r)  r'  r*   Úfilters)r'  r,  )rº  r»  r,  r4   r*  r°  zcfg://true_formatterszcfg://handler_configs[hand1])rº  Útrue_formattersÚhandler_configsr»  r4   r*  r°  )r-  r.  r»  r4   r*  r°  r‘   rï  z!
)rî  Ú
terminator)r¹  r)  r'  r*   r   ZmySimpleFormatterz1%(asctime)s (%(name)s) %(levelname)s: %(message)sú$)rY  Ústyle)r¹  r'  r)  zlogging.handlers.MemoryHandleré   Ú
fileGlobal)r¹  Zcapacityr)  rú   r'  )r3  ÚbufferGlobalÚmymoduler4  Útrue)r'  r4   rz  )rº  r»  r4   r*  c             C   s   t j |¡ d S )N)r   rŠ  Z
dictConfig)r8   rŒ  r:   r:   r;   r  ð
  s    zConfigDictTest.apply_configc          	   C   sb   t  ¡ P}|  | j¡ t ¡ }| |  ¡ ¡ | |  ¡ ¡ | j	dg|d |  	g ¡ W d Q R X d S )N)rd   re   )r*   )
r   r  r  r‘  r   r   ru   rY   rs   rV   )r8   r’  r½   r:   r:   r;   r“  ó
  s    
zConfigDictTest.test_config0_okc          	   C   sd   t  ¡ R}|  |¡ t d¡}| |  ¡ ¡ | |  ¡ ¡ | jddg|d |  g ¡ W d Q R X d S )Nzcompiler.parser)rj   rc   )rd   re   )r*   )	r   r  r  r   r   ru   rY   rs   rV   )r8   rŠ  r’  r½   r:   r:   r;   r–    s    


zConfigDictTest.test_config1_okc             C   s   |   t| j| j¡ d S )N)rÆ   rþ   r  r—  )r8   r:   r:   r;   r˜    s    z#ConfigDictTest.test_config2_failurec             C   s   |   t| j| j¡ d S )N)rÆ   rþ   r  Úconfig2a)r8   r:   r:   r;   Útest_config2a_failure  s    z$ConfigDictTest.test_config2a_failurec             C   s   |   t| j| j¡ d S )N)rÆ   rþ   r  Úconfig2b)r8   r:   r:   r;   Útest_config2b_failure  s    z$ConfigDictTest.test_config2b_failurec             C   s   |   t| j| j¡ d S )N)rÆ   rþ   r  r™  )r8   r:   r:   r;   rš    s    z#ConfigDictTest.test_config3_failurec          	   C   st   t  ¡ b}|  | j¡ y
tƒ ‚W n tk
r>   t d¡ Y nX tj 	d¡ |  
| ¡ d¡ |  g ¡ W d Q R X d S )Nzjust testingr   z-ERROR:root:just testing
Got a [RuntimeError]
)r   r  r  r›  r   r   rœ  rÓ   r  rž  rI   rG   rV   )r8   r’  r:   r:   r;   rŸ  !  s    


zConfigDictTest.test_config4_okc          	   C   st   t  ¡ b}|  | j¡ y
tƒ ‚W n tk
r>   t d¡ Y nX tj 	d¡ |  
| ¡ d¡ |  g ¡ W d Q R X d S )Nzjust testingr   z-ERROR:root:just testing
Got a [RuntimeError]
)r   r  r  Úconfig4ar   r   rœ  rÓ   r  rž  rI   rG   rV   )r8   r’  r:   r:   r;   Útest_config4a_ok0  s    


zConfigDictTest.test_config4a_okc             C   s   | j | jd d S )N)rŠ  )r–  r   )r8   r:   r:   r;   r¡  ?  s    zConfigDictTest.test_config5_okc             C   s   |   t| j| j¡ d S )N)rÆ   rþ   r  r¢  )r8   r:   r:   r;   Útest_config6_failureB  s    z#ConfigDictTest.test_config6_failurec          	   C   sÞ   t  ¡ T}|  | j¡ t d¡}| |  ¡ ¡ | |  ¡ ¡ | j	ddg|d |  	g ¡ W d Q R X t  ¡ j}|  | j
¡ t d¡}|  |j¡ t d¡}| |  ¡ ¡ | |  ¡ ¡ | j	ddg|d |  	g ¡ W d Q R X d S )Nzcompiler.parser)rj   rc   )rd   re   )r*   zcompiler.lexer)rj   rf   )rd   rg   )r   r  r  rÁ  r   r   ru   rY   rs   rV   r¦  r7   r   )r8   r’  r½   r:   r:   r;   r¨  E  s,    




zConfigDictTest.test_config7_okc          	   C   sþ   t  ¡ T}|  | j¡ t d¡}| |  ¡ ¡ | |  ¡ ¡ | j	ddg|d |  	g ¡ W d Q R X t  ¡ Š}|  | j
¡ t d¡}|  |j¡ | |  ¡ ¡ | |  ¡ ¡ t d¡}| |  ¡ ¡ | |  ¡ ¡ | j	dddd	g|d |  	g ¡ W d Q R X d S )
Nzcompiler.parser)rj   rc   )rd   re   )r*   zcompiler.lexer)rj   rf   )rd   rg   )rj   ri   )rd   rk   )r   r  r  rÁ  r   r   ru   rY   rs   rV   r¯  rÝ   r   )r8   r’  r½   r:   r:   r;   Útest_config_8_okb  s4    




zConfigDictTest.test_config_8_okc          	   C   s&  t  ¡ n}|  | j¡ t d¡}t d¡}| |  ¡ ¡ | |  ¡ ¡ | 	|  ¡ ¡ | j
dddg|d |  
g ¡ W d Q R X t  ¡ ˜}|  | j¡ t d¡}|  |j¡ | |  ¡ ¡ | |  ¡ ¡ t d¡}| |  ¡ ¡ | |  ¡ ¡ | 	|  ¡ ¡ | j
dd	d
dg|d |  
g ¡ W d Q R X d S )Nzcompiler.parserzcompiler-hyphenated)rj   rc   )rd   re   )rb   rf   )r*   zcompiler.lexer)rj   rg   )rd   ri   )rj   rk   )rd   rl   )r   r  r  r¤  r   r   ru   rY   rs   r¥  rV   Úconfig8arÝ   r   )r8   r’  r½   r§  r:   r:   r;   Útest_config_8a_okƒ  s<    





z ConfigDictTest.test_config_8a_okc          	   C   sœ   t  ¡ Š}|  | j¡ t d¡}| |  ¡ ¡ | jg |d |  | j	¡ | |  ¡ ¡ | jg |d |  | j
¡ | |  ¡ ¡ | jdg|d W d Q R X d S )Nzcompiler.parser)r*   )rj   rf   )r   r  r  Úconfig9r   r   ru   rY   rV   Úconfig9aÚconfig9b)r8   r’  r½   r:   r:   r;   Útest_config_9_ok®  s    

zConfigDictTest.test_config_9_okc          	   C   s–   t  ¡ „}|  | j¡ t d¡}| |  ¡ ¡ t d¡}| |  ¡ ¡ t d¡}| |  ¡ ¡ t d¡}| |  ¡ ¡ | j	ddg|d W d Q R X d S )Nzcompiler.parserr+  zcompiler.lexerzcompiler.parser.codegen)rh   rc   )rd   rg   )r*   )
r   r  r  Úconfig10r   r   rt   rY   rs   rV   )r8   r’  r½   r:   r:   r;   Útest_config_10_okÀ  s    




z ConfigDictTest.test_config_10_okc             C   s   |   | j¡ d S )N)r–  Úconfig11)r8   r:   r:   r;   Útest_config11_okÓ  s    zConfigDictTest.test_config11_okc             C   s   |   t| j| j¡ d S )N)rÆ   rþ   r  Úconfig12)r8   r:   r:   r;   Útest_config12_failureÖ  s    z$ConfigDictTest.test_config12_failurec             C   s   |   t| j| j¡ d S )N)rÆ   rþ   r  Úconfig13)r8   r:   r:   r;   Útest_config13_failureÙ  s    z$ConfigDictTest.test_config13_failurec          	   C   sh   t  ¡ V}|  | j¡ tjd }|  |jd¡ |  |jd¡ t 	d¡ |  
| ¡  d¡¡ W d Q R X d S )Nr(  rï  z!
ZExclamationzExclamation!
)r   r  r  Úconfig14r   r   rI   rî  r/  rt   r7   rG   rr  )r8   r’  rB   r:   r:   r;   Útest_config14_okÜ  s    


zConfigDictTest.test_config14_okc          	   C   s„   dd„ }|   ¡ P t dd¡\}}t |¡ ddd|dœid	dgid
œ}|  |¡ |  |¡ W d Q R X tjjd }|  	|||¡ d S )Nc             S   s   |   ¡  t |¡ d S )N)r=   r×   r©  )rª  rå   r:   r:   r;   r«  ç  s    z0ConfigDictTest.test_config15_ok.<locals>.cleanupz.logztest_logging-X-rW   rŽ  zlogging.FileHandler)r¹  Úfilenamer4   )rº  r4   r°  r   )
r­  rÕ   rÖ   r×   r=   r  r   r°  r4   r‚   )r8   r«  rä   rå   rŠ  r‹   r:   r:   r;   Útest_config15_okå  s    


zConfigDictTest.test_config15_okNc          
   C   sì   |  d¡}tj d|¡}| ¡  |j ¡  |j}|j ¡  zˆt	 	t	j
t	j¡}| d¡ | d|f¡ t dt|ƒ¡}|| }d}t|ƒ}	x.|	dkr¶| ||d … ¡}
||
7 }|	|
8 }	qŠW | ¡  W d |j d¡ tj ¡  t |d¡ X d S )Nzutf-8r   g       @rÒ   z>L)r¾  r   rŠ  Zlistenrý   rM  r  r:  r?   r8  ræ  ZSOCK_STREAMZ
settimeoutZconnectrÍ  rÞ  rJ   Úsendr=   ZstopListeningr   rI  )r8   ÚtextZverifyrF  r:  r\  rÓ  rU   Z	sentsofarÚleftZsentr:   r:   r;   Úsetup_via_listener  s,    





z!ConfigDictTest.setup_via_listenerc          	   C   sœ   t  ¡ Š}|  t | j¡¡ t d¡}| |  	¡ ¡ t d¡}| |  	¡ ¡ t d¡}| |  	¡ ¡ t d¡}| 
|  	¡ ¡ | jddg|d W d Q R X d S )Nzcompiler.parserr+  zcompiler.lexerzcompiler.parser.codegen)rh   rc   )rd   rg   )r*   )r   r  rT  ÚjsonÚdumpsrE  r   r   rt   rY   rs   rV   )r8   r’  r½   r:   r:   r;   Útest_listen_config_10_ok  s    




z'ConfigDictTest.test_listen_config_10_okc          	   C   sl   t  ¡ Z}|  t tj¡¡ t d¡}| 	|  
¡ ¡ | |  
¡ ¡ | jddg|d |  g ¡ W d Q R X d S )Nzcompiler.parser)rj   rc   )rd   re   )r*   )r   r  rT  rˆ  r‰  r‡  rÁ  r   r   ru   rY   rs   rV   )r8   r’  r½   r:   r:   r;   Útest_listen_config_1_ok1  s    

z&ConfigDictTest.test_listen_config_1_okc          	   C   sb  dd„ }dd„ }t  d¡}t tj¡}t ¡ .}|  ||¡ | 	|  
¡ ¡ | |  
¡ ¡ W d Q R X | jg |d | jddgd	d
 t ¡ 6}|  |¡ t  d¡}| 	|  
¡ ¡ | |  
¡ ¡ W d Q R X | jddg|d | jddgd	d
 t ¡ B}|  |d d d… |¡ t  d¡}| 	|  
¡ ¡ | |  
¡ ¡ W d Q R X | jddg|d | jddgd	d
 d S )Nc             S   s   d S )Nr:   )Ústuffr:   r:   r;   Úverify_failA  s    z6ConfigDictTest.test_listen_verify.<locals>.verify_failc             S   s   | d d d… S )NrÍ   r:   )rY  r:   r:   r;   Úverify_reverseD  s    z9ConfigDictTest.test_listen_verify.<locals>.verify_reversezcompiler.parser)r*   )rj   rc   )rd   re   z^[\w.]+ -> (\w+): (\d+)$)rQ   )rj   rf   )rd   rg   rÍ   )rj   ri   )rd   rk   )r   r   rˆ  r‰  r‡  rÁ  r   r  rT  ru   rY   rs   rV   )r8   rZ  r[  r½   Zto_sendr’  r:   r:   r;   Útest_listen_verify?  sN    






z!ConfigDictTest.test_listen_verifyc             C   sB   |   | j¡ t d¡jd }|  |jtj¡ |  |jj	tj
¡ d S )Nr5  r   )r  Úout_of_orderr   r   r4   r   rú   rÅ   r)  Ú_styleÚStringTemplateStyle)r8   r‹   r:   r:   r;   Útest_out_of_order}  s
    
z ConfigDictTest.test_out_of_orderc             C   sü   ddddgdddœdd	d
dgdgdddgdœ}t j |¡}|  | d¡d¡ |  | d¡d¡ |  | d¡d¡ |  | d¡d¡ |  | d¡d¡ |  | d¡d¡ | d¡}|  | d¡dddg¡ |  t|jd¡ |  t|jd¡ |  t|jd¡ d S )N)rW   r‘   é   ré   ÚbÚcr]  ra  )rø  r›   )Úg)rB   r  Újrº   Úlrw   r‚  Úozcfg://alistÚp)ZatupleZalistZadictZnest1Znest2Znest3zcfg://atuple[1]r‘   zcfg://alist[1]zcfg://nest1[1][0]rB   zcfg://nest2[1][1]zcfg://adict.dzcfg://adict[f]zcfg://nest3rW   zcfg://nosuchzcfg://!zcfg://adict[2])	r   rŠ  ZBaseConfiguratorrI   ZconvertÚpoprÆ   ÚKeyErrorrâ   )r8   rø  Zbcr»   r:   r:   r;   Útest_baseconfig„  s$    
zConfigDictTest.test_baseconfig)N)<rZ   r[   r\   r]   r   r­  rF   r‘  rÁ  r¤  r—  r7  r9  r™  r›  r…  r#  r$  r;  r   r¢  r¦  r¯  r?  rA  rB  rC  rE  rG  rI  rK  rM  r]  r  r“  r–  r˜  r8  r:  rš  rŸ  r<  r¡  r=  r¨  r>  r@  rD  rF  rH  rJ  rL  rN  rP  rT  rW  rX  r\  r`  rk  r:   r:   r:   r;   r&  v  sj  
















!+	
>r&  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚManagerTestc                sn   g ‰ G ‡ fdd„dt jƒ}t  d ¡}|  t|jt¡ | |¡ | d¡}| d¡ t  d¡ |  	ˆ dg¡ d S )Nc                   s   e Zd Zd‡ fdd„	ZdS )z6ManagerTest.test_manager_loggerclass.<locals>.MyLoggerNc                s   ˆ   |¡ d S )N)rt  )r8   r'  rÎ   rï   Úexc_infoÚextra)Úloggedr:   r;   Ú_logŸ  s    z;ManagerTest.test_manager_loggerclass.<locals>.MyLogger._log)NN)rZ   r[   r\   rp  r:   )ro  r:   r;   ÚMyLoggerž  s   rq  r  zshould appear in loggedzshould not appear in logged)
r   ÚLoggerÚManagerrÆ   Ú	TypeErrorÚsetLoggerClassrë  r   rt   rI   )r8   rq  Úmanr½   r:   )ro  r;   Útest_manager_loggerclass›  s    




z$ManagerTest.test_manager_loggerclassc             C   s,   t  d ¡}tƒ }| |¡ |  |j|¡ d S )N)r   rs  ÚobjectÚsetLogRecordFactoryrI   ZlogRecordFactory)r8   rv  rS   r:   r:   r;   Útest_set_log_record_factory«  s    

z'ManagerTest.test_set_log_record_factoryN)rZ   r[   r\   rw  rz  r:   r:   r:   r;   rl  š  s   rl  c               @   s   e Zd Zdd„ ZdS )ÚChildLoggerTestc             C   s¦   t  ¡ }t  d¡}t  d¡}| d¡}| d¡}|  |t  d¡¡ |  |t  d¡¡ | d¡}| d¡}| d¡}|  |t  d¡¡ |  |t  d¡¡ |  ||¡ d S )	NÚabczdef.ghiZxyzzuvw.xyzÚdefZghizabc.defzabc.def.ghi)r   r   ZgetChildr*  )r8   rœ   Úl1Úl2Zc1Zc2Zc3r:   r:   r;   Útest_child_loggers²  s    






z"ChildLoggerTest.test_child_loggersN)rZ   r[   r\   r€  r:   r:   r:   r;   r{  ±  s   r{  c               @   s   e Zd ZdS )ÚDerivedLogRecordN)rZ   r[   r\   r:   r:   r:   r;   r  Â  s   r  c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚLogRecordFactoryTestc             C   sB   G dd„ dt jƒ}t | ¡ |tƒ| _| j | j¡ t  ¡ | _	d S )Nc               @   s   e Zd Zdd„ Zdd„ ZdS )z2LogRecordFactoryTest.setUp.<locals>.CheckingFilterc             S   s
   || _ d S )N)rî   )r8   rî   r:   r:   r;   r  É  s    z;LogRecordFactoryTest.setUp.<locals>.CheckingFilter.__init__c             S   s,   t |ƒ}|| jk	r(d|| jf }t|ƒ‚dS )Nz)Unexpected LogRecord type %s, expected %sT)Útyperî   rt  )r8   r”   rF  rÎ   r:   r:   r;   rš   Ì  s    

z9LogRecordFactoryTest.setUp.<locals>.CheckingFilter.filterN)rZ   r[   r\   r  rš   r:   r:   r:   r;   ÚCheckingFilterÈ  s   r„  )
r   rˆ   r   r<   r  rš   r%   r‰   ZgetLogRecordFactoryÚorig_factory)r8   r„  r:   r:   r;   r<   Ç  s
    

zLogRecordFactoryTest.setUpc             C   s(   | j  | j¡ t | ¡ t | j¡ d S )N)r%   rŠ   rš   r   rC   r   ry  r…  )r8   r:   r:   r;   rC   Ù  s    
zLogRecordFactoryTest.tearDownc             C   s@   |   t| jj|  ¡ ¡ t t¡ | j |  ¡ ¡ |  	dg¡ d S )N)r°  rd   re   )
rÆ   rt  r%   rt   rY   r   ry  r  rs   rV   )r8   r:   r:   r;   Útest_logrecord_classÞ  s    

z)LogRecordFactoryTest.test_logrecord_classN)rZ   r[   r\   r<   rC   r†  r:   r:   r:   r;   r‚  Å  s   r‚  c               @   s„   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Ze 	e
ejd
ƒd¡dd„ ƒZe 	e
ejd
ƒd¡dd„ ƒZe 	e
ejd
ƒd¡dd„ ƒZdS )ÚQueueHandlerTestz^[\w.]+ -> (\w+): (\d+)$c             C   s`   t  | ¡ t d¡| _tj | j¡| _d| _t 	d¡| _
d| j
_| j
 tj¡ | j
 | j¡ d S )NrÍ   ZqueF)r   r<   ÚqueueÚQueuer   r4   ÚQueueHandlerÚque_hdlrr9   r   Ú
que_loggerrz  r+   rh   r6   )r8   r:   r:   r;   r<   ì  s    
zQueueHandlerTest.setUpc             C   s   | j  ¡  t | ¡ d S )N)r‹  r=   r   rC   )r8   r:   r:   r;   rC   ö  s    
zQueueHandlerTest.tearDownc             C   s¢   | j  |  ¡ ¡ |  tj| jj¡ | j  |  ¡ ¡ |  tj| jj¡ |  ¡ }| j  |¡ | j ¡ }|  	t
|tjƒ¡ |  |j| j j¡ |  |j|jf|d f¡ d S )N)rŒ  rv   rY   rÆ   rˆ  ÚEmptyÚ
get_nowaitru   rt   r7   rÈ  r   Ú	LogRecordrI   r9   rÎ   rï   )r8   rÎ   r!  r:   r:   r;   Útest_queue_handlerú  s    
z#QueueHandlerTest.test_queue_handlerc             C   sx   |   ¡ }t tj¡}d}|j| j||d}t | j¡}| j 	|¡ | j
 |¡ | j ¡ }|  ||j¡ |  ||j¡ d S )Nz {name} -> {levelname}: {message})r9   Ú	levelnamer  )rY   r   r   rh   rY  r9   r/   r0   r‹  r2   rŒ  rt   rˆ  rŽ  rI   rÎ   r  )r8   rÎ   r‘  Zlog_format_strZformatted_msgr)  Z
log_recordr:   r:   r;   Útest_formatting  s    

z QueueHandlerTest.test_formattingÚQueueListenerz5logging.handlers.QueueListener required for this testc             C   st  t  t  ¡ ¡}tj | j|¡}| ¡  z4| j 	|  
¡ ¡ | j |  
¡ ¡ | j |  
¡ ¡ W d | ¡  X |  |jtjdd¡ |  |jtjdd¡ |  |jtjdd¡ | ¡  t  t  ¡ ¡}| tj¡ tjj| j|dd}| ¡  z4| j 	|  
¡ ¡ | j |  
¡ ¡ | j |  
¡ ¡ W d | ¡  X |  |jtjdd¡ |  |jtjdd¡ |  |jtjd	d¡ | ¡  d S )
Nrc   )r²   r  re   rf   T)Zrespect_handler_levelrg   ri   rk   )r   ZTestHandlerZMatcherr   r4   r“  rˆ  rý   rŒ  rt   rY   rs   r¥  rK  r7   Úmatchesrh   rd   rb   r=   r+   rÝ   )r8   r‹   Úlistenerr:   r:   r;   Útest_queue_listener  s4    

z$QueueHandlerTest.test_queue_listenerc          
   C   sŠ   t j | j| j¡}| ¡  ydd  W n: tk
r` } z|}| jj|  	¡ |d W d d }~X Y nX | 
¡  |  | j ¡  ¡  d¡d¡ d S )NrW   r   )rm  Z	Traceback)r   r4   r“  rˆ  r.   rý   ÚZeroDivisionErrorrŒ  rœ  rY   rK  rI   r*   rG   r½  Úcount)r8   r•  r]  Úexcr:   r:   r;   Ú&test_queue_listener_with_StreamHandler6  s    &z7QueueHandlerTest.test_queue_listener_with_StreamHandlerc             C   sd   | j  | j¡ | j | j¡ tj | j	| j ¡}| 
¡  | j d¡ | ¡  |  | j ¡  ¡ d¡ d S )Nrs   zque -> ERROR: error)r‹  r2   r1   rŒ  r6   r.   r   r4   r“  rˆ  rý   rs   rK  rI   r*   rG   r½  )r8   r•  r:   r:   r;   Ú*test_queue_listener_with_multiple_handlersD  s    z;QueueHandlerTest.test_queue_listener_with_multiple_handlersN)rZ   r[   r\   rF   r<   rC   r  r’  r  Ú
skipUnlessr  r   r4   r–  rš  r›  r:   r:   r:   r;   r‡  è  s   
"r‡  r“  )Úpatchc               @   sl   e Zd ZdZdZedd„ ƒZe e	j
jd¡dd„ ƒZe e	j
jd¡dd	„ ƒZed
d„ ƒZdd„ Zdd„ ZdS )ÚQueueListenerTestz~
        Tests based on patch submitted for issue #27930. Ensure that
        QueueListener handles all log messages.
        é   c             C   s”   t  d| ¡}| t j¡ t j | ¡}| |¡ t j | ¡}| ¡  | 	d¡ | 	d¡ | 	d¡ | 	d¡ | 	d¡ | 
¡  | |¡ | ¡  dS )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.
            ztest_logger_with_id_%sÚoneÚtwoZthreeZfourZfiveN)r   r   r+   r,   r4   rŠ  r6   r“  rý   ru   rK  r>   r=   )Ú	log_queuerã  r½   r‹   r•  r:   r:   r;   Úsetup_and_log]  s    






zQueueListenerTest.setup_and_logrÜ   c             C   sN   x2t | jƒD ]$}t ¡ }|  |d|  ¡ |f ¡ qW |  |jd| j d¡ d S )Nz%s_%sr2  z&correct number of handled log messages)ró   Úrepeatrˆ  r‰  r£  rû  rI   Ú
call_count)r8   Úmock_handler  r¢  r:   r:   r;   Ú#test_handle_called_with_queue_queueu  s
    z5QueueListenerTest.test_handle_called_with_queue_queuec             C   sh   t  d¡ xBt| jƒD ]4}t ¡ }|  |d|  ¡ |f ¡ | ¡  | 	¡  qW |  
|jd| j d¡ d S )Nzmultiprocessing.synchronizez%s_%sr2  z&correct number of handled log messages)r   Úimport_moduleró   r¤  Úmultiprocessingr‰  r£  rû  r=   rI  rI   r¥  )r8   r¦  r  r¢  r:   r:   r;   Ú test_handle_called_with_mp_queue}  s    
z2QueueListenerTest.test_handle_called_with_mp_queuec             c   s0   yx|   ¡ V  qW W n tjk
r*   g S X d S )N)rŽ  rˆ  r  )r¢  r:   r:   r;   Úget_all_from_queueŠ  s
    z$QueueListenerTest.get_all_from_queuec             C   sŒ   t  d¡ x|t| jƒD ]n}t ¡ }|  |d|  ¡ |f ¡ t|  	|¡ƒ}| 
¡  | ¡  g tjjjgg}|  ||ddd„ |D ƒ ¡ qW dS )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.
            zmultiprocessing.synchronizez%s_%sz&Found unexpected messages in queue: %sc             S   s"   g | ]}t |tjƒr|jn|‘qS r:   )rÈ  r   r  rÎ   )r~  rw   r:   r:   r;   r€  §  s   zJQueueListenerTest.test_no_messages_in_queue_after_stop.<locals>.<listcomp>N)r   r¨  ró   r¤  r©  r‰  r£  rû  Úlistr«  r=   rI  r   r4   r“  Z	_sentinelr,  )r8   r  rˆ  r¹   rS   r:   r:   r;   Ú$test_no_messages_in_queue_after_stop’  s    	
z6QueueListenerTest.test_no_messages_in_queue_after_stopc          	   C   sF   t  ¡ }tj |¡}| ¡  | ¡  |  t¡ | 	¡  W d Q R X d S )N)
rˆ  r‰  r   r4   r“  rý   rK  rÆ   râ   Z	task_done)r8   r¢  r•  r:   r:   r;   Útest_calls_task_done_after_stopª  s    z1QueueListenerTest.test_calls_task_done_after_stopN)rZ   r[   r\   r]   r¤  Ústaticmethodr£  r  rx  r   r4   r“  r§  rª  r«  r­  r®  r:   r:   r:   r;   rž  U  s   rž  c               @   s    e Zd Zdd„ ZeZdd„ ZdS )ÚUTCc             C   s   t S )N)ÚZERO)r8   Údtr:   r:   r;   Ú	utcoffset¸  s    zUTC.utcoffsetc             C   s   dS )Nr°  r:   )r8   r²  r:   r:   r;   Útzname½  s    z
UTC.tznameN)rZ   r[   r\   r³  Údstr´  r:   r:   r:   r;   r°  ·  s   r°  c               @   sF   e Zd Zdd„ Zddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dS )ÚFormatterTestc          	   C   s0   dt jtj ddd¡dd d dddœ| _i | _d S )	Nzformatter.testrÞ   Útoz	dummy.extr  zMessage with %d %s)r‘   Zplaceholders)r9   r'  ÚpathnameÚlinenorm  ÚfuncrÎ   rï   )r   r,   r×   rÞ   r“   ÚcommonÚvariants)r8   r:   r:   r;   r<   Ã  s    
zFormatterTest.setUpNc             C   s,   t | jƒ}|d k	r"| | j| ¡ t |¡S )N)r¿  r»  r@   r¼  r   r™   )r8   r9   Úresultr:   r:   r;   Ú
get_recordÑ  s    
zFormatterTest.get_recordc             C   s˜   |   ¡ }t d¡}|  | |¡d¡ t d¡}|  t|j|¡ |  | ¡ ¡ t d¡}|  	| ¡ ¡ t d¡}|  	| ¡ ¡ t d¡}|  | ¡ ¡ d S )Nz${%(message)s}z${Message with 2 placeholders}z
%(random)sz%(asctime)sz%(asctime)-15sÚasctime)
r¾  r   r/   rI   rY  rÆ   rj  rÝ   ÚusesTimer7   )r8   rœ   r›   r:   r:   r;   Útest_percent×  s    




zFormatterTest.test_percentc             C   sÈ   |   ¡ }tjddd}|  | |¡d¡ tjddd}|  t|j|¡ |  | ¡ ¡ tjddd}|  	| ¡ ¡ tjddd}|  	| ¡ ¡ tjddd}|  	| ¡ ¡ tjd	dd}|  | ¡ ¡ d S )
Nz$%{message}%$Ú{)r1  z$%Message with 2 placeholders%$z{random}z	{asctime}z{asctime!s:15}z{asctime:15}r¿  )
r¾  r   r/   rI   rY  rÆ   rj  rÝ   rÀ  r7   )r8   rœ   r›   r:   r:   r;   Útest_bracesæ  s    zFormatterTest.test_bracesc             C   sè   |   ¡ }tjddd}|  | |¡d¡ tjddd}|  | |¡d¡ tjddd}|  t|j|¡ |  | ¡ ¡ tjddd}|  	| ¡ ¡ tjd	dd}|  | ¡ ¡ tjd
dd}|  	| ¡ ¡ tjddd}|  | ¡ ¡ d S )Nz$messager0  )r1  zMessage with 2 placeholdersz$$%${message}%$$z$%Message with 2 placeholders%$z	${random}z
${asctime}z	${asctimez$asctimer¿  )
r¾  r   r/   rI   rY  rÆ   rj  rÝ   rÀ  r7   )r8   rœ   r›   r:   r:   r;   Útest_dollars÷  s     zFormatterTest.test_dollarsc             C   s   |   ttjd d d¡ d S )NÚx)rÆ   râ   r   r/   )r8   r:   r:   r;   Útest_invalid_style
  s    z FormatterTest.test_invalid_stylec          
   C   s   |   ¡ }t dddddddt¡}t | d ¡ ¡ ¡|_d|_t	 
d¡}tj|_|  | |¡d	¡ |  | |d
¡d¡ | |¡ |  |jd	¡ d S )NiÉ  rò   é   é   ra  r   é{   z%(asctime)s %(message)sz1993-04-21 08:03:00,123z%Y:%dz1993:21)r¾  ÚdatetimeÚutcrô   ZmktimeZ
astimezoneZ	timetupleZcreatedZmsecsr   r/   ÚgmtimeZ	converterrI   Z
formatTimerY  r¿  )r8   rœ   r²  r›   r:   r:   r;   Ú	test_time  s    

zFormatterTest.test_time)N)
rZ   r[   r\   r<   r¾  rÁ  rÃ  rÄ  rÆ  rÍ  r:   r:   r:   r;   r¶  Â  s   
r¶  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestBufferingFormatterc             C   s   dt |ƒ S )Nz[(%d))rJ   )r8   Úrecordsr:   r:   r;   ÚformatHeader  s    z#TestBufferingFormatter.formatHeaderc             C   s   dt |ƒ S )Nz(%d)])rJ   )r8   rÏ  r:   r:   r;   ÚformatFooter  s    z#TestBufferingFormatter.formatFooterN)rZ   r[   r\   rÐ  rÑ  r:   r:   r:   r;   rÎ    s   rÎ  c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚBufferingFormatterTestc             C   s"   t  ddi¡t  ddi¡g| _d S )NrÎ   r   r¡  )r   r™   rÏ  )r8   r:   r:   r;   r<   #  s    zBufferingFormatterTest.setUpc             C   s2   t  ¡ }|  d| g ¡¡ |  d| | j¡¡ d S )Nr   Zonetwo)r   ÚBufferingFormatterrI   rY  rÏ  )r8   r›   r:   r:   r;   Útest_default)  s    z#BufferingFormatterTest.test_defaultc             C   sD   t ƒ }|  d| | j¡¡ t d¡}t |ƒ}|  d| | j¡¡ d S )Nz[(2)onetwo(2)]z<%(message)s>z[(2)<one><two>(2)])rÎ  rI   rY  rÏ  r   r/   )r8   r›   Zlfr:   r:   r;   Útest_custom.  s
    
z"BufferingFormatterTest.test_customN)rZ   r[   r\   r<   rÔ  rÕ  r:   r:   r:   r;   rÒ  "  s   rÒ  c               @   s   e Zd Zdd„ ZdS )ÚExceptionTestc             C   s¦   | j }tƒ }| |¡ ytdƒ‚W n   tjddd Y nX | |¡ | ¡  |jd }|  	|j
 d¡¡ |  	|j
 d¡¡ |  	|j d¡¡ |  	|j d	¡¡ d S )
Nzdeliberate mistakeZfailedT)Ú
stack_infor   z#Traceback (most recent call last):
z!
RuntimeError: deliberate mistakezStack (most recent call last):
z,logging.exception('failed', stack_info=True))r%   ÚRecordingHandlerr6   r   r   rœ  r>   r=   rÏ  r7   Zexc_textrR  rr  r×  )r8   rœ   rB   r:   r:   r;   r’  6  s    


zExceptionTest.test_formattingN)rZ   r[   r\   r’  r:   r:   r:   r;   rÖ  5  s   rÖ  c               @   s   e Zd Zdd„ ZdS )ÚLastResortTestc          	   C   s,  | j }| | j¡ tj}tj}zît ¡ :}| d¡ |  	| 
¡ d¡ | d¡ |  	| 
¡ d¡ W d Q R X d t_t ¡ $}| d¡ d}|  	| 
¡ |¡ W d Q R X t ¡  }| d¡ |  	| 
¡ d¡ W d Q R X d|j_dt_t ¡  }| d¡ |  	| 
¡ d¡ W d Q R X W d | | j¡ |t_|t_X d S )NzThis should not appearr   zFinal chance!zFinal chance!
z-No handlers could be found for logger "root"
F)r%   r>   r.   r   Z
lastResortr)  r   r+  rv   rI   rG   rt   r   ZemittedNoHandlerWarningr6   )r8   r°  Zold_lastresortZold_raise_exceptionsr-  rÎ   r:   r:   r;   Útest_last_resortL  s4    








zLastResortTest.test_last_resortN)rZ   r[   r\   rÚ  r:   r:   r:   r;   rÙ  K  s   rÙ  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚFakeHandlerc          	   C   s(   x"dD ]}t | ||  |||¡ƒ qW d S )N)r  Úflushr=   r  )ÚsetattrÚrecord_call)r8   Ú
identifierÚcalledræ   r:   r:   r;   r  t  s    
zFakeHandler.__init__c                s   ‡ ‡‡fdd„}|S )Nc                  s   ˆ   d ˆˆ¡¡ d S )Nz{} - {})rt  rY  r:   )rà  rß  Úmethod_namer:   r;   Úinnery  s    z&FakeHandler.record_call.<locals>.innerr:   )r8   rß  rá  rà  râ  r:   )rà  rß  rá  r;   rÞ  x  s    zFakeHandler.record_callN)rZ   r[   r\   r  rÞ  r:   r:   r:   r;   rÛ  r  s   rÛ  c                   s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )rØ  c                s   t t| ƒj||Ž g | _d S )N)r  rØ  r  rÏ  )r8   rï   r  )r  r:   r;   r  €  s    zRecordingHandler.__init__c             C   s   | j  |¡ dS )z&Keep track of all the emitted records.N)rÏ  rt  )r8   r”   r:   r:   r;   rÜ   „  s    zRecordingHandler.handle)rZ   r[   r\   r  rÜ   r	  r:   r:   )r  r;   rØ  ~  s   rØ  c                   s˜   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Z‡  ZS )"ÚShutdownTestz#Test suite for the shutdown method.c                s.   t t| ƒ ¡  g | _tj}|  ttd|¡ d S )Nr)  )r  rã  r<   rà  r   r)  r‚   rÝ  )r8   Zraise_exceptions)r  r:   r;   r<     s    zShutdownTest.setUpc                s   ‡ fdd„}|S )Nc                  s
   ˆ ƒ ‚d S )Nr:   r:   )rs   r:   r;   râ  •  s    z'ShutdownTest.raise_error.<locals>.innerr:   )r8   rs   râ  r:   )rs   r;   Úraise_error”  s    zShutdownTest.raise_errorc             C   sv   t d| jƒ}t d| jƒ}t d| jƒ}ttjj|||gƒ}tjt|ƒd ddddd	d
ddddddg}|  || j¡ d S )Nr   rW   r‘   )ÚhandlerListz2 - acquirez	2 - flushz	2 - closez2 - releasez1 - acquirez	1 - flushz	1 - closez1 - releasez0 - acquirez	0 - flushz	0 - closez0 - release)	rÛ  rà  r5  r   rü  rý  rN  r¬  rI   )r8   Zhandler0Zhandler1Zhandler2r4   rS   r:   r:   r;   Útest_no_failure™  s    zShutdownTest.test_no_failurec             C   sR   t d| jƒ}t|||  |¡ƒ tj |¡g}tjt|ƒd |  	d| jd ¡ d S )Nr   )rå  z0 - releaserÍ   )
rÛ  rà  rÝ  rä  r   rü  rý  rN  r¬  rI   )r8   ræ   rs   r‹   r4   r:   r:   r;   Ú_test_with_failure_in_method©  s
    z)ShutdownTest._test_with_failure_in_methodc             C   s   |   dt¡ d S )Nr  )rç  rá   )r8   r:   r:   r;   Útest_with_ioerror_in_acquire²  s    z)ShutdownTest.test_with_ioerror_in_acquirec             C   s   |   dt¡ d S )NrÜ  )rç  rá   )r8   r:   r:   r;   Útest_with_ioerror_in_flushµ  s    z'ShutdownTest.test_with_ioerror_in_flushc             C   s   |   dt¡ d S )Nr=   )rç  rá   )r8   r:   r:   r;   Útest_with_ioerror_in_close¸  s    z'ShutdownTest.test_with_ioerror_in_closec             C   s   |   dt¡ d S )Nr  )rç  râ   )r8   r:   r:   r;   Útest_with_valueerror_in_acquire»  s    z,ShutdownTest.test_with_valueerror_in_acquirec             C   s   |   dt¡ d S )NrÜ  )rç  râ   )r8   r:   r:   r;   Útest_with_valueerror_in_flush¾  s    z*ShutdownTest.test_with_valueerror_in_flushc             C   s   |   dt¡ d S )Nr=   )rç  râ   )r8   r:   r:   r;   Útest_with_valueerror_in_closeÁ  s    z*ShutdownTest.test_with_valueerror_in_closec             C   s   dt _|  dt¡ d S )NFr  )r   r)  rç  Ú
IndexError)r8   r:   r:   r;   Ú.test_with_other_error_in_acquire_without_raiseÄ  s    z;ShutdownTest.test_with_other_error_in_acquire_without_raisec             C   s   dt _|  dt¡ d S )NFrÜ  )r   r)  rç  rî  )r8   r:   r:   r;   Ú,test_with_other_error_in_flush_without_raiseÈ  s    z9ShutdownTest.test_with_other_error_in_flush_without_raisec             C   s   dt _|  dt¡ d S )NFr=   )r   r)  rç  rî  )r8   r:   r:   r;   Ú,test_with_other_error_in_close_without_raiseÌ  s    z9ShutdownTest.test_with_other_error_in_close_without_raisec             C   s   dt _|  t| jdt¡ d S )NTr  )r   r)  rÆ   rî  rç  )r8   r:   r:   r;   Ú+test_with_other_error_in_acquire_with_raiseÐ  s    
z8ShutdownTest.test_with_other_error_in_acquire_with_raisec             C   s   dt _|  t| jdt¡ d S )NTrÜ  )r   r)  rÆ   rî  rç  )r8   r:   r:   r;   Ú)test_with_other_error_in_flush_with_raiseÕ  s    
z6ShutdownTest.test_with_other_error_in_flush_with_raisec             C   s   dt _|  t| jdt¡ d S )NTr=   )r   r)  rÆ   rî  rç  )r8   r:   r:   r;   Ú)test_with_other_error_in_close_with_raiseÚ  s    
z6ShutdownTest.test_with_other_error_in_close_with_raise)rZ   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               @   sp   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zejdd„ ƒZdd„ ZdS )ÚModuleLevelMiscTestz)Test suite for some module level methods.c             C   s`   t jjj}|  |d¡ |  t j|¡ t  d¡ |  t jjjd¡ t  ¡  |  t jjjt j¡ d S )Nr   éS   )r   r°  r   rA   rI   r‚   rb   )r8   Úold_disabler:   r:   r;   Útest_disableä  s    

z ModuleLevelMiscTest.test_disableNc                sÀ   g ‰ t  | td‡ fdd„¡ tƒ }tj |¡ tt|ƒ}|d k	rN||d|ƒ n
|d|ƒ |  t|j	ƒd¡ |j	d }|  | 
¡ d| ¡ |d k	r”|ntt| ¡ ƒ}|  |j|¡ |  ˆ g ¡ d S )NÚbasicConfigc                 s   ˆ   | |f¡S )N)rt  )ré   Úkw)rà  r:   r;   Ú<lambda>õ  ó    z/ModuleLevelMiscTest._test_log.<locals>.<lambda>ztest me: %rrW   r   )r   r  r   rØ  r°  r6   r!   rI   rJ   rÏ  Z
getMessageÚupperr²   )r8   ræ   r'  Ú	recordingÚ
log_methodr”   Zexpected_levelr:   )rà  r;   Ú	_test_logò  s    



zModuleLevelMiscTest._test_logc             C   s   |   dtj¡ d S )Nrr   )r   r   rd   )r8   r:   r:   r;   Útest_log
  s    zModuleLevelMiscTest.test_logc             C   s   |   d¡ d S )Nrv   )r   )r8   r:   r:   r;   Ú
test_debug  s    zModuleLevelMiscTest.test_debugc             C   s   |   d¡ d S )Nru   )r   )r8   r:   r:   r;   Ú	test_info  s    zModuleLevelMiscTest.test_infoc             C   s   |   d¡ d S )Nrt   )r   )r8   r:   r:   r;   Útest_warning  s    z ModuleLevelMiscTest.test_warningc             C   s   |   d¡ d S )Nrs   )r   )r8   r:   r:   r;   Ú
test_error  s    zModuleLevelMiscTest.test_errorc             C   s   |   d¡ d S )Nr¥  )r   )r8   r:   r:   r;   Útest_critical  s    z!ModuleLevelMiscTest.test_criticalc             C   s^   |   ttjt¡ G dd„ dtjƒ}t |¡ |  t ¡ |¡ t tj¡ |  t ¡ tj¡ d S )Nc               @   s   e Zd ZdS )z;ModuleLevelMiscTest.test_set_logger_class.<locals>.MyLoggerN)rZ   r[   r\   r:   r:   r:   r;   rq    s   rq  )rÆ   rt  r   ru  rx  rr  rI   ZgetLoggerClass)r8   rq  r:   r:   r;   Útest_set_logger_class  s    
z)ModuleLevelMiscTest.test_set_logger_classc             C   s8   d}t d|ƒ\}}}| ¡ }|  d|¡ |  d|¡ d S )Na&  if 1:
            import logging

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

            a = A()z-czexception in __del__zValueError: some error)r   rö  r,  )r8   ÚcodeÚrcÚoutÚerrr:   r:   r;   Útest_logging_at_shutdown(  s
    z,ModuleLevelMiscTest.test_logging_at_shutdownc             C   s8   d}t d|ƒ\}}}| ¡ }|  d|¡ |  |d¡ d S )Nz†if 1:
            import logging

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

            rec()z-cz#Cannot recover from stack overflow.rW   )r   rö  ZassertNotInrI   )r8   r  r	  r
  r  r:   r:   r;   Útest_recursion_error;  s
    	z(ModuleLevelMiscTest.test_recursion_error)N)rZ   r[   r\   r]   rø  r   r  r  r  r  r  r  r  r   Zrequires_type_collectingr  r  r:   r:   r:   r;   rõ  à  s   
rõ  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚLogRecordTestc             C   s6   t  i ¡}t|ƒ}|  | d¡¡ |  | d¡¡ d S )Nz<LogRecord: ú>)r   r™   r}  r7   rR  rr  )r8   rœ   rU   r:   r:   r;   Útest_str_repL  s    
zLogRecordTest.test_str_repc             C   sj   t ƒ }t ¡ }| |¡ ddi}t d|¡ |  |jd j|¡ |  |jd j	d¡ | 
|¡ | ¡  d S )NZlessZmorezless is %(less)sr   zless is more)rØ  r   r   r6   rt   r*  rÏ  rï   rI   r  r>   r=   )r8   rB   rœ   rø  r:   r:   r;   Útest_dict_argR  s    

zLogRecordTest.test_dict_argc             C   s\   t  i ¡}|  |jd¡ y*dd l}t  i ¡}|  |j| ¡ j¡ W n tk
rV   Y nX d S )NZMainProcessr   )r   r™   rI   ÚprocessNamer©  Zcurrent_processr9   ró  )r8   rœ   Zmpr:   r:   r;   Útest_multiprocessing]  s    

z"LogRecordTest.test_multiprocessingc             C   s²   t  i ¡}| j}||jƒ ||jƒ ||jƒ ||jƒ t j}t j}t j	}zNdt _dt _dt _	t  i ¡}| j
}||jƒ ||jƒ ||jƒ ||jƒ W d |t _|t _|t _	X d S )NF)r   r™   ÚassertIsNotNoneZthreadZ
threadNameÚprocessr  Ú
logThreadsÚlogProcessesÚlogMultiprocessingr/  )r8   rœ   ZNOT_NONEZlog_threadsZlog_processesZlog_multiprocessingZNONEr:   r:   r;   Útest_optionalg  s,    








zLogRecordTest.test_optionalN)rZ   r[   r\   r  r  r  r  r:   r:   r:   r;   r  K  s   
r  c                   sÎ   e Zd ZdZ‡ fdd„Z‡ fdd„Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd/d!d"„Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Z‡  ZS )0ÚBasicConfigTestz#Test suite for logging.basicConfig.c                sV   t t| ƒ ¡  tjj| _tj ¡ | _tj	d d … | _
tjj| _|  | j¡ g tj_d S )N)r  r  r<   r   r°  r4   r   r   r   r   r   r'  r'   r‚   r«  )r8   )r  r:   r;   r<   „  s    

zBasicConfigTest.setUpc                s@   x,t jjd d … D ]}t j |¡ | ¡  qW tt| ƒ ¡  d S )N)r   r°  r4   r>   r=   r  r  rC   )r8   rB   )r  r:   r;   rC     s    zBasicConfigTest.tearDownc             C   sF   t tjd| jƒ tj ¡  tj | j¡ | jtj	d d …< | j
tj_d S )Nr4   )rÝ  r   r°  r4   r   r?   r@   r   r   r   r'   r'  )r8   r:   r:   r;   r«  “  s
    
zBasicConfigTest.cleanupc             C   s   t  ¡  |  tt jjƒd¡ t jjd }|  |t j¡ |  |jt	j
¡ |j}|  |jjt j¡ |  |j¡ |  |jt j¡ |  t jj| j¡ d S )NrW   r   )r   rù  rI   rJ   r°  r4   r   r-   r*   rÓ   r-  r)  r^  Ú_fmtZBASIC_FORMATr/  r¸  ÚPercentStyler'  r'   )r8   r‹   r)  r:   r:   r;   Útest_no_kwargsš  s    zBasicConfigTest.test_no_kwargsc          	   C   sR   t  ¡ @}tjtjdd t d¡ tj d¡ |  | 	¡  
¡ d¡ W d Q R X d S )NrÂ  )r*   r1  zLog an errorr   zERROR:root:Log an error)r   r  r   rù  rÓ   r  rs   rž  rI   rG   r½  )r8   r’  r:   r:   r;   Útest_strformatstyle®  s    

z#BasicConfigTest.test_strformatstylec          	   C   sR   t  ¡ @}tjtjdd t d¡ tj d¡ |  | 	¡  
¡ d¡ W d Q R X d S )Nr0  )r*   r1  zLog an errorr   zERROR:root:Log an error)r   r  r   rù  rÓ   r  rs   rž  rI   rG   r½  )r8   r’  r:   r:   r;   Útest_stringtemplatestyle¶  s    

z(BasicConfigTest.test_stringtemplatestylec             C   sŠ   dd„ }t jdd |  tt jjƒd¡ t jjd }|  |t j¡ t  dd¡}|  |jj	|jj	¡ |  |jj
|jj
¡ |  |||d¡ d S )Nc             S   s   |   ¡  |  ¡  t |¡ d S )N)r=   r×   r©  )rª  Úh2rå   r:   r:   r;   r«  À  s    z.BasicConfigTest.test_filename.<locals>.cleanupztest.log)rO  rW   r   ré   )r   rù  rI   rJ   r°  r4   r   rë   r*   Úmoder9   r‚   )r8   r«  r‹   rS   r:   r:   r;   Útest_filename¾  s    zBasicConfigTest.test_filenamec             C   sV   dd„ }t jddd t jjd }t  dd¡}|  |jj|jj¡ |  |||d¡ d S )Nc             S   s   |   ¡  |  ¡  t |¡ d S )N)r=   r×   r©  )rª  r   rå   r:   r:   r;   r«  Ò  s    z.BasicConfigTest.test_filemode.<locals>.cleanupztest.logÚwb)rO  Úfilemoder   )	r   rù  r°  r4   rë   rI   r*   r!  r‚   )r8   r«  r‹   rS   r:   r:   r;   Útest_filemodeÐ  s    zBasicConfigTest.test_filemodec             C   s`   t  ¡ }|  |j¡ tj|d |  ttjj	ƒd¡ tjj	d }|  
|tj¡ |  |j|¡ d S )N)r*   rW   r   )r(   r)   r‚   r=   r   rù  rI   rJ   r°  r4   r   r-   r*   )r8   r*   r‹   r:   r:   r;   Útest_streamÞ  s    zBasicConfigTest.test_streamc             C   s.   t jdd t jjd j}|  |jjd¡ d S )Nrî  )rY  r   )r   rù  r°  r4   r)  rI   r^  r  )r8   r)  r:   r:   r;   Útest_formatè  s    zBasicConfigTest.test_formatc             C   s,   t jdd t jjd j}|  |jd¡ d S )Nrï  )r¸  r   )r   rù  r°  r4   r)  rI   r¸  )r8   r)  r:   r:   r;   Útest_datefmtî  s    zBasicConfigTest.test_datefmtc             C   s.   t jdd t jjd j}|  |jt j¡ d S )Nr0  )r1  r   )r   rù  r°  r4   r)  r   r^  r_  )r8   r)  r:   r:   r;   Ú
test_styleô  s    zBasicConfigTest.test_stylec             C   sT   t jj}|  t jj|¡ t jdd |  t jjd¡ t jdd |  t jjd¡ d S )Né9   )r'  é:   )r   r°  r'  r‚   r+   rù  rI   )r8   Ú	old_levelr:   r:   r;   Ú
test_levelú  s    zBasicConfigTest.test_levelc             C   sp   | j }t ¡ g}tj}|ttjd|d |ttjd|d |ttj||d |ttjtjd tjd dd d S )Nztest.log)rO  r*   )rO  r4   )r*   r4   )Zloglevelré   )rO  r$  )rÆ   r   r-   rÓ   r-  râ   rù  rj   )r8   rÆ   r4   r*   r:   r:   r;   Útest_incompatible  s    



z!BasicConfigTest.test_incompatiblec             C   sÒ   t  ¡ t  tj¡t  ¡ g}t  ¡ }|d  |¡ t j|d |  |d t jj	d ¡ |  |d t jj	d ¡ |  |d t jj	d ¡ |  
|d j¡ |  
|d j¡ |  |d j|¡ |  |d j|d j¡ d S )Nr‘   )r4   r   rW   )r   r-   rÓ   r  r/   r2   rù  r*  r°  r4   r  r)  )r8   r4   r›   r:   r:   r;   Útest_handlers  s    

zBasicConfigTest.test_handlersNc                sf   g ‰ t j‰‡ ‡‡fdd„}t ˆt d|¡ tt |ƒ}|d k	rH||dƒ n|dƒ ˆ ˆ di fg¡ d S )Nc                 s<   ˆƒ  t jj}t j d¡ ˆ t jj|¡ ˆ  | |f¡ d S )Néd   )r   r°  r'  r+   r‚   rt  )ré   rú  r,  )rà  Úold_basic_configr8   r:   r;   Úmy_basic_config)  s
    z2BasicConfigTest._test_log.<locals>.my_basic_configrù  ztest mer:   )r   rù  r   r  r!   rI   )r8   ræ   r'  r2  rÿ  r:   )rà  r1  r8   r;   r   $  s    
zBasicConfigTest._test_logc             C   s   |   dtj¡ d S )Nrr   )r   r   rh   )r8   r:   r:   r;   r  ;  s    zBasicConfigTest.test_logc             C   s   |   d¡ d S )Nrv   )r   )r8   r:   r:   r;   r  >  s    zBasicConfigTest.test_debugc             C   s   |   d¡ d S )Nru   )r   )r8   r:   r:   r;   r  A  s    zBasicConfigTest.test_infoc             C   s   |   d¡ d S )Nrt   )r   )r8   r:   r:   r;   r  D  s    zBasicConfigTest.test_warningc             C   s   |   d¡ d S )Nrs   )r   )r8   r:   r:   r;   r  G  s    zBasicConfigTest.test_errorc             C   s   |   d¡ d S )Nr¥  )r   )r8   r:   r:   r;   r  J  s    zBasicConfigTest.test_critical)N)rZ   r[   r\   r]   r<   rC   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                   sL   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	‡  Z
S )ÚLoggerAdapterTestc                s’   t t| ƒ ¡  tjd d … ‰ tƒ | _tj| _| j 	| j¡ |  
| jj| j¡ |  
| jj¡ ‡ fdd„}|  
|¡ |  
tj¡ tj| jd d| _d S )Nc                  s   ˆ t jd d …< d S )N)r   r   r:   )Úold_handler_listr:   r;   r«  Y  s    z(LoggerAdapterTest.setUp.<locals>.cleanup)r½   rn  )r  r3  r<   r   r   rØ  rþ  r°  r½   r6   r‚   r>   r=   rN  rq   Úadapter)r8   r«  )r  )r4  r;   r<   O  s    
zLoggerAdapterTest.setUpc          
   C   s¸   d}d }ydd  W n6 t k
rJ } z|}| j || j¡ W d d }~X Y nX |  t| jjƒd¡ | jjd }|  |jtj	¡ |  |j
|¡ |  |j| jf¡ |  |j|j||jf¡ d S )Nztesting exception: %rrW   r   )r—  r5  rœ  rþ  rI   rJ   rÏ  r²   r   rd   rÎ   rï   rm  r  Ú__traceback__)r8   rÎ   r™  r]  r”   r:   r:   r;   Útest_exception`  s    "z LoggerAdapterTest.test_exceptionc          
   C   s€   ydd  W n& t k
r2 } z|}W d d }~X Y nX | jjd|d |  t| jjƒd¡ | jjd }|  |j|j||j	f¡ d S )NrW   r   zexc_info test)rm  )
r—  r5  rœ  rI   rJ   rþ  rÏ  rm  r  r6  )r8   r]  r™  r”   r:   r:   r;   Útest_exception_excinfoq  s    z(LoggerAdapterTest.test_exception_excinfoc             C   sh   d}| j  || j¡ |  t| jjƒd¡ | jjd }|  |jtj¡ |  |j	|¡ |  |j
| jf¡ d S )Nzcritical test! %rrW   r   )r5  r¥  rþ  rI   rJ   rÏ  r²   r   rb   rÎ   rï   )r8   rÎ   r”   r:   r:   r;   r  ~  s    zLoggerAdapterTest.test_criticalc             C   sD   | j jjj}d| j jj_|  t| j jjd|¡ |  | j  d¡¡ d S )Né!   rA   é    )r5  r½   r   rA   r‚   rÝ  rÝ   ÚisEnabledFor)r8   r÷  r:   r:   r;   Útest_is_enabled_forˆ  s
    z%LoggerAdapterTest.test_is_enabled_forc             C   sR   |   | j ¡ ¡ x| jjD ]}| j |¡ qW |  | j ¡ ¡ |  | j ¡ ¡ d S )N)r7   r5  r3   r½   r4   r>   rÝ   )r8   r‹   r:   r:   r;   Útest_has_handlers  s
    z#LoggerAdapterTest.test_has_handlersc             C   sL  G dd„ dt jƒ}d}|| jd d}||d d}d|_|  t|ƒt|ƒ¡ | t j|| j¡ |  t	| jj
ƒd¡ | jj
d }|  |jt j¡ |  |jd|› ¡ |  |j| jf¡ |j}|  |j|¡ |  | jj|¡ tƒ }z6||_|  |j|¡ |  |j|¡ |  | jj|¡ W d ||_X |  |j|¡ |  |j|¡ |  | jj|¡ d S )	Nc               @   s   e Zd ZdZdd„ ZdS )z.LoggerAdapterTest.test_nested.<locals>.AdapterÚAdapterc             S   s   | j › d|› |fS )Nú )r–   )r8   rÎ   r  r:   r:   r;   r  œ  s    z6LoggerAdapterTest.test_nested.<locals>.Adapter.processN)rZ   r[   r\   r–   r  r:   r:   r:   r;   r>  ™  s   r>  zAdapters can be nested, yo.)r½   rn  ZAdapterAdapterrW   r   zAdapter AdapterAdapter )r   rq   r½   r–   rI   r2  rr   rb   rþ  rJ   rÏ  r²   rÎ   rï   r   r*  rx  )r8   r>  rÎ   r5  Zadapter_adapterr”   Zorig_managerZtemp_managerr:   r:   r;   Útest_nested˜  s2    zLoggerAdapterTest.test_nested)rZ   r[   r\   r<   r7  r8  r  r<  r=  r@  r	  r:   r:   )r  r;   r3  N  s   
	r3  c                   sŒ   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )Ú
LoggerTestc                sb   t t| ƒ ¡  tƒ | _tjdd| _| j | j¡ |  	| jj
| j¡ |  	| jj¡ |  	tj¡ d S )NZblah)r9   )r  rA  r<   rØ  rþ  r   rr  r½   r6   r‚   r>   r=   rN  )r8   )r  r:   r;   r<   ¼  s    zLoggerTest.setUpc             C   s   |   t| jjtƒ ¡ d S )N)rÆ   rt  r½   r+   rx  )r8   r:   r:   r;   Útest_set_invalid_levelÅ  s    z!LoggerTest.test_set_invalid_levelc          
   C   s¸   d}d }ydd  W n6 t k
rJ } z|}| j || j¡ W d d }~X Y nX |  t| jjƒd¡ | jjd }|  |jtj	¡ |  |j
|¡ |  |j| jf¡ |  |j|j||jf¡ d S )Nztesting exception: %rrW   r   )r—  r½   rœ  rþ  rI   rJ   rÏ  r²   r   rd   rÎ   rï   rm  r  r6  )r8   rÎ   r™  r]  r”   r:   r:   r;   r7  È  s    "zLoggerTest.test_exceptionc          	   C   s2   t  tdd¡ |  t| jjdd¡ W d Q R X d S )Nr)  Tro   ztest message)r   Ú	swap_attrr   rÆ   rt  r½   rr   )r8   r:   r:   r;   Ú!test_log_invalid_level_with_raiseÙ  s    z,LoggerTest.test_log_invalid_level_with_raisec          	   C   s,   t  tdd¡ | j dd¡ W d Q R X d S )Nr)  Fro   ztest message)r   rC  r   r½   rr   )r8   r:   r:   r;   Útest_log_invalid_level_no_raiseÝ  s    z*LoggerTest.test_log_invalid_level_no_raisec                sP   g ‰ t  | tjd‡ fdd„¡ | jjdd |  tˆ ƒd¡ |  dˆ d ¡ d S )	NÚprint_stackc                s   ˆ   | ¡ ¡S )N)rt  rG   )r›   rŽ  )rà  r:   r;   rû  ä  rü  z=LoggerTest.test_find_caller_with_stack_info.<locals>.<lambda>T)r×  rW   zStack (most recent call last):
r   )r   r  r   Ú	tracebackr½   Z
findCallerrI   rJ   )r8   r:   )rà  r;   Ú test_find_caller_with_stack_infoá  s    z+LoggerTest.test_find_caller_with_stack_infoc             C   sŠ   d}d}d  } } } } } }}	t  |||||||||	¡	}
xFdt|
j ¡ ƒ D ]0}|di}| jt| jj|||||||||	d qRW d S )Nz	my recordé   )r  r¿  z
some value)rn  Úsinfo)	r   Z_logRecordFactoryrN   Ú__dict__ÚkeysrÆ   rj  r½   Ú
makeRecord)r8   r9   r'  rå   ÚlnorÎ   rï   rm  rº  rJ  Úrvrþ  rn  r:   r:   r;   Ú%test_make_record_with_extra_overwriteë  s    

z0LoggerTest.test_make_record_with_extra_overwritec             C   s\   d}d}d  } } } } } }}	ddi}
| j j||||||||
|	d	}|  d|j¡ d S )Nz	my recordrI  Z	valid_keyz
some value)rn  rJ  )r½   rM  r,  rK  )r8   r9   r'  rå   rN  rÎ   rï   rm  rº  rJ  rn  r½  r:   r:   r;   Ú(test_make_record_with_extra_no_overwriteø  s    z3LoggerTest.test_make_record_with_extra_no_overwritec             C   sB   |   | j ¡ ¡ x| jjD ]}| j |¡ qW |  | j ¡ ¡ d S )N)r7   r½   r3   r4   r>   rÝ   )r8   r‹   r:   r:   r;   r=    s    zLoggerTest.test_has_handlersc             C   s"   t  d¡}d|_|  | ¡ ¡ d S )Nz
blah.childF)r   r   rz  rÝ   r3   )r8   Zchild_loggerr:   r:   r;   Útest_has_handlers_no_propagate  s    
z)LoggerTest.test_has_handlers_no_propagatec             C   s>   | j jj}d| j j_|  t| j jd|¡ |  | j  d¡¡ d S )Né   rA   é   )r½   r   rA   r‚   rÝ  rÝ   r;  )r8   r÷  r:   r:   r;   r<    s    

zLoggerTest.test_is_enabled_forc             C   s    t  ¡ }|  |t j¡ |  |t  d ¡¡ |  |t  d¡¡ |  |t  d¡j¡ |  |t  d¡j¡ |  |t  d¡j¡ |  |t  d¡¡ |  |t  d¡j¡ d S )Nr   rî  zfoo.barú )r   r   r*  r°  ÚparentZassertIsNot)r8   r°  r:   r:   r;   Útest_root_logger_aliases  s    z#LoggerTest.test_root_logger_aliasesc             C   s$   |   ttjt¡ |   ttjd¡ d S )Ns   foo)rÆ   rt  r   r   Úany)r8   r:   r:   r;   Útest_invalid_names  s    zLoggerTest.test_invalid_namesc             C   sV   xPt tjd ƒD ]>}x8dD ]0}t |¡}t ||¡}t |¡}|  ||¡ qW qW d S )NrW   )r   r°  rî  zfoo.barzbaz.bar)ró   rÏ  ZHIGHEST_PROTOCOLr   r   rV  rÐ  r*  )r8   Úprotor9   r½   rU   Z	unpickledr:   r:   r;   Útest_pickling#  s    


zLoggerTest.test_picklingc             C   s6  | j }t d¡}t d¡}| tj¡ |  | ¡ tj¡ |  |ji ¡ |  | 	tj¡¡ |  
| 	tj¡¡ |  |jtjdtjdi¡ |  |ji ¡ |  | 	tj¡¡ |  |ji ¡ |  | 	tj¡¡ |  |jtjdi¡ | tj¡ |  | ¡ tj¡ |  |ji ¡ |  
| 	tj¡¡ | tj¡ |  | ¡ tj¡ |  |ji ¡ |  |ji ¡ |  |ji ¡ |  
| 	tj¡¡ |  | 	tj¡¡ |  
| 	tj¡¡ |  | 	tj¡¡ |  | 	tj¡¡ t ¡  |  | ¡ tj¡ |  |ji ¡ |  |ji ¡ |  |ji ¡ |  
| 	tj¡¡ |  
| 	tj¡¡ |  
| 	tj¡¡ d S )Nr|  zabc.defTF)r%   r   r   r+   rd   rI   r&   Ú_cacher7   r;  rÝ   r,   rb   r…   rA   )r8   r°  r#   r$   r:   r:   r;   Útest_caching+  sH    

zLoggerTest.test_caching)rZ   r[   r\   r<   rB  r7  rD  rE  rH  rP  rQ  r=  rR  r<  rW  rY  r[  r]  r	  r:   r:   )r  r;   rA  º  s   	
	rA  c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚBaseFileTestz1Base class for handler tests that write log filesc             C   s0   t  | ¡ t dd¡\}| _t |¡ g | _d S )Nz.logztest_logging-2-)r   r<   rÕ   rÖ   rå   r×   r=   Úrmfiles)r8   rä   r:   r:   r;   r<   g  s    

zBaseFileTest.setUpc             C   sB   x| j D ]}t |¡ qW tj | j¡r4t | j¡ t | ¡ d S )N)r_  r×   rØ   rÞ   rß   rå   r   rC   )r8   rå   r:   r:   r;   rC   m  s
    zBaseFileTest.tearDownc             C   s*   | j tj |¡d| d | j |¡ dS )z7Assert a log file is there and register it for deletionzLog file %r does not exist)rÎ   N)r7   r×   rÞ   rß   r_  rt  )r8   rO  r:   r:   r;   ÚassertLogFilet  s    zBaseFileTest.assertLogFileN)rZ   r[   r\   r]   r<   rC   r`  r:   r:   r:   r;   r^  d  s   r^  c               @   s   e Zd Zdd„ ZdS )ÚFileHandlerTestc             C   sx   t  | j¡ tj| jdd}|  |j¡ |  t j 	| j¡¡ | 
t i ¡¡ |  |j¡ |  t j 	| j¡¡ | ¡  d S )NT)rÌ   )r×   rØ   rå   r   rë   r/  r*   rÝ   rÞ   rß   rÜ   r™   r  r7   r=   )r8   Úfhr:   r:   r;   Ú
test_delay|  s    zFileHandlerTest.test_delayN)rZ   r[   r\   rc  r:   r:   r:   r;   ra  {  s   ra  c               @   sB   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zej	dd„ ƒZ
dS )ÚRotatingFileHandlerTestc          
   C   s   t  dt jdd|  ¡ d d d ¡S )Nr‚  rh  rW   )r   r  r,   rY   )r8   r:   r:   r;   Únext_rec‡  s    z RotatingFileHandlerTest.next_recc             C   s.   t jj| jdd}|  | d ¡¡ | ¡  d S )Nr   )ÚmaxBytes)r   r4   rì   rå   rÝ   ÚshouldRolloverr=   )r8   Úrhr:   r:   r;   Útest_should_not_rollover‹  s    z0RotatingFileHandlerTest.test_should_not_rolloverc             C   s2   t jj| jdd}|  | |  ¡ ¡¡ | ¡  d S )NrW   )rf  )r   r4   rì   rå   r7   rg  re  r=   )r8   rh  r:   r:   r;   Útest_should_rollover‘  s    z,RotatingFileHandlerTest.test_should_rolloverc             C   s4   t j | j¡}| |  ¡ ¡ |  | j¡ | ¡  d S )N)r   r4   rì   rå   rÈ   re  r`  r=   )r8   rh  r:   r:   r;   Útest_file_created–  s    z)RotatingFileHandlerTest.test_file_createdc             C   s¨   dd„ }t jj| jddd}||_| |  ¡ ¡ |  | j¡ | |  ¡ ¡ |  || jd ƒ¡ | |  ¡ ¡ |  || jd ƒ¡ |  t	j
 || jd ƒ¡¡ | ¡  d S )	Nc             S   s   | d S )Nz.testr:   )r9   r:   r:   r;   ÚnamerŸ  s    z>RotatingFileHandlerTest.test_rollover_filenames.<locals>.namerr‘   rW   )ÚbackupCountrf  z.1z.2z.3)r   r4   rì   rå   rl  rÈ   re  r`  rÝ   r×   rÞ   rß   r=   )r8   rl  rh  r:   r:   r;   Útest_rollover_filenamesž  s    z/RotatingFileHandlerTest.test_rollover_filenamesc          	   C   s¨  dd„ }dd„ }t jj| jddd}||_||_|  ¡ }| |¡ |  | j¡ |  ¡ }| |¡ || jd ƒ}|  |¡ t	j
}t|d	ƒ0}| ¡ }	t |	¡}
|  |
 d
¡|j| ¡ W d Q R X | |  ¡ ¡ || jd ƒ}|  |¡ t|d	ƒ0}| ¡ }	t |	¡}
|  |
 d
¡|j| ¡ W d Q R X | |  ¡ ¡ || jd ƒ}t|d	ƒ0}| ¡ }	t |	¡}
|  |
 d
¡|j| ¡ W d Q R X |  t	j || jd ƒ¡¡ | ¡  d S )Nc             S   s   | d S )Nz.gzr:   )r9   r:   r:   r;   rl  ¯  s    z3RotatingFileHandlerTest.test_rotator.<locals>.namerc          
   S   sX   t | dƒ:}| ¡ }t |d¡}t |dƒ}| |¡ W d Q R X W d Q R X t | ¡ d S )NÚrbr|  r#  )r  rP   ÚzlibÚcompressr"  r×   r©  )ÚsourceÚdestZsfr!  Ú
compressedZdfr:   r:   r;   Úrotator²  s    z5RotatingFileHandlerTest.test_rotator.<locals>.rotatorr‘   rW   )rm  rf  z.1ro  r·  z.2z.3)r   r4   rì   rå   ru  rl  re  rÈ   r`  r×   Úlinesepr  rP   rp  Z
decompressrI   rö  rÎ   rÝ   rÞ   rß   r=   )r8   rl  ru  rh  Zm1Zm2rå   Únewliner›   rt  r!  r:   r:   r;   Útest_rotator­  sB    



"

"
"z$RotatingFileHandlerTest.test_rotatorN)rZ   r[   r\   re  ri  rj  rk  rn  r   Zrequires_zlibrx  r:   r:   r:   r;   rd  †  s   rd  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚTimedRotatingFileHandlerTestc          
      s˜  t jj| jddd}t  d¡}| |¡ t  ddi¡}| |¡ |  | j¡ t	 
d¡ t  ddi¡}| |¡ | ¡  d	}tj ¡ }d
}xNt|ƒD ]B}|tj|d }	| j|	 d¡ ‰ tj ˆ ¡}|r’| j ˆ ¡ P q’W d| }
|s†tj | j¡\}‰ ‡ fdd„t |¡D ƒ}td| d¡ tjd td| tjd xJ|D ]B}td| ƒ tj ||¡}t|dƒ}t| ¡ ƒ W d Q R X q@W | j||
d d S )NÚSrW   )rm  z%(asctime)s %(message)srÎ   ztesting - initialgš™™™™™ñ?ztesting - after delayFi,  )Úsecondsz.%Y-%m-%d_%H-%M-%Sz,No rotated files found, went back %d secondsc                s   g | ]}|  ˆ ¡r|‘qS r:   )rR  )r~  r›   )rå   r:   r;   r€  ü  s    z>TimedRotatingFileHandlerTest.test_rollover.<locals>.<listcomp>zTest time: %sz%Y-%m-%d %H-%M-%S)rŽ  zThe only matching files are: %szContents of %s:rœ   )rÎ   )r   r4   rí   rå   r/   r2   r™   rÈ   r`  rô   rö   r=   rÊ  rØ  ró   Ú	timedeltaZstrftimer×   rÞ   rß   r_  rt  r’   Úlistdirrÿ   rÓ   r-  r“   r  rP   r7   )r8   rb  ZfmtZr1Zr2ÚfoundrØ  ÚGO_BACKÚsecsÚprevrÎ   ZdnÚfilesr›   rÞ   Ztfr:   )rå   r;   Útest_rolloverÜ  sB    






z*TimedRotatingFileHandlerTest.test_rolloverc             C   sR   | j }|ttjj| jddd |ttjj| jddd |ttjj| jddd d S )NÚXT)rÌ   ÚWZW7)rÆ   râ   r   r4   rí   rå   )r8   rÆ   r:   r:   r;   Útest_invalid  s    


z)TimedRotatingFileHandlerTest.test_invalidc             C   sx   d}t  ddd¡}tjj| jdddd|d}z<| |¡}|  ||d ¡ | |d ¡}|  ||d	 ¡ W d | ¡  X d S )
Nr   é   ÚMIDNIGHTrW   T)ÚwhenÚintervalrm  rË  ÚatTimeiÀ¨  iÐ¶  i@ú )	rÊ  rô   r   r4   rí   rå   ÚcomputeRolloverrI   r=   )r8   ÚcurrentTimer‹  rh  rR   r:   r:   r;   Ú"test_compute_rollover_daily_attime  s    
z?TimedRotatingFileHandlerTest.test_compute_rollover_daily_attimec       	   	   C   s6  t t ¡ ƒ}||d  }t ddd¡}t |¡j}xþtdƒD ]ò}tjj| j	d| ddd|d}zÄ||krvd| | }n|| }|d9 }|d	7 }||7 }| 
|¡}||krÄtd
tj ƒ tdtƒ  ƒ |  ||¡ ||krà|d7 }| 
|d ¡}||krtd
tj ƒ tdtƒ  ƒ |  ||¡ W d | ¡  X q<W d S )Ni€Q r‡  r   r  zW%drW   T)r‰  rŠ  rm  rË  r‹  iÀ¨  zfailed in timezone: %dzlocal vars: %si€:	 iÐ¶  )rë  rô   rÊ  rÌ  Ztm_wdayró   r   r4   rí   rå   rŒ  rÿ   ZtimezoneÚlocalsrI   r=   )	r8   r  Ztodayr‹  ZwdayZdayrh  rS   rR   r:   r:   r;   Ú#test_compute_rollover_weekly_attime  s8    

z@TimedRotatingFileHandlerTest.test_compute_rollover_weekly_attimeN)rZ   r[   r\   rƒ  r†  rŽ  r  r:   r:   r:   r;   ry  Ú  s   *	ry  c              K   s   t jf | Žt jdd S )NrW   )r{  )rÊ  r|  )rú  r:   r:   r;   r€  H  s    r€  )rz  rW   )ÚMé<   )ÚHi  )ÚDi€Q )rˆ  i€Q ZW0rò   é   )ZdaysZhoursc             C   sR  t jj| j|dddd}d}| |¡}||kr:|dkr:yÎ|jrNt |¡}n
t |¡}|d }|d }|d	 }	t jj	|d
 | d
 |	  }
||
 }t
d||jf tjd t
d| tjd t
d| tjd t
d|	 tjd t
d|
 tjd t
d| tjd W n0 tk
r8   t
dt ¡ d  tjd Y nX |  ||¡ | ¡  d S )NrW   r   T)r‰  rŠ  rm  rË  g        rˆ  ra  rò   r2  r’  z
t: %s (%s))rŽ  zcurrentHour: %szcurrentMinute: %szcurrentSecond: %szr: %sz
result: %sz exception in diagnostic code: %s)r   r4   rí   rå   rŒ  rË  rô   rÌ  Z	localtimeZ	_MIDNIGHTrÿ   rÓ   r-  rþ   rm  rI   r=   )r8   r‰  Úexprh  r  rR   rF  ZcurrentHourZcurrentMinuteZcurrentSecondrœ   r½  r:   r:   r;   Útest_compute_rolloverS  s6    



 r—  ztest_compute_rollover_%sz>win32evtlog/win32evtlogutil/pywintypes required for this test.c               @   s   e Zd Zdd„ ZdS )ÚNTEventLogHandlerTestc          
   C   s
  d}t  d |¡}t  |¡}ytj d¡}W n: tjk
rd } z|jdkrRt	 
d¡‚‚ W d d }~X Y nX t ddi¡}| |¡ | ¡  |  |t  |¡¡ t jt jB }d}d}	t  |||	¡}
x4|
D ],}|jdkrÐqÀt ||¡}|d	kræqÀd
}P qÀW d|	 }| j||d d S )NZApplicationZtest_loggingr2  z#Insufficient privileges to run testrÎ   zTest Log MessageFr0  zTest Log Message
Tz3Record not found in event log, went back %d records)rÎ   )Úwin32evtlogZOpenEventLogZGetNumberOfEventLogRecordsr   r4   ZNTEventLogHandlerÚ
pywintypesrs   Zwinerrorr  ZSkipTestr™   rÜ   r=   Z
assertLessZEVENTLOG_BACKWARDS_READZEVENTLOG_SEQUENTIAL_READZReadEventLogZ
SourceNameÚwin32evtlogutilZSafeFormatMessager7   )r8   ZlogtypeZelhZnum_recsrB   r]  rœ   Úflagsr~  r  ZeventsrÎ   r:   r:   r;   rs  y  s8    





z NTEventLogHandlerTest.test_basicN)rZ   r[   r\   rs  r:   r:   r:   r;   r˜  w  s   r˜  c               @   s   e Zd Zdd„ ZdS )ÚMiscTestCasec             C   s2   ddddddddd	d
dddh}t j| t|d d S )Nr  r  r  Zcurrentframer  ZStrFormatStyler_  ZFiltererZPlaceHolderrs  Z
RootLoggerr°  rû   )Ú	blacklist)r   Zcheck__all__r   )r8   rž  r:   r:   r;   Útest__all__œ  s    zMiscTestCase.test__all__N)rZ   r[   r\   rŸ  r:   r:   r:   r;   r  ›  s   r  ÚLC_ALLr   c           '   C   sv   t ttttttttt	t
tttttttttttttttttttttt t!t"t#t$t%t&g'} t't(j)dƒrh|  *t+¡ t,j-| Ž  d S )Nr“  ).r^   r†   r·   rÃ   ru  r‡  rÂ  rÜ  rù  r  r  r&  rl  r¶  rÒ  r(  r‚  r{  r‡  rã  rõ  r  r3  rA  rm  ra  rd  rÙ  r  rÖ  rá  rå  rç  r˜  ry  rÛ  rà  rä  r  r  r   r4   rt  rž  r   Zrun_unittest)Ztestsr:   r:   r;   Ú	test_main¨  s    
r¡  Ú__main__)N)›r]   r   Zlogging.handlersZlogging.configr  r”  rÊ  rê   rÏ  r(   r   rU  r×   rˆ  r÷   rD   r  r8  rÍ  rÓ   rÕ   Ztest.support.script_helperr   r   r  r   rˆ  rû   rô   r  r  rü  rG  Zhttp.serverr   r   r6  Zurllib.parser   r   Zsocketserverr	   r
   r   r   r™  r›  rš  ró  rp  ZTestCaser   r^   r†   ZSILENTr¶   ZTERSEZEFFUSIVErµ   r¿   Z	TALKATIVEr³   Z
CHATTERBOXZBORINGró   r¼   r¸   rˆ   r±   r´   r·   rÃ   rx  r  r-   r#  r&  r(  r7  r4  rL  rP  r_  rd  r  rj  rl  rm  ru  r/   r…  r‡  rÂ  rÚ  rœ  rÛ  rÜ  rà  rá  rä  ZIPV6_ENABLEDrå  rç  rù  r  r  r#  r$  r%  r&  rl  r{  r  r  r‚  r‡  r4   r©  Zunittest.mockr  rž  r|  r±  Ztzinfor°  rË  r¶  rÓ  rÎ  rÒ  rÖ  rÙ  rÛ  r!  rØ  rã  rõ  r  r  r3  rA  r^  ra  rd  ry  r€  r‰  r–  r—  rÝ  r˜  r  Zrun_with_localer¡  rZ   r:   r:   r:   r;   Ú<module>   sJ  m FY _,J5)/ N   JY@CM41(
        ,#i`
	Y'Wk5 Ol +Tn!#
