
    Mh"                         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 d dlmZmZmZ d dlmZ d dlmZ e j        d             Z G d dej                  Z G d	 d
ej                  Z G d dej                  ZdS )    N)utf8)LogFormatterdefine_logging_optionsenable_pretty_logging)OptionParser)basestring_typec               #      K   t          j                    5  t          j        dt                     d V  d d d            d S # 1 swxY w Y   d S )Nignore)category)warningscatch_warningssimplefilterBytesWarning     U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/tornado/test/log_test.pyignore_bytes_warningr       s      		 	"	"  h>>>>                 s    AA
Ac                   d    e Zd Z ej        d          Zd Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 ZdS )LogFormatterTestsD   (?s)\[E [0-9]{6} [0-9]{2}:[0-9]{2}:[0-9]{2} log_test:[0-9]+\] (.*)c                     t          d          | _        t          j        di| j        _        d| j        _        t          j        d          | _        d| j        _        t          j
                    | _        t          j                            | j        d          | _        |                     | j                  | _        | j                            | j                   | j                            | j                   d S )NF)colorr   zlog.out)r   	formatterloggingERROR_colors_normalLoggerlogger	propagatetempfilemkdtemptempdirospathjoinfilenamemake_handlerhandlersetFormatter
addHandlerselfs    r   setUpzLogFormatterTest.setUp.   s    %E222
 #*-!:!)n%788 %'))T\9==((77!!$.111t|,,,,,r   c                     | j                                          t          j        | j                   t          j        | j                   d S N)r*   closer%   unlinkr(   rmdirr$   r-   s    r   tearDownzLogFormatterTest.tearDown?   s@    
	$-   
r   c                 .    t          j        |d          S )Nutf-8encoding)r   FileHandler)r.   r(   s     r   r)   zLogFormatterTest.make_handlerD   s    "8g>>>>r   c                 <   t          | j        d          5 }|                                                                }t          j                            |          }|r!|                    d          cd d d            S t          d|z            # 1 swxY w Y   d S )Nrb   zoutput didn't match regex: %r)	openr(   readstripr   LINE_REmatchgroup	Exception)r.   flinems       r   
get_outputzLogFormatterTest.get_outputG   s    $-&& 	H!6688>>##D (..t44A Hwwqzz		H 	H 	H 	H 	H 	H 	H 	H   ?$ FGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs   AB?BBBc                     | j                             d           |                     |                                 d           d S )Nfoos   foo)r    errorassertEqualrH   r-   s    r   test_basic_loggingz#LogFormatterTest.test_basic_loggingP   s>    %   **F33333r   c           	         t                      5  | j                            d           |                     |                                 t          t          d                               d d d            d S # 1 swxY w Y   d S )N   )r   r    rK   rL   rH   r   reprr-   s    r   test_bytes_loggingz#LogFormatterTest.test_bytes_loggingT   s    !## 	E 	EKg&&&T__..T']]0C0CDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es   AA99A= A=c           
         t                      5  | j                            d                                           d d d            n# 1 swxY w Y   t	          t
          t                    r7|                     |                                 t          d                     d S |                     |                                 t          t          t          d                                         d S N   é)r   r    rK   encode
issubclassbytesr   rL   rH   r   rP   r-   s    r   test_utf8_loggingz"LogFormatterTest.test_utf8_loggingZ   s   !## 	1 	1Khoo//000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1e_-- 	L T__..X?????
 T__..T$x..5I5I0J0JKKKKKs   -AAAc                     	 t          d          # t           $ r | j                            d           Y nw xY w|                                 }|                     |d           |                     d|           d S )NrO   zcaught exceptions   Exception.*\\xe9s   \n)rD   r    	exceptionrH   assertRegexassertNotIn)r.   outputs     r   test_bytes_exception_loggingz-LogFormatterTest.test_bytes_exception_loggingg   s    	6G$$$ 	6 	6 	6K!!"455555	6 ""!5666(((((s    $88c                     | j                             d           |                     |                                 t	          d                     d S rS   )r    rK   rL   rH   r   r-   s    r   test_unicode_loggingz%LogFormatterTest.test_unicode_loggings   sD    (###**DNN;;;;;r   N)__name__
__module____qualname__recompilerA   r/   r5   r)   rH   rM   rQ   rX   r^   r`   r   r   r   r   r   '   s         bjW G- - -"  
? ? ?H H H4 4 4E E EL L L
) 
) 
)< < < < <r   r   c                   0     e Zd Z fdZd Zd Zd Z xZS )EnablePrettyLoggingTestc                     t                                                       t                      | _        t	          | j                   t          j        d          | _        d| j        _        d S )Nz-tornado.test.log_test.EnablePrettyLoggingTestF)	superr/   r   optionsr   r   r   r    r!   )r.   	__class__s    r   r/   zEnablePrettyLoggingTest.setUpy   sQ    #~~t|,,,n%TUU %r   c                 h   t          j                    }	 |dz   | j        _        t	          | j        | j                   |                     dt          | j        j                             | j        	                    d           | j        j        d         
                                 t          j        |dz             }|                     dt          |                     t          |d         d          5 }|                     |                                d	           d d d            n# 1 swxY w Y   | j        j        D ]*}|
                                 |                                 +t          j        |dz             D ]}t!          j        |           t!          j        |           d S # | j        j        D ]*}|
                                 |                                 +t          j        |dz             D ]}t!          j        |           t!          j        |           w xY w)
N	/test_logrj   r    r=   hellor   
/test_log*r7   r8   ^\[E [^]]*\] hello$)r"   r#   rj   log_file_prefixr   r    rL   lenhandlersrK   flushglobr>   r[   r?   r2   r%   r3   r4   r.   tmpdir	filenamesrE   r*   r(   s         r   test_log_filez%EnablePrettyLoggingTest.test_log_file   sK   !##	+1K+?DL(!$,t{KKKKQDK$8 9 9:::Kg&&&K #))+++	&<"788IQI///ilW555 C  +ABBBC C C C C C C C C C C C C C C  ;/     If|&;<< $ $	(####HV  ;/     If|&;<< $ $	(####HVs1   C&F6 ;)D0$F6 0D44F6 7D48F6 6A;H1c                 &   t          j                    }	 |dz   | j        _        d| j        _        t          | j        | j                   | j                            d           | j        j        d         	                                 t          j
        |dz             }|                     dt          |                     t          |d         d	          5 }|                     |                                d
           d d d            n# 1 swxY w Y   | j        j        D ]*}|	                                 |                                 +t          j
        |dz             D ]}t#          j        |           t#          j        |           d S # | j        j        D ]*}|	                                 |                                 +t          j
        |dz             D ]}t#          j        |           t#          j        |           w xY w)Nrm   timern   ro   r   rp   r=   r7   r8   rq   )r"   r#   rj   rr   log_rotate_moder   r    rK   rt   ru   rv   rL   rs   r>   r[   r?   r2   r%   r3   r4   rw   s         r   !test_log_file_with_timed_rotatingz9EnablePrettyLoggingTest.test_log_file_with_timed_rotating   s2   !##	+1K+?DL(+1DL(!$,t{KKKKKg&&&K #))+++	&<"788IQI///ilW555 C  +ABBBC C C C C C C C C C C C C C C  ;/     If|&;<< $ $	(####HV  ;/     If|&;<< $ $	(####HVs1   CF )DF DF DF A;Hc                 x   	 d| j         _        d| j         _        |                     t          t
          | j         | j                   | j        j        D ]*}|                                 |	                                 +d S # | j        j        D ]*}|                                 |	                                 +w xY w)N	some_path
wrong_modern   )
rj   rr   r}   assertRaises
ValueErrorr   r    rt   ru   r2   )r.   r*   s     r   test_wrong_rotate_mode_valuez4EnablePrettyLoggingTest.test_wrong_rotate_mode_value   s    	 +6DL(+7DL(%{	      ;/       4;/     s   AB   9B9)ra   rb   rc   r/   rz   r~   r   __classcell__)rk   s   @r   rg   rg   x   se        & & & & &  (  (             r   rg   c                   D    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 ZdS )LoggingOptionTestz?Test the ability to enable and disable Tornado's logging hooks.Nc                 (   d}d}d                     |||g          }t          j        t          j        d|g|pg z   t          j        t          j                  }|                                \  }}|                     |j	        dd|z             d|v S )	Nz7from tornado.options import options, parse_command_linez%import logging; logging.info("hello");z-c)stdoutstderrr   zprocess failed: %rs   hello)
r'   
subprocessPopensys
executablePIPESTDOUTcommunicaterL   
returncode)	r.   	statementargsIMPORTLOG_INFOprogramprocr   r   s	            r   logs_presentzLoggingOptionTest.logs_present   s     K:((FIx899^T7+tzr:?$
 
 

 ))++!-AF-JKKK6!!r   c                 V    |                      |                     d                     d S )NpassassertFalser   r-   s    r   test_defaultzLoggingOptionTest.test_default   s*    **62233333r   c                 V    |                      |                     d                     d S )Nparse_command_line()
assertTruer   r-   s    r   test_tornado_defaultz&LoggingOptionTest.test_tornado_default   s)    ))*@AABBBBBr   c                 Z    |                      |                     ddg                     d S )Nr   z--logging=noner   r-   s    r   test_disable_command_linez+LoggingOptionTest.test_disable_command_line   1    **+ADTCUVVWWWWWr   c                 Z    |                      |                     ddg                     d S )Nr   z--logging=Noner   r-   s    r   *test_disable_command_line_case_insensitivez<LoggingOptionTest.test_disable_command_line_case_insensitive   r   r   c                 V    |                      |                     d                     d S )Nz.options.logging = "none"; parse_command_line()r   r-   s    r   test_disable_code_stringz*LoggingOptionTest.test_disable_code_string   s6    NOO	
 	
 	
 	
 	
r   c                 V    |                      |                     d                     d S )N,options.logging = None; parse_command_line()r   r-   s    r   test_disable_code_nonez(LoggingOptionTest.test_disable_code_none   s6    LMM	
 	
 	
 	
 	
r   c                 Z    |                      |                     ddg                     d S )Nr   z--logging=infor   r-   s    r   test_disable_overridez'LoggingOptionTest.test_disable_override   s>    >AQ@R 	
 	
 	
 	
 	
r   r1   )ra   rb   rc   __doc__r   r   r   r   r   r   r   r   r   r   r   r   r      s        II" " " "$4 4 4C C CX X XX X X
 
 


 
 


 
 
 
 
r   r   )
contextlibrv   r   r%   rd   r   r   r"   unittestr   tornado.escaper   tornado.logr   r   r   tornado.optionsr   tornado.utilr   contextmanagerr   TestCaser   rg   r   r   r   r   <module>r      su         				 				     



          S S S S S S S S S S ( ( ( ( ( ( ( ( ( ( ( (   N< N< N< N< N<x( N< N< N<b=  =  =  =  = h/ =  =  = @1
 1
 1
 1
 1
) 1
 1
 1
 1
 1
r   