B
    u9aÀ’ ã               @   s  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" e/k
rr   d Z, Z-Z.Y nX yd dl0Z0W n e/k
r–   Y nX G dd„ dej1ƒZ2G d	d
„ d
e2ƒZ3G dd„ de2ƒZ4dZ5dZ6dZ7dZ8dZ9dZ:dZ;dZ<dZ=dZ>e?e>e5d ƒZ@e5de6de7de8de9de:de;de<de=d e>d!i
ZAG d"d#„ d#e jBƒZCG d$d%„ d%e jBƒZDG d&d'„ d'e2ƒZEG d(d)„ d)e2ƒZFG d*d+„ d+eGƒZHG d,d-„ d-e jIƒZJG d.d/„ d/eGƒZKG d0d1„ d1e2ƒZLG d2d3„ d3e#jMƒZNG d4d5„ d5eGƒZOG d6d7„ d7eOe!ƒZPG d8d9„ d9eOe*ƒZQG d:d;„ d;eOe(ƒZReSed<ƒr6G d=d>„ d>eQƒZTG d?d@„ d@eRƒZUG dAdB„ dBe2ƒZVG dCdD„ dDe2ƒZWG dEdF„ dFe jXƒZYG dGdH„ dHe2ƒZZG dIdJ„ dJe2ƒZ[dKdL„ Z\e ]eSed<ƒdM¡G dNdO„ dOe[ƒƒZ^G dPdQ„ dQe2ƒZ_e ]eSed<ƒdM¡G dRdS„ dSe_ƒƒZ`G dTdU„ dUe2ƒZae ]eSed<ƒdM¡G dVdW„ dWeaƒƒZbe ]ejcdX¡G dYdZ„ dZeaƒƒZdG d[d\„ d\e2ƒZeG d]d^„ d^e2ƒZfG d_d`„ d`e2ƒZgG dadb„ dbe2ƒZhdµdcdd„Zidedf„ ZjG dgdh„ dhe jIƒZkG didj„ dje2ƒZlG dkdl„ dle2ƒZmG dmdn„ dne2ƒZnG dodp„ dpe joƒZpG dqdr„ dre2ƒZqG dsdt„ dte2ƒZreSe jsduƒr,d dltZtd dvlumvZv G dwdx„ dxe2ƒZwe xd ¡ZyG dydz„ dzejzƒZ{e{ƒ Z|G d{d|„ d|ej1ƒZ}G d}d~„ d~e j~ƒZG dd€„ d€ej1ƒZ€G dd‚„ d‚e2ƒZG dƒd„„ d„e2ƒZ‚G d…d†„ d†ƒZƒG d‡dˆ„ dˆe j„ƒZ…G d‰dŠ„ dŠe2ƒZ†G d‹dŒ„ dŒe2ƒZ‡G ddŽ„ dŽe2ƒZˆG dd„ dej1ƒZ‰G d‘d’„ d’ej1ƒZŠG d“d”„ d”e2ƒZ‹G d•d–„ d–e2ƒZŒG d—d˜„ d˜eŒƒZG d™dš„ dšeŒƒZŽG d›dœ„ dœeŒƒZddž„ ZxHdŸd d¡d¢d£d¤ed¥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­e2ƒƒZ•G d®d¯„ d¯ej1ƒZ–e —d°d±¡d²d³„ ƒZ˜e™d´kre˜ƒ  dS )¶é    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d„ Zdd„ Zdd	d
„Zdd„ Z	dS )ÚBaseTestz&%(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 )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 )Nr   ) 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 )Nz*Log line does not match expected pattern:
z'Remaining output at end of log stream:
)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 )Né   z%d)Úmessage_num)r8   r:   r:   r;   Únext_message«   s    zBaseTest.next_message)NN)
Ú__name__Ú
__module__Ú__qualname__r0   rF   rX   r<   rC   rV   rY   r:   r:   r:   r;   r   E   s   *"
r   c               @   sL   e 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 )ÚBuiltinLevelsTestc             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_   ra   Ú3)r_   rc   Ú4)r_   ÚWARNINGÚ5)r_   ÚINFOÚ6)r`   ra   Ú7)r`   rc   Ú8)r`   rg   Ú9)r`   ri   Ú10)r`   r,   Ú11)rY   r   r   r+   rc   ÚLoggerAdapterri   r,   Úlogra   ÚerrorÚwarningÚinfoÚdebugrV   )r8   Úmr^   r_   r`   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.ERRra   rb   )zINF.ERRrc   rd   )rY   r   r   r+   ri   rc   rq   ra   rr   rs   rt   ru   rV   )r8   rv   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.UNDEFra   rb   )z	INF.UNDEFrc   rd   )z	INF.UNDEFrg   re   )z	INF.UNDEFri   rf   )zINF.ERR.UNDEFra   rh   )zINF.ERR.UNDEFrc   rj   )rY   r   r   r+   ri   rc   rq   ra   rr   rs   rt   ru   rV   )r8   rv   r_   rx   Z	INF_UNDEFZINF_ERR_UNDEFrz   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.UNDEFra   rb   )zINF.BADPARENT.UNDEFri   rd   )zINF.BADPARENTra   re   )zINF.BADPARENTri   rf   )
rY   r   r   r+   ri   rq   ÚFATALrt   ru   rV   )r8   rv   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 )Nri   )rI   r   ÚgetLevelNameri   )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 )Nr   ri   )r   ÚaddLevelNameri   Ú
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 )Nr   ri   ÚNOTSET)r   r€   ri   r   rI   r~   r„   )r8   r:   r:   r;   r‚   G  s
    N)
rZ   r[   r\   rw   ry   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d„ ZdS )ÚBasicFilterTestc          	   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.eggsri   rd   )zspam.eggs.fishri   re   )
r   ÚFilterr%   r4   Ú	addFilterr   rt   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.eggsri   rd   )zspam.eggs.fishri   re   )	r%   r4   rˆ   r   r   rt   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…   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d„ ZdS )ÚGarrulousFilterc             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°   ³  s   r°   c               @   s   e Zd Zdd„ ZdS )ÚVerySpecificFilterc             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³   º  s   r³   c               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚCustomLevelsAndFiltersTestz^[\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_RANGErq   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¬   rh   )r«   rj   )rª   rk   )r©   rl   )r¨   rm   )r§   rn   )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«   rj   )rª   rk   )r©   rl   )r¨   rm   )r§   rn   )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¯   rb   )r®   rd   )r­   rf   )r¬   rh   )r«   rj   )rª   rk   )r©   rl   )r¨   rm   )r§   rn   )r¯   ro   )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\   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 )NÚwÚarB   )rÉ   rÊ   )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 )Nc                   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/z&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   rt   Ú_exitr  r’   ró   Z	monotonicru   Ú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 )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-  r0  r2  r:   r:   r:   r;   r'    s   r'  c               @   s6   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zdd
d„Zd	S )ÚTestSMTPServerc             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 )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 )N)rù   rî   T)rú   rû   Úserve_foreverr<  r;  Ú	setDaemonrü   )r8   Útr:   r:   r;   rü   Z  s    
zTestSMTPServer.startc             C   s   t j|| jd d S )N)r4  )ÚasyncoreZloopÚ_map)r8   r<  r:   r:   r;   rC  c  s    zTestSMTPServer.serve_foreverNc             C   s0   |   ¡  t | j|¡ d | _tj| jdd d S )NT)r4  Z
ignore_all)r=   r   Újoin_threadr;  rF  Z	close_allrG  )r8   Útimeoutr:   r:   r;   Ústopm  s    zTestSMTPServer.stop)N)rZ   r[   r\   r  rB  rü   rC  rJ  r:   r:   r:   r;   r3  1  s
   	
r3  c                   s6   e Zd Zdd„ Zdd„ Z‡ fdd„Zd
dd	„Z‡  ZS )ÚControlMixinc             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 )N)rù   rî   T)rú   rû   rC  r<  r;  rD  rü   )r8   rE  r:   r:   r;   rü   ‘  s    
zControlMixin.startc                s   | j  ¡  tt| ƒ |¡ d S )N)rL  r  r  rK  rC  )r8   r<  )r  r:   r;   rC  š  s    
zControlMixin.serve_foreverNc             C   s<   |   ¡  | jd k	r&t | j|¡ d | _|  ¡  | j ¡  d S )N)Úshutdownr;  r   rH  Úserver_closerL  r?   )r8   rI  r:   r:   r;   rJ  ¢  s    
zControlMixin.stop)N)rZ   r[   r\   r  rü   rC  rJ  r  r:   r:   )r  r;   rK  {  s   	rK  c               @   s   e Zd Zddd„Zdd„ ZdS )	ÚTestHTTPServerç      à?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;   rR  Ã  s    zMTestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.process_requestc                s   ˆrt ˆ | ƒj|f|žŽ  d S )N)r  Úlog_message)r8   Úformatrî   )ÚDelegatingHTTPRequestHandlerr  rq   r:   r;   rW  Æ  s    zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.log_message)N)rZ   r[   r\   rU  rR  rW  r  r:   )rY  rq   )r  r;   rY  ½  s   
rY  )r   r   r  rK  Ússlctx)r8   r=  rŠ   r<  rq   rZ  r:   )rY  rq   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
)r7  ZacceptrZ  Zwrap_socketrà   rÒ   r,  r!  )r8   Úsockr=  Úer:   r:   r;   Úget_requestÎ  s    zTestHTTPServer.get_request)rP  FN)rZ   r[   r\   r  r]  r:   r:   r:   r;   rO  °  s    
rO  c                   s*   e Zd ZdZddd„Z‡ fdd„Z‡  ZS )ÚTestTCPServerTç      à?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)rV  r:  )r8   r:   r:   r;   rÛ   î  s    zBTestTCPServer.__init__.<locals>.DelegatingTCPRequestHandler.handleN)rZ   r[   r\   rÛ   r:   r:   r:   r;   ÚDelegatingTCPRequestHandlerì  s   r`  )r   r   r  rK  )r8   r=  rŠ   r<  Úbind_and_activater`  r:   r:   r;   r  ê  s    
zTestTCPServer.__init__c                s"   t t| ƒ ¡  | j ¡ d | _d S )NrW   )r  r^  Úserver_bindr7  r8  r9  )r8   )r  r:   r;   rb  ô  s    zTestTCPServer.server_bind)r_  T)rZ   r[   r\   Zallow_reuse_addressr  rb  r  r:   r:   )r  r;   r^  Ù  s    
	r^  c                   s2   e Zd Zd	dd„Z‡ fdd„Z‡ fdd„Z‡  ZS )
ÚTestUDPServerç      à?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)rV  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à   rV  Ú_closed)r8   r   )ÚDelegatingUDPRequestHandlerr  r:   r;   re    s    
zBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.finish)rZ   r[   r\   rÛ   re  r  r:   )rg  )r  r;   rg    s   rg  F)r
   r	   r  rK  rf  )r8   r=  rŠ   r<  ra  r:   )rg  r;   r  	  s    zTestUDPServer.__init__c                s"   t t| ƒ ¡  | j ¡ d | _d S )NrW   )r  rc  rb  r7  r8  r9  )r8   )r  r:   r;   rb    s    zTestUDPServer.server_bindc                s   t t| ƒ ¡  d| _d S )NT)r  rc  rN  rf  )r8   )r  r:   r;   rN  #  s    zTestUDPServer.server_close)rd  T)rZ   r[   r\   r  rb  rN  r  r:   r:   )r  r;   rc  ø  s    
rc  ÚAF_UNIXc               @   s   e Zd ZejZdS )ÚTestUnixStreamServerN)rZ   r[   r\   r7  rh  Úaddress_familyr:   r:   r:   r;   ri  (  s   ri  c               @   s   e Zd ZejZdS )ÚTestUnixDatagramServerN)rZ   r[   r\   r7  rh  rj  r:   r:   r:   r;   rk  +  s   rk  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)rI  rÍ   u	   Hello âœ“rW   z
Subject: Log
u   

Hello âœ“)r3  r   ZHOSTrB  rü   r9  r   r4   ZSMTPHandlerÚTIMEOUTrI   ZtoaddrsÚmessagesr˜   rú   r  ÚhandledrÛ   r  rJ  r7   Zis_setrJ   r+  Úendswithr=   )
r8   r>  rV  r=  rB   r›   r?  r@  rA  r   r:   r:   r;   Ú
test_basic4  s,    


zSMTPHandlerTest.test_basicc             G   s   | j  |¡ | j ¡  d S )N)ro  Úappendrp  r  )r8   rî   r:   r:   r;   rB  L  s    zSMTPHandlerTest.process_messageN)rZ   r[   r\   rn  rr  rB  r:   r:   r:   r;   rl  0  s   rl  c               @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚMemoryHandlerTestz^[\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   ÚMemoryHandlerrg   r.   Úmem_hdlrr   Ú
mem_loggerÚ	propagater6   )r8   r:   r:   r;   r<   W  s    

zMemoryHandlerTest.setUpc             C   s   | j  ¡  t | ¡ d S )N)rw  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,   rb   )ri   rd   )rg   re   )rñ   é   é	   c             S   s   g | ]}d t |ƒf‘qS )r,   )Ústr)Ú.0Úir:   r:   r;   ú
<listcomp>y  s    z0MemoryHandlerTest.test_flush.<locals>.<listcomp>ru  )rx  ru   rY   rV   rt   rs   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 )N)r,   rb   )ri   rd   ru  F)rx  ru   rY   rV   rt   r>   rw  r=   r   r4   rv  rg   r.   r6   )r8   r€  r:   r:   r;   Útest_flush_on_close  s(    






z%MemoryHandlerTest.test_flush_on_closeN)rZ   r[   r\   rF   r<   rC   r‚  rƒ  r:   r:   r:   r;   rt  P  s
   rt  c               @   s   e Zd Zdd„ ZdS )ÚExceptionFormatterc             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„  ž  s   r„  c               @   sÎ   e 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 ),ÚConfigFileTestz^(\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)rc   rd   )r*   )
r   Úcaptured_stdoutrŽ  Úconfig0r   r   rt   rY   rr   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)rc   rd   )r*   )r   r  r(   r)   r‡  rˆ  r  ÚconfigparserZConfigParserZ	read_filer   r‰  rŠ  r   rt   rY   rr   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)ri   rb   )rc   rd   )r*   )	r   r  rŽ  r   r   rt   rY   rr   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)ri   rb   )rc   rd   )ra   re   )r*   zcompiler.lexer)ri   rf   )rc   rh   )ri   rj   )rc   rk   )r   r  rŽ  Úconfig1ar   r   rt   rY   rr   Ú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Úconfig8rX  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 )Nat  
            [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)rX  ÚdatefmtÚclass)Úversionr±  Ú
formatters)Údefaults)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¬  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†  ¤  s6     *&+	r†  c               @   s<   e Zd ZeZdZdd„ Zdd„ Zdd„ Zdd	„ Z	d
d„ Z
dS )ÚSocketHandlerTest)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 )Ng{®Gáz„?rÑ   r   r   )r   r<   rV  Ú	sock_hdlrÚserver_exceptionÚserver_classÚaddressÚhandle_socketrü   rà   rL  r  r   r4   ZSocketHandlerÚ
isinstanceÚserver_addressrN   r9  Ú
log_outputr%   r>   r6   rú   Z	Semaphorerp  )r8   rV  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 )Ng       @)rÂ  r%   r>   r=   rV  rJ  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Í   rp  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   rr   rp  r  ru   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
retryStartrV  rJ  r  r%   r›  rr   ró   r  Z	retryTimerõ   )r8   Únowr:   r:   r;   Útest_noserver±  s    zSocketHandlerTest.test_noserverN)rZ   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eedƒreZdd„ Zdd„ ZdS )ÚUnixSocketHandlerTestrh  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  r7  ri  rÄ  r<   rC   r:   r:   r:   r;   rÚ  Ì  s   
rÚ  c               @   s4   e Zd ZeZdZdd„ Zdd„ Zdd„ Zdd	„ Z	d
S )ÚDatagramHandlerTest)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 )Ng{®Gáz„?rÑ   r   r   )r   r<   rV  rÂ  rÃ  rÄ  rÅ  Úhandle_datagramrü   rà   rL  r  r   r4   ZDatagramHandlerrÇ  rÈ  rN   r9  rÉ  r%   r>   r6   rú   r  rp  )r8   rV  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 )Ng       @)rV  rJ  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Í   rp  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   rr   rp  r  r?   rI   rÉ  )r8   r¼   r:   r:   r;   rÖ    s    





zDatagramHandlerTest.test_outputN)
rZ   r[   r\   rc  rÄ  rÅ  r<   rC   rÜ  rÖ  r:   r:   r:   r;   rÛ  Ý  s   rÛ  c               @   s*   e Zd ZeedƒreZdd„ Zdd„ ZdS )ÚUnixDatagramHandlerTestrh  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  r7  rk  rÄ  r<   rC   r:   r:   r:   r;   rß    s   
rß  c               @   s4   e Zd ZeZdZdd„ Zdd„ Zdd„ Zdd	„ Z	d
S )ÚSysLogHandlerTest)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 )Ng{®Gáz„?r   r   )r   r<   rV  Úsl_hdlrrÃ  rÄ  rÅ  rÜ  rü   rà   rL  r  r   r4   rß   rÇ  rÈ  rN   r9  rÉ  r%   r>   r6   rú   r  rp  )r8   rV  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 )Ng       @)rV  rJ  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É  rp  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   rr   rp  r  rI   rÉ  r?   rá  Z
append_nulÚident)r8   r¼   r:   r:   r;   rÖ  ^  s     








zSysLogHandlerTest.test_outputN)
rZ   r[   r\   rc  rÄ  rÅ  r<   rC   rÜ  rÖ  r:   r:   r:   r;   rà  .  s   rà  c               @   s*   e Zd ZeedƒreZdd„ Zdd„ ZdS )ÚUnixSysLogHandlerTestrh  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  r7  rk  rÄ  r<   rC   r:   r:   r:   r;   rã  q  s   
rã  z$IPv6 support required for this test.c                   s0   e Zd ZeZdZ‡ fdd„Z‡ fdd„Z‡  ZS )ÚIPv6SysLogHandlerTest)z::1r   c                s   t j| j_tt| ƒ ¡  d S )N)r7  ZAF_INET6rÄ  rj  r  rä  r<   )r8   )r  r:   r;   r<   ‹  s    
zIPv6SysLogHandlerTest.setUpc                s   t j| j_tt| ƒ ¡  d S )N)r7  ÚAF_INETrÄ  rj  r  rä  rC   )r8   )r  r:   r;   rC     s    
zIPv6SysLogHandlerTest.tearDown)	rZ   r[   r\   rc  rÄ  rÅ  r<   rC   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 )ÚHTTPHandlerTestc             C   s   t  | ¡ t ¡ | _d S )N)r   r<   rú   r  rp  )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_headersrp  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„?)rZ  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_contextrO  rì  rV  rü   rL  r  Zserver_portrâ   Zh_hdlrré  r6   rå   rp  r?   rr   rI   rè  r   Zqueryrë  ÚdecoderJ  r=   )r8   r¼   r%   rï  r=  rñ  rZ  ÚhereZlocalhost_certrð  rV  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æ  “  s   ræ  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú
MemoryTestc             C   s   t  | ¡ i | _d S )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 )N)Úidr1  Ú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 )Nz;%d objects should have survived but have been destroyed: %sz, )ÚgcZcollectrù  r¸   rs  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,   rd   )rí  r,   re   )r%   r+   r   ri   r   rþ  r,   ru   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ø  à  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   rs   r>   r  rI   rP   ÚrstriprÝ   Úisfiler¨  )r8   rq   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   rs   r>   r=   rG   rI   )r8   rq   Ú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/   )rX  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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d/œZd0d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	d1d2d3œd4œiddgdœdœZdd5d6d7d8œiddd5d9œd:d;d5d<dd=œd>œd?dd@gdAdBœidCœZdDdE„ Z dFdG„ Z!efdHdI„Z"dJdK„ Z#dLdM„ Z$dNdO„ Z%dPdQ„ Z&dRdS„ Z'dTdU„ Z(dVdW„ Z)dXdY„ Z*dZd[„ Z+d\d]„ Z,d^d_„ Z-d`da„ Z.dbdc„ Z/ddde„ Z0dfdg„ Z1dhdi„ Z2djdk„ Z3dldm„ Z4d{dodp„Z5dqdr„ Z6dsdt„ Z7dudv„ Z8dwdx„ Z9dydz„ Z:dnS )|ÚConfigDictTestz^(\w+) \+\+ (\w+)$rW   Úform1rX  z%(levelname)s ++ %(message)sÚhand1zlogging.StreamHandlerr„   zext://sys.stdout)r¸  Ú	formatterr&  r*   rg   )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()rX  z.formatFunc)r&  Zform2Zform3z())r'  Zhand2z.CustomHandlerzinvalid parameter name)r¸  r(  r&  r*   rm   zcompiler.lexerF)Úcompilerzcompiler.lexer)r¹  r±  rº  r4   r)  r¯  Tri   )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ú$)rX  Ústyle)r¸  r&  r(  zlogging.handlers.MemoryHandleré   Ú
fileGlobal)r¸  Zcapacityr(  rù   r&  )r2  ÚbufferGlobalÚmymoduler3  Útrue)r&  r4   ry  )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)rc   rd   )r*   )
r   r  rŽ  r  r   r   rt   rY   rr   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)ri   rb   )rc   rd   )r*   )	r   r  rŽ  r   r   rt   rY   rr   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)ri   rb   )rc   rd   )r*   zcompiler.lexer)ri   re   )rc   rf   )r   r  rŽ  rÀ  r   r   rt   rY   rr   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)ri   rb   )rc   rd   )r*   zcompiler.lexer)ri   re   )rc   rf   )ri   rh   )rc   rj   )r   r  rŽ  rÀ  r   r   rt   rY   rr   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)ri   rb   )rc   rd   )ra   re   )r*   zcompiler.lexer)ri   rf   )rc   rh   )ri   rj   )rc   rk   )r   r  rŽ  r£  r   r   rt   rY   rr   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*   )ri   re   )r   r  rŽ  Úconfig9r   r   rt   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)rg   rb   )rc   rf   )r*   )
r   r  rŽ  Úconfig10r   r   rs   rY   rr   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.  rs   r7   rG   rq  )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ü   rL  r  r9  r?   r7  rå  ZSOCK_STREAMZ
settimeoutZconnectrÌ  rÝ  rJ   Úsendr=   ZstopListeningr   rH  )r8   ÚtextZverifyrE  r9  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)rg   rb   )rc   rf   )r*   )r   r  rS  ÚjsonÚdumpsrD  r   r   rs   rY   rr   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)ri   rb   )rc   rd   )r*   )r   r  rS  r‡  rˆ  r†  rÀ  r   r   rt   rY   rr   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:   )rX  r:   r:   r;   Úverify_reverseD  s    z9ConfigDictTest.test_listen_verify.<locals>.verify_reversezcompiler.parser)r*   )ri   rb   )rc   rd   z^[\w.]+ -> (\w+): (\d+)$)rQ   )ri   re   )rc   rf   rÌ   )ri   rh   )rc   rj   )r   r   r‡  rˆ  r†  rÀ  r   r  rS  rt   rY   rr   rV   )r8   rY  rZ  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 )Nr4  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\  r`  )r÷  rš   )Úg)rB   r~  Újr¹   Úlrv   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¬  rF   r  rÀ  r£  r–  r6  r8  r˜  rš  r„  r"  r#  r:  rŸ  r¡  r¥  r®  r>  r@  rA  rB  rD  rF  rH  rJ  rL  r\  rŽ  r’  r•  r—  r7  r9  r™  rž  r;  r   r<  r§  r=  r?  rC  rE  rG  rI  rK  rM  rO  rS  rV  rW  r[  r_  rj  r:   r:   r:   r;   r%  v  sh  
















!+	
>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)rs  )r8   r&  rÍ   rî   Úexc_infoÚextra)Úloggedr:   r;   Ú_logŸ  s    z;ManagerTest.test_manager_loggerclass.<locals>.MyLogger._log)NN)rZ   r[   r\   ro  r:   )rn  r:   r;   ÚMyLoggerž  s   rp  r  zshould appear in loggedzshould not appear in logged)
r   ÚLoggerÚManagerrÅ   Ú	TypeErrorÚsetLoggerClassrê  r   rs   rI   )r8   rp  Úmanr¼   r:   )rn  r;   Útest_manager_loggerclass›  s    




z$ManagerTest.test_manager_loggerclassc             C   s,   t  d ¡}tƒ }| |¡ |  |j|¡ d S )N)r   rr  ÚobjectÚsetLogRecordFactoryrI   ZlogRecordFactory)r8   ru  rS   r:   r:   r;   Útest_set_log_record_factory«  s    

z'ManagerTest.test_set_log_record_factoryN)rZ   r[   r\   rv  ry  r:   r:   r:   r;   rk  š  s   rk  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;   rz  ±  s   rz  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í   rs  )r8   r“   rE  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   rx  r„  )r8   r:   r:   r;   rC   Ù  s    
zLogRecordFactoryTest.tearDownc             C   s@   |   t| jj|  ¡ ¡ t t¡ | j |  ¡ ¡ |  	dg¡ d S )N)r¯  rc   rd   )
rÅ   rs  r%   rs   rY   r   rx  r€  rr   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_loggerry  r+   rg   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‹  ru   rY   rÅ   r‡  ÚEmptyÚ
get_nowaitrt   rs   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~   rg   rX  r9   r/   r0   rŠ  r2   r‹  rs   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 )
Nrb   )r±   r  rd   re   T)Zrespect_handler_levelrf   rh   rj   )r   ZTestHandlerZMatcherr   r4   r’  r‡  rü   r‹  rs   rY   rr   r¤  rJ  r7   Úmatchesrg   rc   ra   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   )rl  Z	Traceback)r   r4   r’  r‡  r.   rü   ÚZeroDivisionErrorr‹  r›  rY   rJ  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 )Nrr   zque -> ERROR: error)rŠ  r2   r1   r‹  r6   r.   r   r4   r’  r‡  rü   rr   rJ  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               @   sh   e 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 )ÚQueueListenerTesté   c             C   s”   t  d| ¡}| t j¡ t j | ¡}| |¡ t j | ¡}| ¡  | 	d¡ | 	d¡ | 	d¡ | 	d¡ | 	d¡ | 
¡  | |¡ | ¡  d S )Nztest_logger_with_id_%sÚoneÚtwoZthreeZfourZfive)r   r   r+   r,   r4   r‰  r6   r’  rü   rt   rJ  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_%sr1  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_%sr1  z&correct number of handled log messages)r   Úimport_modulerò   r£  Úmultiprocessingrˆ  r¢  rú  r=   rH  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 )Nz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}  rv   r:   r:   r;   r  §  s   zJQueueListenerTest.test_no_messages_in_queue_after_stop.<locals>.<listcomp>)r   r§  rò   r£  r¨  rˆ  r¢  rú  Úlistrª  r=   rH  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ü   rJ  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£  Ústaticmethodr¢  rœ  rw  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Úlinenorl  Ú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   rX  rÅ   ri  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}%$Ú{)r0  z$%Message with 2 placeholders%$z{random}z	{asctime}z{asctime!s:15}z{asctime:15}r¾  )
r½  r   r/   rI   rX  rÅ   ri  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$messager/  )r0  zMessage with 2 placeholdersz$$%${message}%$$z$%Message with 2 placeholders%$z	${random}z
${asctime}z	${asctimez$asctimer¾  )
r½  r   r/   rI   rX  rÅ   ri  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ñ   é   é   r`  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
formatTimerX  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   rX  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   rX  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_textrQ  rq  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*  ru   rI   rG   rs   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{} - {})rs  rX  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 )N)rÎ  rs  )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‡ 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 )!ÚShutdownTestc                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:   )rr   r:   r;   rá  •  s    z'ShutdownTest.raise_error.<locals>.innerr:   )r8   rr   rá  r:   )rr   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ß  r4  r   rû  rü  rM  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ü  rM  r«  rI   )r8   rå   rr   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â  ‰  s    	râ  c               @   sl   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d„ Z
dd„ Zejdd„ ƒZdd„ ZdS )ÚModuleLevelMiscTestc             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   ra   )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)rs  )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 )Nrq   )rÿ  r   rc   )r8   r:   r:   r;   Útest_log
  s    zModuleLevelMiscTest.test_logc             C   s   |   d¡ d S )Nru   )rÿ  )r8   r:   r:   r;   Ú
test_debug  s    zModuleLevelMiscTest.test_debugc             C   s   |   d¡ d S )Nrt   )rÿ  )r8   r:   r:   r;   Ú	test_info  s    zModuleLevelMiscTest.test_infoc             C   s   |   d¡ d S )Nrs   )rÿ  )r8   r:   r:   r;   Útest_warning  s    z ModuleLevelMiscTest.test_warningc             C   s   |   d¡ d S )Nrr   )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;   rp    s   rp  )rÅ   rs  r   rt  rw  rq  rI   ZgetLoggerClass)r8   rp  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   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   rQ  rq  )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   rs   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‡ 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 )/ÚBasicConfigTestc                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*   r0  zLog an errorr   zERROR:root:Log an error)r   r  r   rø  rÒ   rœ  rr   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 )Nr/  )r*   r0  zLog an errorr   zERROR:root:Log an error)r   r  r   rø  rÒ   rœ  rr   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)rN  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)rN  Ú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í  )rX  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 )Nr/  )r0  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)rN  r*   )rN  r4   )r*   r4   )Zloglevelrè   )rN  r#  )rÅ   r   r-   rÒ   r,  rá   rø  ri   )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   rs  )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&  r1  rþ  r:   )rß  r0  r8   r;   rÿ  $  s    
zBasicConfigTest._test_logc             C   s   |   dtj¡ d S )Nrq   )rÿ  r   rg   )r8   r:   r:   r;   r   ;  s    zBasicConfigTest.test_logc             C   s   |   d¡ d S )Nru   )rÿ  )r8   r:   r:   r;   r  >  s    zBasicConfigTest.test_debugc             C   s   |   d¡ d S )Nrt   )rÿ  )r8   r:   r:   r;   r  A  s    zBasicConfigTest.test_infoc             C   s   |   d¡ d S )Nrs   )rÿ  )r8   r:   r:   r;   r  D  s    zBasicConfigTest.test_warningc             C   s   |   d¡ d S )Nrr   )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<   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¼   rm  )r  r2  r<   r   r   r×  rý  r¯  r¼   r6   r   r>   r=   rM  rp   Úadapter)r8   rª  )r  )r3  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–  r4  r›  rý  rI   rJ   rÎ  r±   r   rc   rÍ   rî   rl  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)rl  )
r–  r4  r›  rI   rJ   rý  rÎ  rl  r  r5  )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   )r4  r¤  rý  rI   rJ   rÎ  r±   r   ra   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   é    )r4  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   r4  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¼   rm  ZAdapterAdapterrW   r   zAdapter AdapterAdapter )r   rp   r¼   r•   rI   r1  rq   ra   rý  rJ   rÎ  r±   rÍ   rî   r   r)  rw  )r8   r=  rÍ   r4  Zadapter_adapterr“   Zorig_managerZtemp_managerr:   r:   r;   Útest_nested˜  s2    zLoggerAdapterTest.test_nested)rZ   r[   r\   r<   r6  r7  r  r;  r<  r?  r  r:   r:   )r  r;   r2  N  s   
	r2  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  r@  r<   r×  rý  r   rq  r¼   r6   r   r>   r=   rM  )r8   )r  r:   r;   r<   ¼  s    zLoggerTest.setUpc             C   s   |   t| jjtƒ ¡ d S )N)rÅ   rs  r¼   r+   rw  )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   rc   rÍ   rî   rl  r  r5  )r8   rÍ   r˜  r\  r“   r:   r:   r;   r6  È  s    "zLoggerTest.test_exceptionc          	   C   s2   t  tdd¡ |  t| jjdd¡ W d Q R X d S )Nr(  Trn   ztest message)r   Ú	swap_attrr   rÅ   rs  r¼   rq   )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(  Frn   ztest message)r   rB  r   r¼   rq   )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)rs  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)rm  Úsinfo)	r   Z_logRecordFactoryrN   Ú__dict__ÚkeysrÅ   ri  r¼   Ú
makeRecord)r8   r9   r&  rä   ÚlnorÍ   rî   rl  r¹  rI  Úrvrý  rm  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 recordrH  Z	valid_keyz
some value)rm  rI  )r¼   rL  r+  rJ  )r8   r9   r&  rä   rM  rÍ   rî   rl  r¹  rI  rm  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   ry  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Å   rs  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   rU  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+   rc   rI   r&   Ú_cacher7   r:  rÜ   r,   ra   r„   rA   )r8   r¯  r#   r$   r:   r:   r;   Útest_caching+  sH    

zLoggerTest.test_caching)rZ   r[   r\   r<   rA  r6  rC  rD  rG  rO  rP  r<  rQ  r;  rV  rX  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 )ÚBaseFileTestc             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 )NzLog file %r does not exist)rÍ   )r7   rÖ   rÝ   rÞ   r^  rs  )r8   rN  r:   r:   r;   ÚassertLogFilet  s    zBaseFileTest.assertLogFileN)rZ   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\   rb  r:   r:   r:   r;   r`  {  s   r`  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  rg  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   )re  )r   r4   rë   rä   r7   rf  rd  r=   )r8   rg  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Ç   rd  r_  r=   )r8   rg  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   )ÚbackupCountre  z.1z.2z.3)r   r4   rë   rä   rk  rÇ   rd  r_  rÜ   rÖ   rÝ   rÞ   r=   )r8   rk  rg  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;   rk  ¯  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   )rl  re  z.1rn  r¶  z.2z.3)r   r4   rë   rä   rt  rk  rd  rÇ   r_  rÖ   Úlinesepr  rP   ro  Z
decompressrI   rõ  rÍ   rÜ   rÝ   rÞ   r=   )r8   rk  rt  rg  Zm1Zm2rä   Únewlinerš   rs  r   r:   r:   r;   Útest_rotator­  sB    



"

"
"z$RotatingFileHandlerTest.test_rotatorN)rZ   r[   r\   rd  rh  ri  rj  rm  r   Zrequires_zlibrw  r:   r:   r:   r;   rc  †  s   rc  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   )rl  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:   )rQ  )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^  rs  r‘   Úlistdirrþ   rÒ   r,  r’   r  rP   r7   )r8   ra  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Úintervalrl  rÊ  ÚatTimeiÀ¨  iÐ¶  i@ú )	rÉ  ró   r   r4   rì   rä   ÚcomputeRolloverrI   r=   )r8   ÚcurrentTimerŠ  rg  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‰  rl  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dayrg  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;   rx  Ú  s   *	rx  c              K   s   t jf | Žt jdd S )NrW   )rz  )rÉ  r{  )rù  r:   r:   r;   r  H  s    r  )ry  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‰  rl  rÊ  g        r‡  r`  rñ   r1  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ý   rl  rI   r=   )r8   rˆ  Úexprg  rŒ  rR   rE  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_loggingr1  z#Insufficient privileges to run testrÍ   zTest Log MessageFr/  zTest Log Message
Tz3Record not found in event log, went back %d records)rÍ   )Úwin32evtlogZOpenEventLogZGetNumberOfEventLogRecordsr   r4   ZNTEventLogHandlerÚ
pywintypesrr   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;   rr  y  s8    





z NTEventLogHandlerTest.test_basicN)rZ   r[   r\   rr  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PlaceHolderrr  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Â   rt  r†  rÁ  rÛ  rø  r  r  r%  rk  rµ  rÑ  r'  r  rz  r†  râ  rô  r  r2  r@  rl  r`  rc  rØ  r  rÕ  rà  rä  ræ  r—  rx  rÚ  rß  rã  rœ  r  r   r4   rs  r  r   Zrun_unittest)Ztestsr:   r:   r;   Ú	test_main¨  s    
r   Ú__main__)N)šr   Zlogging.handlersZlogging.configr  r“  rÉ  ré   rÎ  r(   rÿ  rT  rÖ   r‡  rö   rD   r  r7  rÌ  rÒ   rÔ   Ztest.support.script_helperr   r   r  r   r‡  rú   ró   r  r  rû  rF  Zhttp.serverr   r   r5  Zurllib.parser   r   Zsocketserverr	   r
   r   r   r˜  rš  r™  rò  ro  ZTestCaser   r]   r…   ZSILENTrµ   ZTERSEZEFFUSIVEr´   r¾   Z	TALKATIVEr²   Z
CHATTERBOXZBORINGrò   r»   r·   r‡   r°   r³   r¶   rÂ   rw  r  r-   r"  r%  r'  r6  r3  rK  rO  r^  rc  r  ri  rk  rl  rt  r/   r„  r†  rÁ  rÙ  r›  rÚ  rÛ  rß  rà  rã  ZIPV6_ENABLEDrä  ræ  rø  r  r  r"  r#  r$  r%  rk  rz  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  r2  r@  r]  r`  rc  rx  r  rˆ  r•  r–  rÜ  r—  rœ  Zrun_with_localer   rZ   r:   r:   r:   r;   Ú<module>   sH  m FY _,J5)/ N   JY@CM41(
        ,#i`
	Y'Wk5 Ol +Tn!#
