
    5f4                       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	Z		 d dl
Z
	 d dlmZ d dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lm Z! d dl"Z"d dl#m$Z$ d dl#m%Z% d dl#m&Z& d dl#m'Z' d dl(m)Z) dZ*d Z+ G d de,      Z- G d de-e!j\                        Z/ G d de!j\                        Z. G d de.      Z0 G d de.      Z1 G d de.      Z2 e"jf                  e
d       G d d e.             Z4 G d! d"e.      Z5 G d# d$e.      Z6 G d% d&e0      Z7d' Z8 G d( d)ejr                        Z: G d* d+e0      Z; G d, d-e0      Z< G d. d/e0      Z= G d0 d1e0      Z> G d2 d3e0      Z? G d4 d5e0      Z@ G d6 d7e0      ZA G d8 d9e.      ZB e"j                   ej                         d:k7  d;       G d< d=e.             ZE G d> d?e.      ZF G d@ dAe.      ZG G dB dCe.      ZH G dD dEe'j                        ZJ G dF dGe.      ZK G dH dIe.      ZL G dJ dKe/      ZM G dL dMe!j\                        ZNy# e$ r dZ
Y w xY w# e$ r dZY &w xY w)N    )contextmanagerN)journal)mock)tz)cfg)fixturecontext)	jsonutils)base)_options)
formatters)handlers)log)unitssS   [loggers]
keys=root

[formatters]
keys=

[handlers]
keys=

[logger_root]
handlers=
c                  B    t        j                  ddddddddd	      } | S )NmyusermyscopemydomainmytenantmyuserdomainT)	user_id	user_namesystem_scopedomain
project_idproject_nameproject_domain_iduser_domain_id	overwrite)r
   RequestContext)ctxts    >/usr/lib/python3/dist-packages/oslo_log/tests/unit/test_log.py_fake_contextr$   G   s3    !!(,4/8)3-7/94>1?,02D K    c                       e Zd ZdZ fdZd Zd Zd Zd Zd Z	 e
j                  dd	
      d        Z e
j                  dd
       e
j                  d       e
j                  d      d                      Z e
j                  d       e
j                  dd
       e
j                  dd	
      d                      Z e
j                  d       e
j                  dd
       e
j                  dd
      d                      Z e
j                  d       e
j                  dd
      d               Z e
j                  d       e
j                  dd
      d               Z xZS )CommonLoggerTestsMixInzNThese tests are shared between LoggerTestCase and
    LazyLoggerTestCase.
    c                 B   t         t        |           | j                  t	        j
                  t        j                                     | _        | j                  j                  | _	        | j                  j                  | _        t        j                  | j                  j                         | j                  d       d | _        t        j                  | j                  j                  dd       t        j                  d       j                   j"                  | _        y )NzT%(asctime)s %(levelname)s %(name)s [%(request_id)s %(user)s %(project)s] %(message)slogging_context_format_stringtest)superr'   setUp
useFixturefixture_configConfigr   
ConfigOptsconfig_fixtureconfigconfCONFr   register_options_setup_logging_from_conf	getLoggerloggerr   log_handlersself	__class__s    r#   r-   zCommonLoggerTestsMixIn.setUpZ   s    $d13"oo!!#.."235))00'',,	T00556 3@ 	A $$T%8%8%=%=vvNMM$/66??r%   c                 h   g }| j                   j                  j                  D ]:  }|j                  }t	        |t
        j                        s*|j                  |       < | j                  |       | j                  t        |      t        | j                   j                  j                               y N)r   r9   r   	formatter
isinstancer   ContextFormatterappend
assertTrueassertEquallen)r<   formatters_listhfs       r#   $test_handlers_have_context_formatterz;CommonLoggerTestsMixIn.test_handlers_have_context_formatterj   s    )) 	*AA!Z889&&q)	* 	(_-s488??3K3K/LMr%   c                 p    | j                   j                  dt                      | j                  d       y )Nfoor	   T)r   infor$   rD   r<   s    r#   test_handles_context_kwargz1CommonLoggerTestsMixIn.test_handles_context_kwargs   s$    e]_5r%   c                     | j                  d       d}t        j                  | j                  |       t	        j
                  |      }| j                  t        j                  |j                                y )NTdebugtest_is_debug)	r3   r   setupr5   loggingr8   rE   DEBUGgetEffectiveLevelr<   logger_namer9   s      r#   $test_will_be_debug_if_debug_flag_setz;CommonLoggerTestsMixIn.test_will_be_debug_if_debug_flag_setw   sT    $%		$))[)"";/(@(@(BCr%   c                     | j                  d       d}t        j                  | j                  |       t	        j
                  |      }| j                  t        j                  |j                                y )NFrQ   test_is_not_debug)	r3   r   rT   r5   rU   r8   rE   INFOrW   rX   s      r#   'test_will_be_info_if_debug_flag_not_setz>CommonLoggerTestsMixIn.test_will_be_info_if_debug_flag_not_set~   sT    % )		$))[)"";/v'?'?'ABr%   c                 R    dD ]"  }| j                  t        t        t        |       $ y )N)criticalerror	exceptionwarningwarnrM   rR   r   )assertRaisesAttributeErrorgetattrr   )r<   funcs     r#   test_no_logging_via_modulez1CommonLoggerTestsMixIn.test_no_logging_via_module   s)    - 	BDngsDA	Br%   zplatform.systemLinuxreturn_valuec                     | j                  d       | j                  t        t        j                  | j
                  dd       y NT)use_eventlogr+   )r3   re   RuntimeErrorr   r7   r5   )r<   platform_mocks     r#   test_eventlog_missingz,CommonLoggerTestsMixIn.test_eventlog_missing   s6    &,66))  		"r%   Windowsz"logging.handlers.NTEventLogHandlerzoslo_log.log.getLoggerc                    | j                  d       t        j                  | j                  dd       |j	                  d       |j
                  j                  }|j                  j                  |j
                         y rn   )	r3   r   r7   r5   assert_called_once_withrl   r9   
addHandlerassert_any_call)r<   loggers_mockhandler_mockrq   mock_loggers        r#   test_eventlogz$CommonLoggerTestsMixIn.test_eventlog   sa     	&$$TYY?,,V4"//66..|/H/HIr%   z(oslo_log.watchers.FastWatchedFileHandlerzoslo_log.log._get_log_file_pathz	test.confc                     | j                  d       t        j                  | j                  dd       |j	                  |j
                         | j                  | j                  d   |j
                         y NTwatch_log_filer+   r   r3   r   r7   r5   ru   rl   rE   r:   )r<   platfotm_mock	path_mockry   s       r#   test_watchlog_on_linuxz-CommonLoggerTestsMixIn.test_watchlog_on_linux   ]     	4($$TYY?,,Y-C-CD**1-|/H/HIr%   z#logging.handlers.WatchedFileHandlerc                     | j                  d       t        j                  | j                  dd       |j	                  |j
                         | j                  | j                  d   |j
                         y r}   r   )r<   rq   r   ry   s       r#   test_watchlog_on_windowsz/CommonLoggerTestsMixIn.test_watchlog_on_windows   r   r%   z)logging.handlers.TimedRotatingFileHandlerc                    d}d}d}d}| j                  ||||       t        j                  | j                  dd       |j	                  |j
                  d||       | j                  | j                  d   |j
                         y )	Nintervalweekday   )log_rotation_typelog_rotate_intervallog_rotate_interval_typemax_logfile_countr+   w2)whenr   backupCountr   r   )r<   r   ry   rotation_typer   r   backup_counts          r#   test_timed_rotate_logz,CommonLoggerTestsMixIn.test_timed_rotate_log   s     #m(0-1&2 	 	4 	$$TYY?,,Y-C-C266>9E 	- 	G 	**1-|/H/HIr%   z$logging.handlers.RotatingFileHandlerc                 .   d}d}|t         j                  z  }d}| j                  |||       t        j                  | j
                  dd       |j                  |j                  ||       | j                  | j                  d   |j                         y )Nsized   r   )r   max_logfile_size_mbr   r+   )maxBytesr   r   )
r   Mir3   r   r7   r5   ru   rl   rE   r:   )r<   r   ry   r   r   r   r   s          r#   test_rotate_logz&CommonLoggerTestsMixIn.test_rotate_log   s     !&1m(;&2 	 	4 	$$TYY?,,Y-C-C6>9E 	- 	G 	**1-|/H/HIr%   )__name__
__module____qualname____doc__r-   rJ   rO   rZ   r^   ri   r   patchrr   r{   r   r   r   r   __classcell__r=   s   @r#   r'   r'   U   s   @ NDCB
 TZZ!8" 9" TZZ!	:TZZ45TZZ()J * 6 ;J TZZ:;TZZ1LTZZ!8J 9 M <J TZZ56TZZ1LTZZ!	:J ; M 7J TZZ;<TZZ1LJ M =J  TZZ67TZZ1LJ M 8Jr%   r'   c                        e Zd Z fdZ xZS )LoggerTestCasec                 ^    t         t        |           t        j                  d       | _        y r?   )r,   r   r-   r   r8   r;   s    r#   r-   zLoggerTestCase.setUp   s     nd)+==&r%   r   r   r   r-   r   r   s   @r#   r   r      s    ' 'r%   r   c                        e Zd Z fdZ xZS )BaseTestCasec                    t         t        |           | j                  t	        j
                               | _        | j                  t        j                  t        j                                     | _        | j                  j                  | _        | j                  j                  | _        t        j                   | j                         t        j"                  | j                  d       y )Nr   )r,   r   r-   r.   fixture_contextClearRequestContextcontext_fixturer/   r0   r   r1   r2   r3   r4   r5   r   r6   rT   r;   s    r#   r-   zBaseTestCase.setUp   s    lD')#//1 3"oo!!#.."235))00'',,	TYY'		$))V$r%   r   r   s   @r#   r   r      s    	% 	%r%   r   c                   "    e Zd ZdZ	 	 ddZd Zy)LogTestBasez9Base test class that provides some convenience functions.Nc                    t        j                         | _        |t        j                  } || j                        | _        |t        j                  }| j
                  j                   |              |j                  j                  | j
                         | j                  |j                  j                  | j
                         y)a  Add a log handler to a log instance.

        This function should be used to add handlers to loggers in test cases
        instead of directly adding them to ensure that the handler is
        correctly removed at the end of the test.  Otherwise the handler may
        be left on the logger and interfere with subsequent tests.

        :param log_instance: The log instance to which the handler will be
            added.
        :param handler: The handler class to be added.  Must be the class
            itself, not an instance.
        :param formatter: The formatter class to set on the handler.  Must be
            the class itself, not an instance.
        N)ioStringIOstreamrU   StreamHandlerhandlerr   rB   setFormatterr9   rv   
addCleanupremoveHandler)r<   log_instancer   r@   s       r#   _add_handler_with_cleanupz%LogTestBase._add_handler_with_cleanup   s      kkm?++Gt{{+"33I!!)+.&&t||4++994<<Hr%   c                     |j                   j                         | _        |j                   j                  |       | j	                  |j                   j                  | j                         y)aN  Set the log level of a logger for the duration of a test.

        Use this function to set the log level of a logger and add the
        necessary cleanup to reset it back to default at the end of the test.

        :param log_instance: The logger whose level will be changed.
        :param level: The new log level to use.
        N)r9   rW   levelsetLevelr   )r<   r   r   s      r#   _set_log_level_with_cleanupz'LogTestBase._set_log_level_with_cleanup  sL     "((::<
$$U+++44djjAr%   )NN)r   r   r   r   r   r    r%   r#   r   r      s    C>B,0I4Br%   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)LogHandlerTestCasec                 *   t         j                  j                  dd      }d}t         j                  j                  |d|z        }| j                  |d        | j	                  t        j                  | j                  j                  |      |       y )Nsomepathfoo-bar%s.loglog_dirlog_filebinary	osr   joinr3   rE   r   _get_log_file_pathr2   r4   r<   r   r   expecteds       r#   test_log_path_logdirz'LogHandlerTestCase.test_log_path_logdir  ss    ww||FF+77<<h&78D40//0C0C0H0H &(!	#r%   c                 (   t         j                  j                  dd      }d}t         j                  j                  |d|z        }| j                  |       | j	                  t        j                  | j                  j                  |      |       y )Nr   r   r   r   )r   r   r   r   s       r#   test_log_path_logfilez(LogHandlerTestCase.test_log_path_logfile  sq    ww||FF+77<<h&78X&//0C0C0H0H &(!	#r%   c                     d}| j                  d d        | j                  t        j                  | j                  j
                  |             y )Nr   r   r   )r3   assertIsNoner   r   r2   r4   )r<   prefixs     r#   test_log_path_nonez%LogHandlerTestCase.test_log_path_none"  sC    D40#001D1D1I1I!') 	*r%   c                    t         j                  j                  t         j                  dd      }d}t         j                  j                  |d|z        }| j	                  t         j                  j                  ddd      |       | j                  t        j                  | j                  j                  |      |       y )Nr   r   r   r   otherr   r   )
r   r   r   sepr3   rE   r   r   r2   r4   )r<   r   r   r   s       r#   &test_log_path_logfile_overrides_logdirz9LogHandlerTestCase.test_log_path_logfile_overrides_logdir(  s    ww||BFFFF377<<h&78BGGLL&A% 	 	'//0C0C0H0H &(!	#r%   c                     t        j                  d      }t        t        j                               }| j                  t        j                         |       | j                  ||       y )Nzabc.cde)rU   r8   listr   _iter_loggersassertIn)r<   mylogloggerss      r#   test_iter_loggersz$LogHandlerTestCase.test_iter_loggers2  sJ    !!),s((*+g'')73eW%r%   N)r   r   r   r   r   r   r   r   r   r%   r#   r   r     s    ##*#&r%   r   c                   (     e Zd ZdZ fdZd Z xZS )SysLogHandlersTestCasez!Test the standard Syslog handler.c                     t         t        |           t        j                  j
                  j                  | _        t        j                  j                  | j                        | _        y )N)facility)	r,   r   r-   rU   r   SysLogHandlerLOG_USERr   r9   r;   s    r#   r-   zSysLogHandlersTestCase.setUp;  sI    $d13((66??&&44dmm4Lr%   c           	          t        j                  dt         j                  ddddd      }|}| j                  |j	                         | j
                  j                  |             y)z6Ensure syslog msg isn't modified for standard handler.namez/tmp   MessageN)rU   	LogRecordWARNINGrE   
getMessager9   format)r<   	logrecordr   s      r#   test_standard_formatz+SysLogHandlersTestCase.test_standard_format@  sU    %%fgoovq&/t=	,,.++I6	8r%   )r   r   r   r   r-   r   r   r   s   @r#   r   r   9  s    +M
8r%   r   zsyslog is not availablec                   $    e Zd Zd Zd Zd Zd Zy)OSSysLogHandlerTestCasec                 (   t        j                         }t        j                         t        _        |j                  t        j                  dt        j                  dddd d              | j                  t        j                  j                         y NrL   r   {   zhey!)r   OSSysLogHandlerr   MocksyslogemitrU   r   r]   rD   calledr<   r   s     r#   test_handlerz$OSSysLogHandlerTestCase.test_handlerK  sc    **,		eW\\$c6"D*	+ 	,,-r%   c                     t        j                         t        _        t	        j
                          t        j                  j                  t	        j                         dt        j                         y Nr   )	r   r   r   openlogr   r   assert_called_with_get_binary_namer   rN   s    r#   test_syslog_binary_namez/OSSysLogHandlerTestCase.test_syslog_binary_nameT  sC       "))(*C*C*E*+V__	>r%   c                    | j                  t        j                  t        j                  d             | j                  t        j
                  t        j                  d             | j                  t        j                  t        j                  d             | j                  t        j                  t        j                  d             | j                  t        t        j                  d       y )NuserLPR
log_local3LOG_UUCPfougere)
rE   r   r   r   _find_facilityLOG_LPR
LOG_LOCAL3r	  re   	TypeErrorrN   s    r#   test_find_facilityz*OSSysLogHandlerTestCase.test_find_facility]  s    #*<*<V*DE););E)BC**C,>,>|,LM#*<*<Z*HI),,#	%r%   c                 6   d}t        j                         }t        j                         t        _        |j                  t        j                  dt        j                  dd|d d              t        j                  j                  t        j                  |       y )Nu3   Benoît Knecht & François Deppierraz login failurer   r   r   )r   r   r   r   r   r   rU   r   r]   ru   LOG_INFO)r<   msg_unicoder   s      r#   test_syslogz#OSSysLogHandlerTestCase.test_syslogf  si    L**,		fgllFC)47	8 	--foo{Kr%   N)r   r   r   r   r  r  r  r   r%   r#   r   r   I  s    .>%Lr%   r   c                   `     e Zd ZdZ fdZ ej                  ed      d        Zd Z	d Z
 xZS )OSJournalHandlerTestCaseaF  Test systemd journal logging.

    This is a lightweight test for testing systemd journal logging. It
    mocks out the journal interface itself, which allows us to not
    have to have systemd-python installed (which is not possible to
    install on non Linux environments).

    Real world testing is also encouraged.

    c                 (   t         t        |           | j                  d       t	        j
                  d      j                         | _        | j                  | j                  j                         t        j                  | j                  d       y )NT)use_journalzoslo_log.handlers.journaltesting)r,   r  r-   r3   r   r   startr   r   stopr   rT   r5   r;   s    r#   r-   zOSJournalHandlerTestCase.setUp{  sa    &35%zz"=>DDF))*		$))Y'r%   z(systemd journal binding is not availablec                     t        j                         }|j                  t        j                  dt        j
                  dddd d              | j                  | j                  j                  j                         y r   )
r   OSJournalHandlerr   rU   r   r]   rD   r   sendr   r   s     r#   r   z%OSJournalHandlerTestCase.test_handler  s\    ++-eW\\$c6"D*	+ 	))001r%   c                    t        j                  d      }t               }|j                  d|       | j	                  t        j                  t
        j                  t
        j                  dt
        j                  dddt        j                  t
        j                  t
        j                  dddd	d
      | j                  j                  j                         | j                  j                  j                  \  }}| j	                  t        |      d       | j                  |d   t               | j                  |d   t                | j                  |d   t                | j                  |d   t                |d= |d= |d= |j#                         D ]7  \  }}| j                  |t               | j                  |t$        t        f       9 y )Nnova-test.fooFoor	   	test_emitr]      r   MainProcess
MainThreadr   )	CODE_FILE	CODE_FUNC	CODE_LINELOGGER_LEVELLOGGER_NAMEPRIORITYSYSLOG_FACILITYSYSLOG_IDENTIFIER
REQUEST_ID
PROJECT_IDPROJECT_NAMEPROCESS_NAMETHREAD_NAME	USER_NAMEr   r   r'  r*  r+  )r   r8   r$   rM   rE   r   callANYr   r   r   r  	call_argsrF   assertIsInstancestrintitemsbytesr<   r9   local_contextargskwargskeyargs          r#   r!  z"OSJournalHandlerTestCase.test_emit  sm   /%E=1IIdhh$((k $v"1A&,oo(,!%!+#-#0". (
* LL''	) ||((22fTA&d1gs+f[137fZ0#6f%67=;
!3V<M5N 	5HC!!#s+!!#s|4	5r%   c                 L   t        j                  d      }t               }	 t        d      # t        $ r |j	                  d|       Y nw xY w| j                  t        j                  t        j                  fi dt        j                  dddt        j                  d	d
dddddt        j                  dt        j                  dt        j                  dt        j                  dt        j                  dddddddddd| j                  j                  j                         | j                  j                  j                  \  }}| j                  t        |      d       | j                  |d   t                | j                  |d   t"               | j                  |d   t"               | j                  |d   t"               |d= |d= |d= |j%                         D ]7  \  }}| j                  |t                | j                  |t&        t         f       9 y )Nznova-exception.foozSome exceptionr   r	   r%  r&  test_emit_exceptionr'  r(  ERRORr)  r*     r+  r,  r-  EXCEPTION_INFOEXCEPTION_TEXTr.  r   r/  r0  r#  r1  r$  r2  r   r   r   )r   r8   r$   	Exceptionrb   rE   r   r3  r4  r   r   r   r  r5  rF   r6  r7  r8  r9  r:  r;  s          r#   rB  z,OSJournalHandlerTestCase.test_emit_exception  s   34%	;,-- 	;UM:	;IIdhh *$(( * 5* $*7>* #7* BC* '-oo	*
 )-* "&* &*XX* &*XX* ",* $.* $1* #/* !)* LL''	)  ||((22fTA&d1gs+f[137fZ0#6f%67=;
!3V<M5N 	5HC!!#s+!!#s|4	5s   , A
A)r   r   r   r   r-   	testtools
skipUnlessr   r   r!  rB  r   r   s   @r#   r  r  p  s<    	( Y'#MN2 O258 5r%   r  c                   B     e Zd Z fdZd Zd Zd Zd Zd Zd Z	 xZ
S )LogLevelTestCasec                 :   t         t        |           | j                  j                  }d}d}d}d}|j                  |dz          |j                  |dz          |j                  |dz          |j                  |dz          | j                  |	       t        j                  | j                  d
       t        j                  |      | _        t        j                  |      | _
        t        j                  |      | _        t        j                  |      | _        y )Nz	nova-testznova-not-debugznova-below-debugz
nova-tracez=INFOz=WARNz=7z=TRACEdefault_log_levelsr  )r,   rK  r-   r5   rN  rC   r3   r   rT   r8   log_no_debuglog_below_debug	log_trace)r<   levels
info_level
warn_levelother_leveltrace_levelr=   s         r#   r-   zLogLevelTestCase.setUp  s    +--- 
%
("j7*+j7*+kD()kH,-v.		$))Y'==,MM*5"}}[9{3r%   c                    | j                  | j                  j                  t        j                               | j                  | j                  j                  t        j                               | j                  | j                  j                  t        j                               | j                  | j                  j                  d             | j                  | j                  j                  t        j                               y )N   )rD   r   isEnabledForrU   r]   assertFalserO  rV   rP  rQ  TRACErN   s    r#   test_is_enabled_forz$LogLevelTestCase.test_is_enabled_for  s    --gll;<**77FG,,99'--HI,,99!<=33CII>?r%   c                     | j                  t        j                  | j                  j                  j                                y r?   )rE   rU   r]   r   r9   rW   rN   s    r#   test_has_level_from_flagsz*LogLevelTestCase.test_has_level_from_flags  s'    txx'H'H'JKr%   c                     | j                  t        j                  | j                  j                  j                                y r?   )rE   r   r[  rQ  r9   rW   rN   s    r#   #test_has_level_from_flags_for_tracez4LogLevelTestCase.test_has_level_from_flags_for_trace  s)    DNN$9$9$K$K$MNr%   c                     t        j                  d      }| j                  t        j                  |j
                  j                                y )Nr  )r   r8   rE   rU   r]   r9   rW   r<   r9   s     r#   'test_child_log_has_level_of_parent_flagz8LogLevelTestCase.test_child_log_has_level_of_parent_flag  s1    /v}}'F'F'HIr%   c                     t        j                  d      }| j                  t         j                  |j                  j                                y )Nznova-trace.foo)r   r8   rE   r[  r9   rW   rb  s     r#   1test_child_log_has_level_of_parent_flag_for_tracezBLogLevelTestCase.test_child_log_has_level_of_parent_flag_for_trace  s2    /0FMM$C$C$EFr%   c                     t         j                  j                  t        j                  d<   t        j
                         }| j                  t        j                  |       y )Nsentinel_log)r   sentinelrg  r   _loggersget_loggersassertDictEqual)r<   ress     r#   test_get_loggersz!LogLevelTestCase.test_get_loggers  s:    '+}}'A'A^$ooS\\3/r%   )r   r   r   r-   r\  r^  r`  rc  re  rm  r   r   s   @r#   rK  rK    s+    4$@LOJG0r%   rK  c                   r     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Z xZS )JSONFormatterTestCasec                    t         t        |           t        j                  d      | _        | j                  | j                  t        j                         | j                  | j                  t        j                         y )N	test-json)r@   )r,   ro  r-   r   r8   r   r   JSONFormatterr   rU   rV   r;   s    r#   r-   zJSONFormatterTestCase.setUp  s\    #T02==-&&txx1;1I1I 	' 	K((7==Ar%   c                     d}ddi}t               }| j                  j                  ||d|       | j                  d|||       y )NThis is a %(test)s liner+   r   valuer?  r
   test_json_w_context_in_extrasr$   r   rR   _validate_json_datar<   test_msg	test_datar<  s       r#   rw  z3JSONFormatterTestCase.test_json_w_context_in_extras   sG    ,UO	%xO  !@(!*M	;r%   c                     d}ddi}t               }| j                  j                  ||d       | j                  d|||       y )Nrt  r+   r   ru  )r?  "test_json_w_fetched_global_contextrx  rz  s       r#   r~  z8JSONFormatterTestCase.test_json_w_fetched_global_context  sH    ,UO	%
 	x8  !E!)9m	Er%   c                 B   t        j                  | j                  j                               }| j	                  |       | j                  d|       | j                  d|       |d   }|d   }| j                  d|       | j                  d|d          | j                  |j                  |d          | j                  |j                  |d          | j                  |j                  |d          | j                  d|d	          | j                  d
|       | j                  |j                  |d
          | j                  d|       | j                  |j                  |d          | j                  ||z  |d          | j                  ||d          | j                  ||d          | j                  d|d          | j                  ||d          | j                  d|d          | j                  t        j                  |d          | j                  |d          y )Nextrar
   ru  r?  r  r   r   rq  r   
request_idglobal_request_idmessagemsgr=  test_log.pyfilenamefuncnamerV   	levelnamelevelno	traceback)r   loadsr   getvaluerD   r   assertNotInrE   r  r   r   r  r  rU   rV   rZ  )r<   testnamer{  r|  ctxdatar  r
   s           r#   ry  z)JSONFormatterTestCase._validate_json_data  s   t{{3356gt$i&Wy/E*%,/76?3(<=))7>+BCd6l3lG,)>?)73..8K0LMI-tI?4;/DL1Z(894
#34${"34Y8k*+r%   c                 b   d}d}	 t        d      # t         $ r | j                  j                  ||       Y nw xY wt        j                  | j
                  j                               }| j                  |       | j                  d|       | j                  d|d          | j                  ||z  |d          | j                  ||d          | j                  |g|d	          | j                  d
|d          | j                  t        j                  |d          | j                  |d          y )N
This is %sexceptionalThis is exceptionalr  rq  r   r  r  r=  rC  r  r  r  )rG  r   rb   r   r  r   r  rD   r   rE   rU   rC  r<   r{  r|  r  s       r#   test_json_exceptionz)JSONFormatterTestCase.test_json_exception1  s   !		4122 	4HHx3	4 t{{3356gt$d6l3I-tI?4;/)d6l3${"34Y8[)*    %99c                    d}ddi}ddd}| j                   j                  ||d|       t        j                  | j                  j                               }| j                  |       | j                  d	|       |j                         D ]2  \  }}| j                  ||d	          | j                  ||d	   |          4 y )
Nrt  r+   r   user1unicorns)special_userspecial_tenantru  )r?  r  r  )
r   rR   r   r  r   r  rD   r   r9  rE   )r<   r{  r|  
extra_datar  kvs          r#   test_json_with_extraz*JSONFormatterTestCase.test_json_with_extraF  s    ,UO	&-(24
xzJt{{3356gt$$$& 	2DAqMM!T']+QWa 01	2r%   c                    d}ddi}ddg}d}d}| j                   j                  ||d|||	       t        j                  | j                  j                               }| j                  |       | j                  d
|       | j                  |d   |d
          | j                  ||d
   |d             | j                  |d   |d
          | j                  ||d
   |d             y )Nrt  r+   r   r  r  r  user2ru  )r?  
extra_keysr  r  r  r   r   )	r   rR   r   r  r   r  rD   r   rE   )r<   r{  r|  r  r  r  r  s          r#   test_json_with_extra_keysz/JSONFormatterTestCase.test_json_with_extra_keysT  s    ,UO	&7
#x",^$0 	 	2 t{{3356gt$jmT']3gz!})EFjmT']3tG}Z]'CDr%   c                     d}d}| j                   j                  ddj                  d             | j                  || j                  j                                y )Ns   \u2622z\\xe2\\x98\\xa2   %s   ☢utf8r   rM   encoder   r   r  r<   r   s     r#   test_can_process_stringsz.JSONFormatterTestCase.test_can_process_stringsf  sB    *eX__V45h 4 4 67r%   c                 P   t               }t        d      |_        	 t        d      # t        $ r  | j                  j                  d|       Y nw xY wt        j                  | j                  j                               }| j                  d|       | j                  d|d          y )N99test_exceptionr  r	   error_summaryRuntimeError: test_exceptionr$   r7  r  rp   r   rc   r   r  r   r  r   rE   r<   r"   r  s      r#   r  z$JSONFormatterTestCase.test_exceptionm  s    d)	6/00 	6HHY5	6t{{3356ot,7o.	0   ' &AAc                    t               }t        d      |_        | j                  j	                  d|       t        j                  | j                  j                               }| j                  d|       | j                  d|d          y )Nr  r  r	   r   )r$   r7  r  r   rM   r   r  r   r  r   rE   r  s      r#   test_no_exceptionz'JSONFormatterTestCase.test_no_exceptiony  sf    d)i.t{{3356ot,T/23r%   c                 P   t               }t        d      |_        	 t        d      # t        $ r  | j                  j                  d|       Y nw xY wt        j                  | j                  j                               }| j                  d|       | j                  d|d          y )Nr  *test_exception
traceback
from
remote errorr  r	   r  r  r  r  s      r#   &test_exception_without_exc_info_passedz<JSONFormatterTestCase.test_exception_without_exc_info_passed  s    d)	6NOO 	6HHY5	6t{{3356ot,7o9NOr  c                 P   t               }t        d      |_        	 t        d      # t        $ r  | j                  j                  d|       Y nw xY wt        j                  | j                  j                               }| j                  d|       | j                  d|d          y )Nr  r  r  r	   r  z8RuntimeError: test_exception
traceback
from
remote error)r$   r7  r  rp   r   rb   r   r  r   r  r   rE   r  s      r#   #test_exception_with_exc_info_passedz9JSONFormatterTestCase.test_exception_with_exc_info_passed  s    d)	8NOO 	8HHy$7	8t{{3356ot, ;o.	0r  c                     G d dt               } |       }| j                  j                  d|       t        j                  | j
                  j                               }| j                  d|d          | j                  dg|d          y )Nc                       e Zd Zd Zd Zy)5JSONFormatterTestCase.test_fallback.<locals>.MyObjectc                      y)Nr7  r   rN   s    r#   __str__z=JSONFormatterTestCase.test_fallback.<locals>.MyObject.__str__  s    r%   c                      y)Nreprr   rN   s    r#   __repr__z>JSONFormatterTestCase.test_fallback.<locals>.MyObject.__repr__  s    r%   N)r   r   r   r  r  r   r%   r#   MyObjectr    s    r%   r  zobj=%szobj=strr  r  r=  )objectr   rR   r   r  r   r  rE   )r<   r  objr  s       r#   test_fallbackz#JSONFormatterTestCase.test_fallback  sp    	v 	 jx%t{{3356DO4 	&4<0r%   c                     d}ddd}| j                   j                  ||       t        j                  | j                  j                               }| j                  d|d          y )Nz"This is a %(test)s line %%(unused)r   removeme)r+   unusedr  r=  )r   rR   r   r  r   r  r  r  s       r#   test_extra_args_filteredz.JSONFormatterTestCase.test_extra_args_filtered  sR    7"j9	x+t{{33564<0r%   c                     d}ddd}| j                   j                  ||       t        j                  | j                  j                               }| j                  ||d          y )NzThis is a %s dictr   ru  )r+   r   r=  )r   rR   r   r  r   r  rE   r  s       r#   test_entire_dictz&JSONFormatterTestCase.test_entire_dict  sR    &"W5	x+t{{3356DL1r%   )r   r   r   r-   rw  r~  ry  r  r  r  r  r  r  r  r  r  r  r  r   r   s   @r#   ro  ro    sR    B;
E,:+*2E$8
04	P01$12r%   ro  c                 >      G  fddt         j                         }|S )Nc                   "    e Zd Ze fd       Zy)'get_fake_datetime.<locals>.FakeDateTimec                     S r?   r   )cls	timestampretvals     r#   fromtimestampz5get_fake_datetime.<locals>.FakeDateTime.fromtimestamp  s    Mr%   N)r   r   r   classmethodr  )r  s   r#   FakeDateTimer    s    		 
	r%   r  )datetime)r  r  s   ` r#   get_fake_datetimer    s    x(( 
 r%   c                       e Zd ZdZd Zy)DictStreamHandlerzjSerialize dict in order to avoid TypeError in python 3. It is needed for
    FluentFormatterTestCase.
    c                     	 | j                  |      }t        j                  || j                         | j                  j	                          y # t
        $ r | j                  |       Y y w xY wr?   )r   r   dumpr   flushrf   handleError)r<   recordr  s      r#   r   zDictStreamHandler.emit  sT    	%++f%CNN3,KK 	%V$	%s   AA A+*A+N)r   r   r   r   r   r   r%   r#   r  r    s    %r%   r  c                   6     e Zd Z fdZd Zd Zd Zd Z xZS )FluentFormatterTestCasec                    t         t        |           t        j                  d      | _        | j                  | j                  t        t        j                         | j                  | j                  t        j                         y )Ntest-fluent)r   r@   )r,   r  r-   r   r8   r   r  r   FluentFormatterr   rU   rV   r;   s    r#   r-   zFluentFormatterTestCase.setUp  sa    %t24==/&&txx/@1;1K1K 	' 	M 	((7==Ar%   c                 D   d}ddi}t               }| j                  j                  ||d|       t        j                  | j
                  j                               }| j                  d|       | j                  d|       |d   }|d   }| j                  d|d	          | j                  |j                  |d
          | j                  d|d          | j                  d|       | j                  |j                  |d          | j                  d|       | j                  |j                  |d          | j                  ||z  |d          | j                  d|d          | j                  d|d          | j                  d|d          | j                  |d          y )Nrt  r+   r   ru  rv  linenor  r
   r?  r  r  r   r  r  r  r  r  test_fluentr  rV   r   r  )r$   r   rR   r   r  r   r  r   rE   r  r  r  rZ  )r<   r{  r|  r<  r  r  r
   s          r#   r  z#FluentFormatterTestCase.test_fluent  s}   ,UO	%xOt{{3356h%gt$Wy/%,/++WV_=V5lG,117<3HI)7388 !45	7 	I-tI?Z(89Z(89$w-0k*+r%   c                 0   t               }	 t        d      # t        $ r  | j                  j                  d|       Y nw xY wt	        j
                  | j                  j                               }| j                  d|       | j                  d|d          y )Nr  r  r	   r  r  )
r$   rp   r   rc   r   r  r   r  r   rE   r<   r<  r  s      r#   r  z&FluentFormatterTestCase.test_exception  s    %	?/00 	?HHY>	?t{{3356ot,7o.	0s    &A A c                     t               }| j                  j                  d|       t        j                  | j
                  j                               }| j                  d|       | j                  d|d          y )Nr  r	   r  r  )	r$   r   rM   r   r  r   r  r   rE   r  s      r#   r  z)FluentFormatterTestCase.test_no_exception  s[    %i7t{{3356ot,T/23r%   c                    d}d}	 t        d      # t         $ r | j                  j                  ||       Y nw xY wt        j                  | j
                  j                               }| j                  |       | j                  d|       | j                  d|d          | j                  ||z  |d          | j                  d|d	          | j                  |d
          y )Nr  r  r  r  r  r   r  rC  r   r  )
rG  r   rb   r   r  r   r  rD   r   rE   r  s       r#   r  z+FluentFormatterTestCase.test_json_exception
  s    !		4122 	4HHx3	4 t{{3356gt$V5I-tI?$w-0[)*r  )	r   r   r   r-   r  r  r  r  r   r   s   @r#   r  r    s    B,:	04+r%   r  c                       e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Z ej*                  d e ej.                  ddddddd                   ej*                  d ej0                   ej4                                     d               Z ej*                  d e ej.                  dddddd                   ej*                  d ej0                  d             ej*                  d ej0                   ej4                                     d                       Zd! Zd" Z xZS )#ContextFormatterTestCasec                 `   t         t        |           | j                  ddd       t	        j
                  d      | _        | j                  | j                         | j                  | j                  t        j                         | j                  t        j                               | _        y )Nz)HAS CONTEXT [%(request_id)s]: %(message)szNOCTXT: %(message)sz--DBG)r*   logging_default_format_stringlogging_debug_format_suffixr  )r,   r  r-   r3   r   r8   r   r   rU   rV   r.   fixture_transTranslationtrans_fixturer;   s    r#   r-   zContextFormatterTestCase.setUp  s    &35 3@ 3H07	 	 	9
 ==$&&txx0((7==A!__]-F-F-HIr%   c                     d}| j                   j                  |       | j                  d|z  | j                  j	                                y )NrL   zNOCTXT: %s
)r   rM   rE   r   r  r<   r  s     r#   test_uncontextualized_logz2ContextFormatterTestCase.test_uncontextualized_log*  s9    g'14;;3G3G3IJr%   c                     t               }d}| j                  j                  ||       d|j                  d|d}| j	                  || j
                  j                                y )Nbarr	   HAS CONTEXT []: 
r$   r   rM   r  rE   r   r  r<   r"   r  r   s       r#   test_contextualized_logz0ContextFormatterTestCase.test_contextualized_log/  sM    gt,/3H4;;#7#7#9:r%   c                     t               }d}| j                  j                  |       d|j                  d|d}| j	                  || j
                  j                                y )Nr  r  r  r  r  r  s       r#   'test_context_is_taken_from_tls_variablez@ContextFormatterTestCase.test_context_is_taken_from_tls_variable6  sI    g/3H4;;#7#7#9:r%   c                     t               }t        j                  d      }|j                  t        j                         d}|j                  |       d|j                  d|d}| j                  || j                  j                                y )Nsqlalchemy.enginez!emulate logging within sqlalchemyr  r  r  )
r$   rU   r8   r   r]   rM   r  rE   r   r  r<   r"   sa_logr  r   s        r#   @test_contextual_information_is_imparted_to_3rd_party_log_recordszYContextFormatterTestCase.test_contextual_information_is_imparted_to_3rd_party_log_records=  sf    ""#67%5G04I4;;#7#7#9:r%   c                    t               }t        d      |_        t        j                  d      }|j                  t        j                         | j                  j                  dt        d      z         }|j                  |       d|j                  dt        |      d}| j                  || j                  j                                y )Nr  r  test    r  r  r  )r$   r7  r  rU   r8   r   r]   r  lazychrrM   rE   r   r  r  s        r#   *test_message_logging_3rd_party_log_recordszCContextFormatterTestCase.test_message_logging_3rd_party_log_recordsG  s    d)""#67%$$))'CH*<=G0403G>4;;#7#7#9:r%   c                     d}| j                   j                  |       | j                  d|z  | j                  j	                                y )NbazzNOCTXT: %s --DBG
)r   rR   rE   r   r  r  s     r#   test_debugging_logz+ContextFormatterTestCase.test_debugging_logS  s=    w-7--/	1r%   c                 L   t               }t        d      |_        | j                  j	                  dt        d      z         }| j                  j                  ||       d|j                  dt        |      d}| j                  || j                  j                                y )Nr  r	  r
  r	   r  r  r  )r$   r7  r  r  r  r  r   rM   rE   r   r  r  s       r#   test_message_loggingz-ContextFormatterTestCase.test_message_loggingY  s{    
 d)$$))'CH*<=gt,/3/27|=4;;#7#7#9:r%   c                 j   t               }t        d      |_        | j                  j	                  dt        d      z         }	 t        d      # t        $ r  | j                  j                  ||       Y nw xY wd}| j                  | j                  j                         j                  |             y )Nr  r	  r
  test_exception_loggingr	   z%RuntimeError: test_exception_logging
)r$   r7  r  r  r  r  rp   r   rc   rD   r   r  endswithr  s       r#   r  z/ContextFormatterTestCase.test_exception_loggingf  s     d)$$))'CH*<=	4788 	4HHWd3	4;,,.77ABs   A &A76A7c                    t               }t        d      |_        | j                  j	                  dt        d      z         }t        t        t        t        t        g}|D ]
  }	  |d       y # |$ rM}| j                  j                  ||       dj                  |j                  j                  |      }Y d }~nd }~ww xY w| j!                  || j"                  j%                                )Nr  r	  r
  r  r	   z{}: {})r$   r7  r  r  r  r  
ValueErrorr  KeyErrorrf   ImportErrorr   rc   r   r=   r   r  r   r  )r<   r"   r  ignored_exceptionsignoreer   s          r#   $test_skip_logging_builtin_exceptionsz=ContextFormatterTestCase.test_skip_logging_builtin_exceptionst  s     d)$$))'CH*<=	8^[
 ) 	?FD566	?  D  $ 7#??1;;+?+?CD Xt{{';';'=>s   #A--B?2AB::B?c                    | j                  d       t               }t        d      |_        | j                  j                  dt        d      z         }	 t        d      # t        $ r  | j                  j                  ||       Y nw xY wd}| j                  | j                  j                         j                  |             y )	NzA %(error_summary)s Br)   r  r	  r
  r  r	   z&A RuntimeError: test_exception_logging)r3   r$   r7  r  r  r  r  rp   r   rc   rD   r   r  
startswithr  s       r#   $test_exception_logging_format_stringz=ContextFormatterTestCase.test_exception_logging_format_string  s     	2IJd)$$))'CH*<=	4788 	4HHWd3	4;,,.99(CDs   A   &B	B	c                 X   | j                  d       t               }t        d      |_        | j                  j                  dt        d      z         }| j                  j                  ||       d}| j                  | j                  j                         j                  |             y )Nz%(error_summary)sr)   r  r	  r
  r	   z-
)r3   r$   r7  r  r  r  r  r   rM   rD   r   r  r  r  s       r#   'test_no_exception_logging_format_stringz@ContextFormatterTestCase.test_no_exception_logging_format_string  s     	2EFd)$$))'CH*<=gt,,,.99(CDr%   c                 n   t               }t        d      |_        d}t        | j                  j                  dt        d      z               }| j                  j                  |||       t        |      |z  }d|j                  d|d}| j                  || j                  j                                y )	Nr  Exception is (%s)r+   r
  r	   r  r  z --DBG
)r$   r7  r  rG  r  r  r  r   rR   rE   r   r  )r<   r"   r  exr   s        r#   "test_unicode_conversion_in_adapterz;ContextFormatterTestCase.test_unicode_conversion_in_adapter  s    d)%t))..vC/@ABwD1g,#59__5<>4;;#7#7#9:r%   c                    t               }t        d      |_        t        j                  d      }|j                  t        j                         d}t        | j                  j                  dt        d      z               }|j                  ||       t        |      |z  }d|j                  d|d}| j                  || j                  j                                y )	Nr  no_adaptr$  r+   r
  r  r  r  )r$   r7  r  rU   r8   r   r]   rG  r  r  r  rM   rE   r   r  )r<   r"   no_adapt_logr  r%  r   s         r#   $test_unicode_conversion_in_formatterz=ContextFormatterTestCase.test_unicode_conversion_in_formatter  s    d)((4gll+%t))..vC/@AB'2&g,#/3/684;;#7#7#9:r%   c                    | j                  d       t               }d|_        d}| j                  j	                  ||       d|j                  d|j
                  d|j                  d|j                  d|j                  d|j                  d|j                  dt        |      d	}| j                  || j                  j                                y )
N;HAS CONTEXT [%(request_id)s %(user_identity)s]: %(message)sr)   r  r+   r	   r   r  r  )r3   r$   r  r   rM   r  r   r   r   user_domainproject_domainr7  rE   r   r  r  s       r#   test_user_identity_loggingz3ContextFormatterTestCase.test_user_identity_logging  s     3@ 	A gt,__dii$++&&(8(8$:M:M\# 	4;;#7#7#9:r%   c                 2   d}| j                  |       t               }d|_        d}| j                  j	                  ||       d|j                  d|j
                  dt        |      d	}| j                  || j                  j                                y )
Nz?HAS CONTEXT [%(request_id)s %(global_request_id)s]: %(message)sr)   r  r+   r	   r  r-  r  r  )
r3   r$   r  r   rM   r  r7  rE   r   r  )r<   fmt_strr"   r  r   s        r#   test_global_request_id_loggingz7ContextFormatterTestCase.test_global_request_id_logging  sx     ':gt,__d&<&<c'lL4;;#7#7#9:r%   c           
      J   | j                  dd       t               }d|_        d}| j                  j	                  ||       d|j                  d|j
                  d|j                  d	t        |      d
	}| j                  || j                  j                                y )Nr,  z%(user)s %(project)sr*   logging_user_identity_formatr  r+   r	   r  r-  r  r  )r3   r$   r  r   rM   r  r   r7  rE   r   r  r  s       r#   %test_user_identity_logging_set_formatz>ContextFormatterTestCase.test_user_identity_logging_set_format  s     3@2?	 	 	@ gt,__dii\# 	4;;#7#7#9:r%   datetime.datetime           6       dateutil.tz.tzlocalrk   newc                     | j                  d       d}d|z  }| j                  j                  |       | j                  || j                  j                                y )N%(isotime)s %(message)sr  r+   z$2015-12-16T13:54:26.517893+00:00 %s
r3   r   rM   rE   r   r  r<   r  r   s      r#   test_rfc5424_isotime_formatz4ContextFormatterTestCase.test_rfc5424_isotime_format  sO    
 	2KL:WDg4;;#7#7#9:r%   z	time.timeg  D[Ac                     | j                  d       d}d|z  }| j                  j                  |       | j                  || j                  j                                y )NrD  rE  r+   z$2015-12-16T13:54:26.000000+00:00 %s
rF  rG  s      r#   +test_rfc5424_isotime_format_no_microsecondszDContextFormatterTestCase.test_rfc5424_isotime_format_no_microseconds  sO     	2KL:WDg4;;#7#7#9:r%   c                     d}d}| j                   j                  ddj                  d             | j                  || j                  j                                y )Ns   ☢z\xe2\x98\xa2r  r  r  r  r  s     r#   r  z1ContextFormatterTestCase.test_can_process_strings   sD    " %eX__V45h 4 4 67r%   c                     d}ddi}| j                   j                  ||       | j                  |d   | j                  j	                                y )Nz	%(thing)sthingu   ÆÆ¡Æ¡r   rM   r   r   r  )r<   r  r@  s      r#   test_dict_args_with_unicodez4ContextFormatterTestCase.test_dict_args_with_unicode	  sC    23c3c'lDKK$8$8$:;r%   ) r   r   r   r-   r  r   r  r  r  r  r  r  r  r   r"  r&  r*  r0  r3  r7  r   r   r  r  r   r   tzutcrH  rJ  r  rO  r   r   s   @r#   r  r    sq   
JK
;;;
;1;C?"E
E	;;;
;;  TZZ#!%H%%dBBBGIJ TZZ%9499("((*+MN; OJ; TZZ#!%H%%dBBB?AB TZZ8I!JKTZZ%9499("((*+MN; O LB
;8<r%   r  c                       e Zd ZdZd Zd Z ej                  d e e	j                  ddddd	d
d                   ej                  d ej                   ej                                     d               Zy)ExceptionLoggingTestCasez Test that Exceptions are logged.c                 >   d}t        j                  |      }| j                  |       t        j                  |      }	 t	        d      # t        $ r  |t        j                           Y nw xY wd}| j                  || j                  j                         d       y )NsomenameSome error happenedzECRITICAL somename [-] Unhandled error: Exception: Some error happenedzException is not logged)r  )
r   r8   r   _create_logging_excepthookrG  sysexc_infor   r   r  )r<   product_nameexc_log
excepthookexpected_strings        r#   test_excepthook_logs_exceptionz7ExceptionLoggingTestCase.test_excepthook_logs_exception  s    !---&&w/33LA
	(122 	('	(<ot{{';';'=7 	 	9s   A
 
 A-,A-c                     t        j                  | j                  d       | j                  t        j
                  t        j                  k7         y )Ntest_excepthook_installed)r   rT   r5   rD   rW  r[  __excepthook__rN   s    r#   r_  z2ExceptionLoggingTestCase.test_excepthook_installed$  s0    		$))89#*<*<<=r%   r8  r9  r:  r;  r<  r=  r>  r?  r@  rk   rA  c                 j   | j                  dd       d}t        j                  |      }| j                  |       t        j                  |      }d}	 t        |      # t
        $ r  |t        j                           Y nw xY wd|z  }| j                  || j                  j                                y )NrD  z%(isotime)s )r  logging_exception_prefixrT  rU  z.2015-12-16T13:54:26.517893+00:00 Exception: %s)r3   r   r8   r   rV  rG  rW  rX  r   r   r  )r<   rY  rZ  r[  r  r\  s         r#   rH  z4ExceptionLoggingTestCase.test_rfc5424_isotime_format(  s    
 	*C%3 	 	

 "---&&w/33LA
'	(G$$ 	('	(+-45okk**,	.s   A  BBN)r   r   r   r   r]  r_  r   r   r  r  r   r   rP  rH  r   r%   r#   rR  rR    s    *9"> TZZ#!%H%%dBBBGIJ TZZ%9499("((*+MN. OJ.r%   rR  c                   F     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
 xZS )	FancyRecordTestCasezVTest how we handle fancy record keys that are not in the
    base python logging.
    c                 *   t         t        |           | j                  dd       t	        j
                         | _        | j                  | j                  t        j                         | j                  | j                  t        j                         y )Nz?%(color)s [%(request_id)s]: %(instance)s%(resource)s%(message)sz%(missing)s: %(message)sr*   r  )r,   rd  r-   r3   r   r8   colorlogr   r   ColorHandlerr   rU   rV   r;   s    r#   r-   zFancyRecordTestCase.setUpI  sr    !4.0 	 3@
 3M 	 	N &&t}}h6K6KL((Fr%   c                 $   t         j                  }t        j                         t         _        | j                  j                  d       | j                  dt         j                  j                         j                  d             |t         _        y )NrL   zKeyError: 'missing')	rW  stderrr   r   rg  rM   assertNotEqualr  find)r<   ra   s     r#   test_unsupported_key_in_log_msgz3FancyRecordTestCase.test_unsupported_key_in_log_msgX  sb     

[[]
5!BJJ//1667LM	O 
r%   c                    t         j                  j                  t        j                     }t         j                  j                  t        j
                     }d}d}|d|d|}|d|d|}| j                  j                  ||       | j                  || j                  j                                | j                  d|       | j                  j                  ||       | j                  || j                  j                                | j                  || j                  j                                | j                  d|       y )NrM   rd   r-  r	   z[00;36mz[01;33m)r   rh  LEVEL_COLORSrU   r]   WARNrg  rM   r   r   r  rE   rd   )	r<   r"   keyed_log_string	infocolor	warncolorinfo_msgwarn_msginfoexpectedwarnexpecteds	            r#   _validate_keysz"FancyRecordTestCase._validate_keyse  s    ))66w||D	))66w||D	%.0@(K%.0@(K8T2lDKK$8$8$:;	28T2lDKK$8$8$:;lDKK$8$8$:;	2r%   c                 V    t               }| j                  |d|j                  z         y )Nz[%s]:)r$   ry  r  r<   r"   s     r#   test_fancy_key_in_log_msgz-FancyRecordTestCase.test_fancy_key_in_log_msgv  s"    D'DOO";<r%   c                     t               }d|_        | j                  |d|j                  d|j                  d       y )N1234[z]: [instance: ])r$   resource_uuidry  r  r{  s     r#   test_instance_key_in_log_msgz0FancyRecordTestCase.test_instance_key_in_log_msgz  s7    #D$(OOT5G5G$I 	Kr%   c                 >   t         j                  j                  t        j                     }t               }d}d|i}d}| j                  j                  |||       |d|j                  d|d|d}| j                  || j                  j                                y )	Nz-resource-202260f9-1224-490d-afaf-6a744c13141fr   rM   r
   resource []: [] [00m
r   rh  rp  rU   r]   r$   rg  rM   r  rE   r   r  )r<   colorr"   r  fake_resourcer  r   s          r#   test_resource_key_in_log_msgz0FancyRecordTestCase.test_resource_key_in_log_msg  s    %%227<<@B*7D=IDOOXw@4;;#7#7#9:r%   c           
      J   t         j                  j                  t        j                     }t               }d}d}||d}d}| j                  j                  |||       |d|j                  d|d|d	|d

}| j                  || j                  j                                y )Nr  z$202260f9-1224-490d-afaf-6a744c13141f)typeidrM   r  r  r  -r  r  r  )r<   r  r"   r  resource_idr  r  r   s           r#   !test_resource_key_dict_in_log_msgz5FancyRecordTestCase.test_resource_key_dict_in_log_msg  s    %%227<<@<!%*,7D=IDOOT;I4;;#7#7#9:r%   )r   r   r   r   r-   rn  ry  r|  r  r  r  r   r   s   @r#   rd  rd  D  s-    G3"=K	;;r%   rd  c                   H     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
 xZS )	InstanceRecordTestCasec                    t         t        |           | j                  dd       t	        j
                         | _        | j                  | j                         | j                  | j                  t        j                         y )Nz5[%(request_id)s]: %(instance)s%(resource)s%(message)sz#%(instance)s%(resource)s%(message)srf  )
r,   r  r-   r3   r   r8   r   r   rU   rV   r;   s    r#   r-   zInstanceRecordTestCase.setUp  sh    $d13 3@3@	 	 	A ==?&&txx0((7==Ar%   c                     t               }d}d|i}d}| j                  j                  |||       d|z  }| j                  || j                  j                                y )N$C9B7CCC6-8A12-4C53-A736-D7A1C36A62F3uuidrM   )r
   instance[instance: %s]r$   r   rM   r   r   r  )r<   r"   r  r  r  r   s         r#   %test_instance_dict_in_context_log_msgz<InstanceRecordTestCase.test_instance_dict_in_context_log_msg  sW    5gtmD#d*h 4 4 67r%   c                     d}d|i}d}| j                   j                  ||       d|z  }| j                  || j                  j	                                y )Nr  r  rM   )r  r  rN  )r<   r  r  r  r   s        r#   %test_instance_dict_in_default_log_msgz<InstanceRecordTestCase.test_instance_dict_in_default_log_msg  sN    5g6#d*h 4 4 67r%   c                     t               }d}d}| j                  j                  |||       d|z  }| j                  || j                  j                                y )Nr  rM   )r
   instance_uuidr  r  )r<   r"   r  r  r   s        r#   ,test_instance_uuid_as_arg_in_context_log_msgzCInstanceRecordTestCase.test_instance_uuid_as_arg_in_context_log_msg  sN    5gt4@#d*h 4 4 67r%   c                     d}d}| j                   j                  ||       d|z  }| j                  || j                  j	                                y )Nr  rM   )r  r  rN  )r<   r  r  r   s       r#   ,test_instance_uuid_as_arg_in_default_log_msgzCInstanceRecordTestCase.test_instance_uuid_as_arg_in_default_log_msg  sE    5gT2#d*h 4 4 67r%   c                     t               }d|_        d}| j                  j                  ||       d|j                  z  }| j	                  || j
                  j                                y )Nz$CCCCCCCC-8A12-4C53-A736-D7A1C36A62F3rM   r	   r  )r$   r  r   rM   r   r   r  r  s       r#   2test_instance_uuid_from_context_in_context_log_msgzIInstanceRecordTestCase.test_instance_uuid_from_context_in_context_log_msg  U    Cgt,#d&8&88h 4 4 67r%   c                     t               }d|_        d}| j                  j                  ||       d|j                  z  }| j	                  || j
                  j                                y )Nz$RRRRRRRR-8A12-4C53-A736-D7A1C36A62F3rM   r	   r  )r$   r  r   rM   r   r   r  r  s       r#   2test_resource_uuid_from_context_in_context_log_msgzIInstanceRecordTestCase.test_resource_uuid_from_context_in_context_log_msg  r  r%   c                     t               }d|_        d}| j                  j                  ||       d|j                  z  }| j	                  || j
                  j                                y )Nz$IIIIIIII-8A12-4C53-A736-D7A1C36A62F3rM   r	   r  )r$   r  r   rM   r   r   r  r  s       r#   -test_instance_from_context_in_context_log_msgzDInstanceRecordTestCase.test_instance_from_context_in_context_log_msg  sT     >gt,#dmm3h 4 4 67r%   )r   r   r   r-   r  r  r  r  r  r  r  r   r   s   @r#   r  r    s,    B8888888r%   r  c                   $     e Zd Z fdZd Z xZS )TraceLevelTestCasec                 
   t         t        |           | j                  d       t	        j
                         | _        | j                  | j                         | j                  | j                  t        j                         y )Nz%(message)sr)   )
r,   r  r-   r3   r   r8   r   r   r   r[  r;   s    r#   r-   zTraceLevelTestCase.setUp  sV     $-/-@]]_
&&tzz2((SYY?r%   c                     t               }d}| j                  j                  ||       | j                  d|z  | j                  j                                y )Nzmy trace messager	   z%s
)r$   r   tracerE   r   r  )r<   r"   r  s      r#   test_trace_log_msgz%TraceLevelTestCase.test_trace_log_msg  sG    $

$/')4;;+?+?+ABr%   )r   r   r   r-   r  r   r   s   @r#   r  r    s    @Cr%   r  c                   *     e Zd Z fdZd Zd Z xZS )DomainTestCasec                    t         t        |           | j                  dd       t	        j
                         | _        | j                  | j                         | j                  | j                  t        j                         y )Nz/[%(request_id)s]: %(user_identity)s %(message)szB%(user)s %(project)s %(user_domain)s %(project_domain)s %(domain)sr5  )r,   r  r-   r3   r   r8   r   r   r   rU   rV   r;   s    r#   r-   zDomainTestCase.setUp  se    nd)+ 3@2> 	 	? ]]_
&&tzz2((W]]Cr%   c                 N   d}|d|d}d}|d|d}| j                   j                  ||       | j                  || j                  j	                                | j                   j                  ||       | j                  ||z   | j                  j	                                y )NrM   r-  r  rd   r	   )r   rM   rE   r   r  rd   )r<   r"   rr  info_messagerw  warn_messagerx  s          r#   ry  zDomainTestCase._validate_keys  s    $4lC$4lC

d3t{{';';'=>

d34dkk6J6J6LMr%   c                 R   t               }| j                  j                  |j                         z  }| j	                  |j
                  |       | j	                  |j                  |       | j	                  |j                  |       | j                  |d|j                  d|       y )Nr  r  )
r$   r5   r6  get_logging_valuesr   r   r/  r.  ry  r  )r<   r"   user_identitys      r#   test_domain_in_log_msgz%DomainTestCase.test_domain_in_log_msg  s    ??0023dkk=1d))=9d&&6D$(OO]$D 	Fr%   )r   r   r   r-   ry  r  r   r   s   @r#   r  r    s    D
NFr%   r  c                   r     e Zd Z G d dej                        Z fdZd Zd Zd Z	d Z
d Zd	 Zd
 Z xZS )SetDefaultsTestCasec                       e Zd ZddZy)"SetDefaultsTestCase.TestConfigOptsNc                 L    t         j                  j                  | |dddg       S )Nr+   z1.0z%(prog)s FOO BAR)r=  progversionusagedefault_config_files)r   r1   __call__)r<   r=  s     r#   r  z+SetDefaultsTestCase.TestConfigOpts.__call__  s1    >>**40406381C@B + D Dr%   r?   )r   r   r   r  r   r%   r#   TestConfigOptsr    s    	Dr%   r  c                    t         t        |           | j                         | _        | j                  j                  t        j                         | j                  j                  t        j                         t        t        j                  D cg c]  }|j                  |j                  f c}      | _        | j                  | j                         y c c}w r?   )r,   r  r-   r  r4   register_optsr   log_optsregister_cli_optslogging_cli_optsdictdestdefault_orig_defaultsr   _restore_log_defaults)r<   or=   s     r#   r-   zSetDefaultsTestCase.setUp   s    !4.0'')			 1 12		##H$=$=>"-5->->$@() &'VVQYY$7 $@ A223$@s   Cc                 j    t         j                  D ]   }| j                  |j                     |_        " y r?   )r   r  r  r  r  )r<   opts     r#   r  z)SetDefaultsTestCase._restore_log_defaults*  s-    $$ 	8C--chh7CK	8r%   c                     t        j                  d d        | j                  g        | j                  t        j
                  | j                  j                         y )N)r*   rN  )r   set_defaultsr4   rE   r   DEFAULT_LOG_LEVELSrN  rN   s    r#   test_default_log_level_to_nonez2SetDefaultsTestCase.test_default_log_level_to_none.  sC    t,0	2		"4455	7r%   c                 h    | j                  t        j                  t        j                                y r?   )rE   r   r  r   get_default_log_levelsrN   s    r#   test_default_log_level_methodz1SetDefaultsTestCase.test_default_log_level_method5  s$    44335	7r%   c                     d}t        j                  |       | j                  g        | j                  | j                  j                  |       y )Nzc%(asctime)s %(levelname)s %(name)s [%(request_id)s %(user_id)s %(project)s] %(instance)s%(message)sr)   )r   r  r4   rE   r*   )r<   
my_defaults     r#   test_change_defaultz'SetDefaultsTestCase.test_change_default9  s>    #
 	zB		"@@*Mr%   c                     d}t        j                  |g       | j                  g        | j                  |g| j                  j                         | j                  | j                  j                         y )Nzfoo=barrM  )r   r  r4   rE   rN  assertIsNotNoner*   )r<   package_log_levels     r#   test_change_default_log_levelz1SetDefaultsTestCase.test_change_default_log_levelA  s[    %->,?@		"+,dii.J.JKTYYDDEr%   c                    d}t        j                  |       | j                  t         j                  d        t        j                          | j	                  g        | j                  || j                  j                         y )Nzfoo.log)r   tempest_set_log_filer   r  r4   rE   r   r<   r   s     r#   test_tempest_set_log_filez-SetDefaultsTestCase.test_tempest_set_log_fileH  sZ      *00$7		"499#5#56r%   c                     t        j                          | j                  g        | j                  | j                  j                         y r?   )r   r  r4   r   r   rN   s    r#   test_log_file_defaults_to_nonez2SetDefaultsTestCase.test_log_file_defaults_to_noneP  s1    		"$)),,-r%   )r   r   r   r   r1   r  r-   r  r  r  r  r  r  r  r   r   s   @r#   r  r    s?    D D4877NF7.r%   r  rj   z/pyinotify library works on Linux platform only.c                   <     e Zd Z fdZd Zd Zd Zd Zd Z xZ	S )FastWatchedFileHandlerTestCasec                 *    t         t        |           y r?   )r,   r  r-   r;   s    r#   r-   z$FastWatchedFileHandlerTestCase.setUpZ  s    ,d9;r%   c                 d   t        j                         \  }}t        j                  j	                  |      }t        j                  j                  |      }| j                  d|d|g       | j                  d       | j                  d       t        j                  | j                  dd       |S )N	--log-dir
--log-fileF)
use_stderrTr~   r+   )
tempfilemkstempr   r   dirnamebasenamer5   r3   r   rT   )r<   os_levellog_pathlog_dir_pathlog_file_paths        r#   _configz&FastWatchedFileHandlerTestCase._config]  s    %--/(wwx0((2		;lMJKu%4(		$))VV,r%   c                    | j                          t        j                  d    j                  }| j	                  dt        |j                               ddlm} | j                  |j                  d   |j                         y )Nr   r   )watchers)r  r   ri  r9   rE   rF   r   oslo_logr  r6  FastWatchedFileHandler)r<   r9   r  s      r#   test_instantiatez/FastWatchedFileHandlerTestCase.test_instantiateg  s]    d#**C01%fooa0&==	?r%   c                 
   | j                         }t        j                  d    j                  }d}|j	                  |       t        |d      5 }|j                         }d d d        | j                  |       y # 1 sw Y   xY w)NzHello World!r)r  r   ri  r9   rM   openreadr   )r<   r  r9   textrI   file_contents         r#   test_logz'FastWatchedFileHandlerTestCase.test_logo  sl    <<>d#**D(C  	$A668L	$dL)	$ 	$s   A99Bc                    | j                         }t        j                         \  }}t        j                  ||       t        j                  d       | j                  t        j                  j                  |             y Nr"  )
r  r  r  r   renametimesleeprD   r   exists)r<   r  os_level_dstlog_path_dsts       r#   	test_movez(FastWatchedFileHandlerTestCase.test_movex  sR    <<>%-%5%5%7"l
		(L)

1x01r%   c                     | j                         }t        j                  |       t        j                  d       | j                  t        j                  j                  |             y r  )r  r   remover  r  rD   r   r	  )r<   r  s     r#   test_removez*FastWatchedFileHandlerTestCase.test_remove  s=    <<>
		(

1x01r%   )
r   r   r   r-   r  r  r  r  r  r   r   s   @r#   r  r  V  s!    <?*22r%   r  c                       e Zd Z fdZd Zd Zej                  j                  e	j                  d      d        Zej                  j                  e	j                  d      d        Zej                  j                  e	j                  d      d        Zd Zd	 Zd
 Zed        Zej                  j                  e	j                  d      d        Zd Zd Zd Z xZS )MutateTestCasec                     t         t        |           t        t        j
                  d      rt        j
                  `y y )Nold_time)r,   r  r-   hasattrr   _load_log_configr  r;   s    r#   r-   zMutateTestCase.setUp  s1    nd)+3''4$$- 5r%   c                 t    | j                  d t        |      D              }| j                  d|d   g       |S )Nc              3   0   K   | ]  \  }}d |z  |f  yw)zconf_%dNr   ).0ir4   s      r#   	<genexpr>z-MutateTestCase.setup_confs.<locals>.<genexpr>  s$      &C&-aY]D!&Cs   z--config-filer   )create_tempfiles	enumerater5   )r<   confspathss      r#   setup_confszMutateTestCase.setup_confs  sA    %% &C1:51A&C C		?E!H-.r%   c                 d   | j                  dd      }t        j                  d       j                  }t        j                  | j
                  dd       | j                  d| j
                  j                         | j                  t        j                  |j                                t        j                  |d   |d          | j
                  j                          | j                  d| j
                  j                         | j                  t        j                  |j                                y )Nz[DEFAULT]
debug = false
z[DEFAULT]
debug = true
r+   Fr   r   T)r  r   r8   r9   r7   r5   rE   rR   r]   rW   shutilcopymutate_config_filesrV   )r<   r  log_roots      r#   
test_debugzMutateTestCase.test_debug  s      (') ==&--$$TYY?		08#=#=#?@E!HeAh'		%%'tyy/H$>$>$@Ar%   
fileConfigc                    | j                  dt        fg      d   }| j                  dd|z        }| j                  t        j
                  t        j                  | j                  d       | j                  |j                         t        j                  |d   |d          | j                  j                          |j                  |d       y )	Nlog.inir   z'[DEFAULT]
log_config_append = no_exist
![DEFAULT]
log_config_append = %s
r  r   Fdisable_existing_loggers)r  MIN_LOG_INIr  re   r   LogConfigErrorrT   r5   rZ  r   r!  r"  r#  ru   )r<   mock_fileConfigloginir  s       r#   test_log_config_appendz%MutateTestCase.test_log_config_append  s    &&K(@'AB1E  71F:< 	#,,ciiBG//0E!HeAh'		%%'//U 	0 	4r%   c                 R   | j                  dt        fg      d   }| j                  d|z         t        j                  | j
                  d       |j                  |d       |j                          | j
                  j                          | j                  |j                         y )Nr(  r   r)  r  Fr*  )r  r,  r  r   rT   r5   ru   
reset_mockr#  rZ  r   r<   r.  r/  s      r#   test_log_config_append_no_touchz.MutateTestCase.test_log_config_append_no_touch  s    &&K(@'AB1E>GH		$))R //U 	0 	4""$		%%'//0r%   c                    | j                  dt        fg      d   }| j                  d|z         t        j                  | j
                  d       |j                  |d       |j                          t        j                  d       t        j                  |d        | j
                  j                          |j                  |d       y )Nr(  r   r)  r  Fr*  r   )r  r,  r  r   rT   r5   ru   r2  r  r  r   utimer#  r3  s      r#   test_log_config_append_touchz+MutateTestCase.test_log_config_append_touch  s    &&K(@'AB1E>GH		$))R //U 	0 	4""$ 	

1
		%%'//U 	0 	4r%   c           
        	 g }dD ]  }|j                  |i       }t        |      }dj                  |      }|dk(  rd|v r	|rd|z   nd}|j                  d|z  d|z  g       |D ]  }|j                  dd	|d
d d|dg       ||   |j                  fdt              D               |dk(  rdvsR|j	                  d       d|dk(  sj|j	                  d|z         dvs|j	                  d        |j	                  d        |j                  di       		rJ|j                  dg       |j                  	fdt        	      D               d	vr|j	                  d       dj                  |      S )a  Turns a dictConfig-like structure into one suitable for fileConfig.

        The schema is not validated as this is a test helper not production
        code. Garbage in, garbage out. Particularly, don't try to use filters,
        fileConfig doesn't support them.

        Handler args must be passed like 'args': (1, 2). dictConfig passes
        keys by keyword name and fileConfig passes them by position so
        accepting the dictConfig form makes it nigh impossible to produce the
        fileConfig form.

        I traverse dicts by sorted keys for output stability but it doesn't
        matter if defaulted keys are out of order.
        )r   r   r   ,r   rootzroot,z[%s]zkeys=%sr  r  Nrj  _r  c              3   2   K   | ]  }|d |     yw=Nr   )r  r  items     r#   r  z/MutateTestCase.mk_log_config.<locals>.<genexpr>  s     J473J   r   r=  zargs=()zqualname=%sz	handlers=z[logger_root]c              3   2   K   | ]  }|d |     ywr=  r   )r  r  r:  s     r#   r  z/MutateTestCase.mk_log_config.<locals>.<genexpr>  s     FAAtAw/Fr@  r  )getsortedr   extendrC   )
r<   r  linessectionr9  keysskeysr?  r?  r:  s
           @@r#   mk_log_configzMutateTestCase.mk_log_config  s~    < 	GHHWb)E%=DHHTNE)#$-25LL&7*#e+- . 2b+23B<=? @SzJVD\JJj(T)Y/	)LL!45!-[12 LL)	* xx#LL/*+LLFFF%[)yyr%   c                     ddiddddddidddddddidddddd	d
d}d}| j                  || j                  |             y )Nr   r]   rq  F)r   	propagate)aaabbb)r   r   )r   rK  r=  rL  )r   r   )r   r   r   r:  a  [formatters]
keys=aaa,bbb

[formatter_aaa]
level=INFO

[formatter_bbb]
level=WARN
propagate=False

[handlers]
keys=aaa,bbb

[handler_aaa]
level=INFO
args=()

[handler_bbb]
args=(1, 2)
level=WARN
propagate=False

[loggers]
keys=root,aaa,bbb

[logger_aaa]
level=INFO
qualname=aaa
handlers=

[logger_bbb]
level=WARN
propagate=False
qualname=bbb
handlers=

[logger_root]
handlers=aaa
level=INFOrE   rI  )r<   r  fulls      r#   test_mk_log_config_fullz&MutateTestCase.test_mk_log_config_full  s    $+V#4-316$89 &-f$5.427-3%56 (/&70649';< #)%*,&N 	t11$78r%   c                 J    d}| j                  || j                  i              y)z+Ensure mk_log_config tolerates missing bitsz6[formatters]
keys=

[handlers]
keys=

[loggers]
keys=
NrN  )r<   emptys     r#   test_mk_log_config_emptyz'MutateTestCase.test_mk_log_config_empty2  s&     	 2 22 67r%   c              #     K   | j                  d| j                  |      fd| j                  |      fg      }| j                  d|d   z  d|d   z        }t        j                  | j
                  d       ||f t        j                  |d   |d          t        j                  | j
                  j                  d       | j
                  j                          y w)Nzlog1.inizlog2.inir)  r   r   r  )r   r   )r  rI  r  r   rT   r5   r!  r"  r   r6  log_config_appendr#  )r<   conf1conf2loginisr  s        r#   mutate_confzMutateTestCase.mutate_conf?  s     ''++E23++E23)5 6   1GAJ>1GAJ>@ 			$))R unE!HeAh'
,,f5		%%'s   CCc                     | j                  i i       5 \  }}|j                  |d   d       |j                          d d d        |j                  d   d       y # 1 sw Y    xY w)Nr   Fr*  r   )rY  ru   r2  )r<   r.  rX  r  s       r#   "test_log_config_append_change_filez1MutateTestCase.test_log_config_append_change_fileO  st    b"% 	))9'533
U 4 <&&(	)
 	//AJ 	0 	8	) 	)s   *AA%c                     t        j                         }| j                  dt        |j                               |j                  d   }t        j                         |_        |j                  S )Nr   r   )rU   r8   rE   rF   r   r   r   r   )r<   r:  r   s      r#   set_root_streamzMutateTestCase.set_root_streamY  sN      "C./--"~~r%   c                    ddd}ddid|id}dddii}| j                  ||      5 \  }}| j                         }t        j                         }|j	                  d	       | j                  d
|j                                d d d        j                  d       j	                  d	       | j                  d|j                                y # 1 sw Y   LxY w)Nlogging.StreamHandlerr   )classr=  r   faker:  r   r:  r  boozboo
r   )rY  r]  rU   r8   ra   rE   r  truncate)r<   fake_handlerrV  rW  rX  r  r   r:  s           r#   test_remove_handlerz"MutateTestCase.test_remove_handler`  s    !8 "$$f-$l35*b)*eU+ 	9/?))+F$$&DJJuWfoo&78		9
 	

5V__./	9 	9s   ACCc                 4   ddi}ddi}ddid|id|id}ddid|id	}t        j                         }| j                  ||      5 \  }}| j                         }t	        j
                  d      } |j                  d
        |j                  d       | j                  d|j                                d d d        | j                         } j                  d
        |j                  d       | j                  d|j                                y # 1 sw Y   ^xY w)Nr`  r_  r   rq  r   ra  za.a)r:  r   r   rb  rM   rd   zwarn
z
info
warn
)
r   r   rY  r]  rU   r8   rM   rd   rE   r  )	r<   re  fake_loggerrV  rW  r   rX  r  r   s	            r#   test_remove_loggerz!MutateTestCase.test_remove_loggero  s   !89'$f-$l3"K02 %f-$l35eU+ 	:/?))+F##E*CCHHVCHHVXv'89	: %%'):;	: 	:s   A-DD)r   r   r   r-   r  r%  r   r   r  rU   r3   r0  r4  r7  rI  rP  rS  r   rY  r[  r]  rf  ri  r   r   s   @r#   r  r    s    .
B 
ZZw~~|44 54 
ZZw~~|4
1 5
1 
ZZw~~|44 54 + Z59n8 ( ( 
ZZw~~|48 580<r%   r  c                   l     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Z xZS )LogConfigOptsTestCasec                 *    t         t        |           y r?   )r,   rk  r-   r;   s    r#   r-   zLogConfigOptsTestCase.setUp  s    #T02r%   c                     t        j                         }| j                  g        | j                  j                  |       dD ]"  }| j	                  ||j                                $ y )N)file)rR   z
log-configzwatch-log-file)r   r   r5   
print_helpr   r  )r<   rI   options      r#   test_print_helpz%LogConfigOptsTestCase.test_print_help  sP    KKM		"		!$? 	0FMM&!**,/	0r%   c                 t    | j                  dg       | j                  d| j                   j                         y )Nz--debugT)r5   rE   rR   rN   s    r#   r%  z LogConfigOptsTestCase.test_debug  s(    		9+tyy/r%   c                    | j                  g        | j                  | j                   j                         | j                  | j                   j                         | j                  | j                   j                         | j                  t        j                  | j                   j                         | j                  d| j                   j                         | j                  d| j                   j                         y )NF)r5   r   rU  r   r   rE   r   _DEFAULT_LOG_DATE_FORMATlog_date_format
use_sysloguse_jsonrN   s    r#   test_logging_optsz'LogConfigOptsTestCase.test_logging_opts  s    		"$))556$)),,-$))++,::22	4 			 4 45		 2 23r%   c                 z    d}| j                  d|g       | j                  || j                   j                         y )Nz/some/path/foo-bar.logr  r5   rE   r   r  s     r#   test_log_filez#LogConfigOptsTestCase.test_log_file  s2    +		<*+499#5#56r%   c                    t        j                         }| j                  d|g       | j                  j                  dd       t	        j
                  | j                  dd       t        j                  d    j                  }| j                  dt        |j                               | j                  |j                  d   t        j                  j                         y )Nr  r  Fr+   r   r   )r  mkdtempr5   set_defaultr   r7   ri  r9   rE   rF   r   r6  rU   WatchedFileHandler)r<   r   r9   s      r#   test_log_dir_handlersz+LogConfigOptsTestCase.test_log_dir_handlers  s    ""$		;()		lE2$$TYY?d#**C01fooa0%..AA	Cr%   c                    t        j                         }t        j                  d|      5 }t        j                         }| j                  d|g       | j
                  j                  dd       | j
                  j                  dd       t        j                  | j
                  dd       t        j                  d    j                  }| j                  d	t        |j                               | j                  |j                  d
   t        j                  j                          | j                  ||j                  d          |j#                  dt        j$                         d d d        y # 1 sw Y   y xY w)Nz$oslo_utils.importutils.import_objectrk   r  r  Fpublish_errorsTr+   r   r   r   z6oslo_messaging.notify.log_handler.PublishErrorsHandler)r   	MagicMockr   r  r}  r5   r~  r   r7   ri  r9   rE   rF   r   r6  rU   r  ru   rC  )r<   re  mock_importr   r9   s        r#    test_log_publish_errors_handlersz6LogConfigOptsTestCase.test_log_publish_errors_handlers  s   ~~'ZZ>%13 	6A&&(GII{G,-II!!,6II!!"2D9((FFC\\$'..FQFOO 45!!&//!"4")"2"2"E"EG\6??1+=>//H	 	 	s   D9E..E7c                 z    d}| j                  d|g       | j                  || j                   j                         y )Nz/some/other/path/foo-bar.logz	--logfilerz  )r<   logfiles     r#   test_logfile_deprecatedz-LogConfigOptsTestCase.test_logfile_deprecated  s2    0		;()$))"4"45r%   c                 z    d}| j                  d|g       | j                  || j                   j                         y )Nz/some/path/r  r5   rE   r   )r<   r   s     r#   test_log_dirz"LogConfigOptsTestCase.test_log_dir  s2    		;()$))"3"34r%   c                 z    d}| j                  d|g       | j                  || j                   j                         y )Nz/some/other/path/z--logdirr  )r<   logdirs     r#   test_logdir_deprecatedz,LogConfigOptsTestCase.test_logdir_deprecated  s2    $		:v&'!2!23r%   c                     t        j                  | j                  dd       t         j                  d    j                  }|j
                  D ].  }|j                  }| j                  |t        j                         0 y )Nr+   )
r   r7   r5   ri  r9   r   r@   r6  r   rB   r<   r9   r   r@   s       r#   test_default_formatterz,LogConfigOptsTestCase.test_default_formatter  sc    $$TYY?d#** 	?G))I!!)","="=?	?r%   c                    | j                  dg       t        j                  | j                   dd       t        j                  d    j                  }|j
                  D ].  }|j                  }| j                  |t        j                         0 y )Nz
--use-jsonr+   )
r5   r   r7   ri  r9   r   r@   r6  r   rr  r  s       r#   test_json_formatterz)LogConfigOptsTestCase.test_json_formatter  sq    		<.!$$TYY?d#** 	<G))I!!)",":":<	<r%   c                    t         j                  j                         t         j                  j                         g}t        |      t         j                  d   j
                  _        t        j                  | j                  dd       t         j                  d   j
                  j                  }| j                  dt        |             | j                  |d   |       y)z5Test that all old handlers get removed from log_root.Nr+   r   r   )r   r   rh  r   ri  r9   r7   r5   rE   rF   r  )r<   old_handlersr   s      r#   test_handlers_cleanupz+LogConfigOptsTestCase.test_handlers_cleanup  s    1131135-1,-?T!!*$$TYY?<<%,,55CM*!l3r%   c                 :   t        j                         }|d   \  }}| j                  |       | j                  t         j                  t         j
                  z   t         j                  z   t         j                  z   t         j                  j                  z   |       y r   )
r   	list_optsr   rE   common_cli_optsr  generic_log_optsr  versionutilsdeprecated_opts)r<   all_optionsgroupoptionss       r#   test_list_optsz$LogConfigOptsTestCase.test_list_opts  s    ((*&q>% (22"334"334 #++, #//??	@ CJ		Kr%   )r   r   r   r-   rq  r%  rx  r{  r  r  r  r  r  r  r  r  r  r   r   s   @r#   rk  rk    sK    30047
C$6
5
4
?<4Kr%   rk  c                   <     e Zd Z fdZd Zd Zd Zd Zd Z xZ	S )LogConfigTestCasec                     t         t        |           | j                  dt        fg      }|d   | _        t        t        j                  d      rt        j                  `	y y )NrU   r   r  )
r,   r  r-   r  r,  rU  r  r   r  r  )r<   namesr=   s     r#   r-   zLogConfigTestCase.setUp  sV    ,.%%	;'?&@A!&q3''4$$- 5r%   c                 |    | j                  | j                         t        j                  | j                  d       y NrU  r0  )r3   rU  r   rT   r5   rN   s    r#   test_log_config_append_okz+LogConfigTestCase.test_log_config_append_ok  s)    d&<&<=		$))56r%   c                     t        j                  | j                         | j                  | j                         | j	                  t
        j                  t
        j                  | j                  d       y r  )	r   r  rU  r3   re   r   r-  rT   r5   rN   s    r#    test_log_config_append_not_existz2LogConfigTestCase.test_log_config_append_not_exist  sN    
		$(()d&<&<=#,,cii))2	4r%   c                     | j                  dg      }|d   | _        | j                  | j                         | j                  t        j
                  t        j                  | j                  d       y )N)rU   squawkr   r  r0  )r  rU  r3   re   r   r-  rT   r5   )r<   r  s     r#   test_log_config_append_invalidz0LogConfigTestCase.test_log_config_append_invalid
  s\    %%'<&=>!&qd&<&<=#,,cii))2	4r%   c                     t        j                  | j                  d       | j                  | j                         | j	                  t
        j                  t
        j                  | j                  d       y )Nr   r  r0  )	r   chmodrU  r3   re   r   r-  rT   r5   rN   s    r#   !test_log_config_append_unreadablez3LogConfigTestCase.test_log_config_append_unreadable  sP    
''+d&<&<=#,,cii))2	4r%   c                 
   | j                  | j                         t        j                  d      5 }t	        j
                  | j                  d       d d d        j                  | j                  d       y # 1 sw Y   'xY w)Nr  zlogging.config.fileConfigr0  Fr*  )r3   rU  r   r   r   rT   r5   ru   )r<   r&  s     r#   /test_log_config_append_disable_existing_loggerszALogConfigTestCase.test_log_config_append_disable_existing_loggers  sn    d&<&<=ZZ34 	;
IIdii!9:	; 	**4+A+ADI 	+ 	K	; 	;s   !A99B)
r   r   r   r-   r  r  r  r  r  r   r   s   @r#   r  r    s"    .7444Kr%   r  c                   (     e Zd Z fdZ fdZ xZS )SavingAdapterc                 N    t        t        j                  |   |i | g | _        y r?   )r,   r   KeywordArgumentAdapter__init__results)r<   r=  kwdsr=   s      r#   r  zSavingAdapter.__init__$  s$    c(($8$G$Gr%   c                 l    t         t        |   ||      }| j                  j	                  |||f       |S r?   )r,   r  processr  rC   )r<   r  r>  r  r=   s       r#   r  zSavingAdapter.process(  s6     t4S&AS&'23r%   )r   r   r   r  r  r   r   s   @r#   r  r  "  s     r%   r  c                   B     e Zd Z fdZd Zd Zd Zd Zd Zd Z	 xZ
S )KeywordArgumentAdapterTestCasec                 6   t         t        |           t        j                         | _        t        j                  | j
                  j                  _	        d| j
                  j                  _        t        j                  | j
                  j                  _        y )NT)r,   r  r-   r   r   mock_logrU   NOTSETmanagerdisablerY  rl   rV   rW   r;   s    r#   r-   z$KeywordArgumentAdapterTestCase.setUp2  s^    ,d9; 		(/%26""/7>}}''4r%   c                     t        j                  | j                  i       }|j                  di       \  }}| j	                  ddg ii|       y )Nr  r  r  r   r  r  r  rE   )r<   ar  r>  s       r#   test_empty_kwargsz0KeywordArgumentAdapterTestCase.test_empty_kwargs;  sF    &&t}}b9ii	2.V'L"#56?r%   c                     d}d}||i}t        j                  | j                  |      }|j                  di       \  }}| j	                  d||d|gii|       y )NrL   blahr  r  r  r  )r<   r?  valr  r  r  r>  s          r#   test_include_constructor_extrasz>KeywordArgumentAdapterTestCase.test_include_constructor_extras@  sb    Sz&&t}}d;ii	2.V'ClSE#BC	!r%   c                     t        j                  | j                  i       }d}|j                  dd|i      \  }}| j	                  dg i|d|       y )Nrb   r  rX  r  )r  rX  r  )r<   r  exc_messager  r>  s        r#   test_pass_through_exc_infoz9KeywordArgumentAdapterTestCase.test_pass_through_exc_infoI  sW    &&t}}b9!ii	J+DEV#R($&	r%   c           	          t        j                  | j                  i       }ddddd}t        j                  |      }|j	                  d|      \  }}| j                  d|d   |d	   t        |j                               |d
   |d   di|       y )Nzsome context objectzinstance identifierzUUID for instancegoes)r
   r  r  anythingr  r  r  r
   r  r  )r  r
   r  r  r  )r   r  r  r"  r  rE   rC  rG  )r<   r  r  r   r  r>  s         r#   test_update_extrasz1KeywordArgumentAdapterTestCase.test_update_extrasR  s    &&t}}b901!4"$ 99T?ii	40V8J#7"*9"5%+HMMO%<#+J#7(0(A	C D
 	r%   c                 d   t        | j                  i       }d}d}d}|j                  t        j                  |||       ||dgdd}|j
                  d   }| j                  ||d          | j                  ||d	          |d
   }| j                  ||d          | j                  ||d	          y Nr  rb   ru  )r   rX  r   )r   r  )rX  r  r   r   r   )r  r  r   rU   rV   r  rE   r<   r  r  r  r  r   actualr  s           r#   test_pass_args_to_logz4KeywordArgumentAdapterTestCase.test_pass_args_to_logc  s    $--,!	gmmW3E $!&:

 1&),6!9-)'!*-71:.r%   c                 F   t        | j                  i       }d}d}d}|j                  |||       ||dgdd}|j                  d   }| j	                  ||d          | j	                  ||d	          |d
   }| j	                  ||d          | j	                  ||d	          y r  )r  r  rR   r  rE   r  s           r#   test_pass_args_via_debugz7KeywordArgumentAdapterTestCase.test_pass_args_via_debugw  s    $--,!	cK8 $!&:

 1&),6!9-)'!*-71:.r%   )r   r   r   r-   r  r  r  r  r  r  r   r   s   @r#   r  r  0  s(    E@
!"/(/r%   r  c                   "    e Zd ZdZd Zd Zd Zy)UnicodeConversionTestCaseu+   Message with unicode char ꀀ in the middlec                     | j                   }|j                  d      }t        j                  |      }| j	                  ||       | j                  |t               y )Nzutf-8)_MSGr  r   _ensure_unicoderE   r6  r7  )r<   r  enc_msgresults       r#   test_ascii_to_unicodez/UnicodeConversionTestCase.test_ascii_to_unicode  sI    ii**W%++G4f%fc*r%   c                     | j                   }t        j                  |      }| j                  ||       | j	                  |t
               y r?   )r  r   r  rE   r6  r7  )r<   r  r  s      r#   test_unicode_to_unicodez1UnicodeConversionTestCase.test_unicode_to_unicode  s;    ii++C0f%fc*r%   c                     | j                   }t        |      }t        j                  |      }| j	                  ||       | j                  |t               y r?   )r  rG  r   r  rE   r6  r7  )r<   r  excr  s       r#   test_exception_to_unicodez3UnicodeConversionTestCase.test_exception_to_unicode  sD    iin++C0f%fc*r%   N)r   r   r   r  r  r  r  r   r%   r#   r  r    s    ;D+++r%   r  c                       e Zd Zd Zd Zy)LoggerNameTestCasec                 ~    d}t        j                  |      }| j                  ||j                  j                         y )Nzoslo.subname)r   r8   rE   r9   r   rX   s      r#   test_oslo_dotz LoggerNameTestCase.test_oslo_dot  s/    ${+fmm&8&89r%   c                     d}|j                  dd      }t        j                  |      }| j                  ||j                  j
                         y )Noslo_subnamer;  .)replacer   r8   rE   r9   r   )r<   rY   r   r9   s       r#   test_oslo_underscorez'LoggerNameTestCase.test_oslo_underscore  sA    $&&sC0{+6==#5#56r%   N)r   r   r   r  r  r   r%   r#   r  r    s    :
7r%   r  c                   2     e Zd Z fdZddZd Zd Z xZS )IsDebugEnabledTestCasec                 ^   t         t        |           | j                  t	        j
                  t        j                                     | _        | j                  j                  | _	        | j                  j                  | _        t        j                  | j                  j                         y r?   )r,   r  r-   r.   r/   r0   r   r1   r2   r3   r4   r5   r   r6   r;   s    r#   r-   zIsDebugEnabledTestCase.setUp  sw    $d13"oo!!#.."235))00'',,	T00556r%   c                     | j                  |       | j                  |t        j                  | j                               y )NrQ   )r3   rE   r   is_debug_enabledr5   )r<   rR   s     r#   _test_is_debug_enabledz-IsDebugEnabledTestCase._test_is_debug_enabled  s/    %  4 4TYY ?@r%   c                 $    | j                          y r?   r  rN   s    r#   test_is_debug_enabled_offz0IsDebugEnabledTestCase.test_is_debug_enabled_off  s    ##%r%   c                 (    | j                  d       y )NTrQ   r  rN   s    r#   test_is_debug_enabled_onz/IsDebugEnabledTestCase.test_is_debug_enabled_on  s    ##$#/r%   )F)r   r   r   r-   r  r  r  r   r   s   @r#   r  r    s    7A&0r%   r  )O
contextlibr   r"  r  r   rU   r   platformr!  rW  r   r  systemdr   r  r  unittestr   dateutilr   oslo_configr   r   r/   oslo_contextr
   r   	oslo_i18nr  oslo_serializationr   oslotestr   	test_baserH  r  r   r   r   r   
oslo_utilsr   r,  r$   r  r'   r   r   r   r   r   rI  r   r  rK  ro  r  r   r  r  r  rR  rd  r  r  r  r  skipIfsystemr  r  rk  r  r  r  r  r  r  r  r   r%   r#   <module>r     s  & &   	  	   
      1   3 . ( &      zJV zJz'+Y-C-C '
%9)) 
%'B, 'BT'& '&T8\ 8  f78#Ll #L 9#LLW5| W5t+0| +0\A2K A2H
%-- 
%H+k H+Vp<{ p<f1.{ 1.hR;+ R;jF8[ F8RC C"F[ "FJ=., =.@ /(//#w.CE+2\ +2E+2\{<\ {<|pKL pKf(K (KVC.. Y/\ Y/x+ +27 70Y33 0k<  F  Gs"   I I IIII