
    R?g"                     .   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
Jr  S SKJrJrJr  S SKJr  S SKJr  \ R(                  S 5       r " S S\R,                  5      r " S	 S
\R,                  5      r " S S\R,                  5      rg)    N)utf8)LogFormatterdefine_logging_optionsenable_pretty_logging)OptionParser)basestring_typec               #      #    [         R                  " 5          [         R                  " S[        S9  S v   S S S 5        g ! , (       d  f       g = f7f)Nignore)category)warningscatch_warningssimplefilterBytesWarning     7/usr/lib/python3/dist-packages/tornado/test/log_test.pyignore_bytes_warningr       s/     		 	 	"h> 
#	"	"s   A?	A
A	Ac                   n    \ rS rSr\R
                  " S5      rS rS rS r	S r
S rS rS	 rS
 rS rSrg)LogFormatterTest'   sD   (?s)\[E [0-9]{6} [0-9]{2}:[0-9]{2}:[0-9]{2} log_test:[0-9]+\] (.*)c                 B   [        SS9U l        [        R                  S0U R                  l        SU R                  l        [        R                  " S5      U l        SU R                  l        [        R                  " 5       U l        [        R                  R                  U R                  S5      U l        U R!                  U R                  5      U l        U R"                  R%                  U R                  5        U R                  R'                  U R"                  5        g )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   setUpLogFormatterTest.setUp.   s    %E2
 #*--!:!)nn%78 %'')T\\9=((7!!$..1t||,r   c                     U R                   R                  5         [        R                  " U R                  5        [        R
                  " U R                  5        g N)r+   closer&   unlinkr)   rmdirr%   r.   s    r   tearDownLogFormatterTest.tearDown?   s2    
		$-- 
r   c                 ,    [         R                  " USS9$ )Nutf-8encoding)r   FileHandler)r/   r)   s     r   r*   LogFormatterTest.make_handlerD   s    ""8g>>r   c                 *   [        U R                  S5       nUR                  5       R                  5       n[        R
                  R                  U5      nU(       a  UR                  S5      sS S S 5        $ [        SU-  5      e! , (       d  f       g = f)Nrb   zoutput didn't match regex: %r)	openr)   readstripr   LINE_REmatchgroup	Exception)r/   flinems       r   
get_outputLogFormatterTest.get_outputG   sl    $--&!668>>#D ((..t4Awwqz	 '&   ?$ FGG '&s   AB6B
Bc                 z    U R                   R                  S5        U R                  U R                  5       S5        g )Nfoos   foo)r!   errorassertEqualrL   r.   s    r   test_basic_logging#LogFormatterTest.test_basic_loggingP   s+    % *F3r   c           	          [        5          U R                  R                  S5        U R                  U R	                  5       [        [        S5      5      5        S S S 5        g ! , (       d  f       g = f)N   )r   r!   rP   rQ   rL   r   reprr.   s    r   test_bytes_logging#LogFormatterTest.test_bytes_loggingT   sF    !#KKg&T__.T']0CD $##s   AA""
A0c           
         [        5          U R                  R                  SR                  S5      5        S S S 5        [	        [
        [        5      (       a*  U R                  U R                  5       [        S5      5        g U R                  U R                  5       [        [        [        S5      5      5      5        g ! , (       d  f       N= f)N   ér   )r   r!   rP   encode
issubclassbytesr   rQ   rL   r   rV   r.   s    r   test_utf8_logging"LogFormatterTest.test_utf8_loggingZ   s    !#KKhoof56 $e_-- T__.X?
 T__.T$x.5I0JK $#s   +B==
Cc                      [        S5      e! [          a    U R                  R                  S5         Of = fU R                  5       nU R	                  US5        U R                  SU5        g )NrU   zcaught exceptions   Exception.*\\xe9s   \n)rH   r!   	exceptionrL   assertRegexassertNotIn)r/   outputs     r   test_bytes_exception_logging-LogFormatterTest.test_bytes_exception_loggingg   sc    	6G$$ 	6KK!!"45	6 "!56(s    %55c                     U R                   R                  S5        U R                  U R                  5       [	        S5      5        g )NrZ   )r!   rP   rQ   rL   r   r.   s    r   test_unicode_logging%LogFormatterTest.test_unicode_loggings   s/    (#*DN;r   )r)   r   r+   r!   r%   N)__name__
__module____qualname____firstlineno__recompilerE   r0   r7   r*   rL   rR   rW   r^   re   rh   __static_attributes__r   r   r   r   r   '   sE     jjWG-"
?H4EL
)<r   r   c                   :   ^  \ rS rSrU 4S jrS rS rS rSrU =r	$ )EnablePrettyLoggingTestx   c                    > [         TU ]  5         [        5       U l        [	        U R                  5        [
        R                  " S5      U l        SU R                  l        g )Nz-tornado.test.log_test.EnablePrettyLoggingTestF)	superr0   r   optionsr   r   r    r!   r"   )r/   	__class__s    r   r0   EnablePrettyLoggingTest.setUpy   s>    #~t||,nn%TU %r   c                    [         R                  " 5       n US-   U R                  l        [	        U R                  U R
                  S9  U R                  S[        U R
                  R                  5      5        U R
                  R                  S5        U R
                  R                  S   R                  5         [        R                  " US-   5      nU R                  S[        U5      5        [        US   SS9 nU R                  UR                  5       S	5        S S S 5        U R
                  R                   H#  nUR                  5         UR                  5         M%     [        R                  " US-   5       H  n[         R"                  " U5        M     [         R$                  " U5        g ! , (       d  f       N= f! U R
                  R                   H#  nUR                  5         UR                  5         M%     [        R                  " US-   5       H  n[         R"                  " U5        M     [         R$                  " U5        f = f)
N	/test_logrv   r!   rA   hellor   
/test_log*r:   r;   ^\[E [^]]*\] hello$)r#   r$   rv   log_file_prefixr   r!   rQ   lenhandlersrP   flushglobrB   rb   rC   r4   r&   r5   r6   r/   tmpdir	filenamesrI   r+   r)   s         r   test_log_file%EnablePrettyLoggingTest.test_log_file   s   !!#	+1K+?DLL(!$,,t{{KQDKK$8$8 9:KKg&KK  #))+		&<"78IQI/ilW5  +AB 6  ;;// 0 !IIf|&;<		(# =HHV 65  ;;// 0 !IIf|&;<		(# =HHVs%   C$F? ;!F.F? .
F<8F? ?BI
c                 ^   [         R                  " 5       n US-   U R                  l        SU R                  l        [        U R                  U R                  S9  U R                  R                  S5        U R                  R                  S   R                  5         [        R                  " US-   5      nU R                  S[        U5      5        [        US   SS	9 nU R                  UR                  5       S
5        S S S 5        U R                  R                   H#  nUR                  5         UR!                  5         M%     [        R                  " US-   5       H  n["        R$                  " U5        M     ["        R&                  " U5        g ! , (       d  f       N= f! U R                  R                   H#  nUR                  5         UR!                  5         M%     [        R                  " US-   5       H  n["        R$                  " U5        M     ["        R&                  " U5        f = f)Nrz   timer{   r|   r   r}   rA   r:   r;   r~   )r#   r$   rv   r   log_rotate_moder   r!   rP   r   r   r   rQ   r   rB   rb   rC   r4   r&   r5   r6   r   s         r   !test_log_file_with_timed_rotating9EnablePrettyLoggingTest.test_log_file_with_timed_rotating   s   !!#	+1K+?DLL(+1DLL(!$,,t{{KKKg&KK  #))+		&<"78IQI/ilW5  +AB 6  ;;// 0 !IIf|&;<		(# =HHV 65  ;;// 0 !IIf|&;<		(# =HHVs%   CF! !F>F! 
FF! !BH,c                     SU R                   l        SU R                   l        U R                  [        [
        U R                   U R                  S9  U R                  R                   H#  nUR                  5         UR                  5         M%     g ! U R                  R                   H#  nUR                  5         UR                  5         M%     f = f)N	some_path
wrong_moder{   )
rv   r   r   assertRaises
ValueErrorr   r!   r   r   r4   )r/   r+   s     r   test_wrong_rotate_mode_value4EnablePrettyLoggingTest.test_wrong_rotate_mode_value   s    	 +6DLL(+7DLL(%{{	    ;;// 04;;// 0s   AB ?C)r!   rv   )
rj   rk   rl   rm   r0   r   r   r   rp   __classcell__)rw   s   @r   rr   rr   x   s    &((   r   rr   c                   L    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rSrg)LoggingOptionTest   z?Test the ability to enable and disable Tornado's logging hooks.Nc                 <   SnSnSR                  X1U/5      n[        R                  " [        R                  SU/U=(       d    / -   [        R
                  [        R                  S9nUR                  5       u  pxU R                  UR                  SSU-  5        SU;   $ )	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communicaterQ   
returncode)	r/   	statementargsIMPORTLOG_INFOprogramprocr   r   s	            r   logs_presentLoggingOptionTest.logs_present   s     K:((Fx89^^T7+tzr:??$$

 ))+!-AF-JK6!!r   c                 D    U R                  U R                  S5      5        g )NpassassertFalser   r.   s    r   test_defaultLoggingOptionTest.test_default   s    **623r   c                 D    U R                  U R                  S5      5        g )Nparse_command_line()
assertTruer   r.   s    r   test_tornado_default&LoggingOptionTest.test_tornado_default   s    ))*@ABr   c                 H    U R                  U R                  SS/5      5        g )Nr   z--logging=noner   r.   s    r   test_disable_command_line+LoggingOptionTest.test_disable_command_line   "    **+ADTCUVWr   c                 H    U R                  U R                  SS/5      5        g )Nr   z--logging=Noner   r.   s    r   *test_disable_command_line_case_insensitive<LoggingOptionTest.test_disable_command_line_case_insensitive   r   r   c                 D    U R                  U R                  S5      5        g )Nz.options.logging = "none"; parse_command_line()r   r.   s    r   test_disable_code_string*LoggingOptionTest.test_disable_code_string   s    NO	
r   c                 D    U R                  U R                  S5      5        g )N,options.logging = None; parse_command_line()r   r.   s    r   test_disable_code_none(LoggingOptionTest.test_disable_code_none   s    LM	
r   c                 H    U R                  U R                  SS/5      5        g )Nr   z--logging=infor   r.   s    r   test_disable_override'LoggingOptionTest.test_disable_override   s%    >AQ@R	
r   r   r3   )rj   rk   rl   rm   __doc__r   r   r   r   r   r   r   r   rp   r   r   r   r   r      s0    I"$4CXX




r   r   )
contextlibr   r   r&   rn   r   r   r#   unittestr   tornado.escaper   tornado.logr   r   r   tornado.optionsr   tornado.utilr   contextmanagerr   TestCaser   rr   r   r   r   r   <module>r      s       	 	  
     S S ( (  N<x(( N<b= h// = @1
)) 1
r   