
    5f1                         d 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
 Z G d de      Z G d dej(                        Z G d dej(                        Zy)z!Unit Tests for oslo.log formatter    N)mock)cfg)fixture)context)base)
formatters)logc                  :    t        j                  ddddd      } | S )NusertenantpdomainudomainT)user_id
project_idproject_domain_iduser_domain_id	overwrite)r   RequestContext)ctxts    E/usr/lib/python3/dist-packages/oslo_log/tests/unit/test_formatters.py_fake_contextr      s'    !!&-54=1:,0	2D K    c                       e Zd ZddZd Zy)AlternativeRequestContextNc                      || _         || _        y Nr   r   )selfr   r   s      r   __init__z"AlternativeRequestContext.__init__*   s    	r   c                 4    | j                   | j                  dS )Nr   r   r   s    r   to_dictz!AlternativeRequestContext.to_dict.   s    		++' 	'r   )NN)__name__
__module____qualname__r   r"    r   r   r   r   (   s    'r   r   c                        e Zd Z fdZd Zd Zd Z ej                  d      d        Z	 ej                  d      d        Z
 ej                  d      d        Z xZS )	FormatterTestc                 *    t         t        |           y r   )superr(   setUpr   	__class__s    r   r+   zFormatterTest.setUp5   s    mT(*r   c                 f    ddi}dt        j                  |      z  }| j                  |d   |       y )Nr   user1z%(user)sr   _ReplaceFalseValueassertEqualr   dss      r   test_replace_false_value_existsz-FormatterTest.test_replace_false_value_exists8   s5    W66q996A&r   c                 `    ddi}dt        j                  |      z  }| j                  d|       y )Nr   r/   z%(project)s-r0   r3   s      r   #test_replace_false_value_not_existsz1FormatterTest.test_replace_false_value_not_exists=   s1    WJ99!<<a r   c                 N    | j                  i t        j                  d              y r   )r2   r   _dictify_contextr!   s    r   test_dictify_context_emptyz(FormatterTest.test_dictify_context_emptyB   s    Z88>?r   zdebtcollector.deprecatec                 v    ddi}| j                  |t        j                  |             |j                          y )Nr   )r2   r   r;   assert_not_called)r   mock_deprecater4   s      r   test_dictify_context_with_dictz,FormatterTest.test_dictify_context_with_dictE   s3    VJ77:;((*r   c                     t               }| j                  |j                         t        j                  |             |j                          y r   )r   r2   get_logging_valuesr   r;   r>   )r   r?   r   s      r   !test_dictify_context_with_contextz/FormatterTest.test_dictify_context_with_contextK   s<    002#44T:	<((*r   c                     t        dd      }ddd}| j                  |t        j                  |             |j	                  ddd       y )Nr   r   r   zThe RequestContext.get_logging_values() method should be defined for logging context specific information.  The to_dict() method is deprecated for oslo.log use.z5.0.0z3.8.0)removal_versionversion)r   r2   r   r;   assert_called_with)r   r?   r   r4   s       r   /test_dictify_context_without_get_logging_valuesz=FormatterTest.test_dictify_context_without_get_logging_valuesR   sS    (fXFx0J77=>))  29'	 	* 	Kr   )r#   r$   r%   r+   r6   r9   r<   r   patchr@   rC   rH   __classcell__r-   s   @r   r(   r(   3   sz    +'
!
@ TZZ)*+ ++
 TZZ)*+ ++ TZZ)*K +K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 )FormatUnhashableExceptionTestc                    t         t        |           | j                  t	        j
                  t        j                                     | _        | j                  j                  | _        t        j                  | j                         y r   )r*   rM   r+   
useFixtureconfig_fixtureConfigr   
ConfigOptsconfr	   register_optionsr,   s    r   r+   z#FormatUnhashableExceptionTest.setUp`   s\    +T8:"oo!!#.."235'',,	TYY'r   c                 n     G d dt               }	  |       # |$ r t        j                         cY S w xY w)Nc                       e Zd ZdZy)UFormatUnhashableExceptionTest._unhashable_exception_info.<locals>.UnhashableExceptionN)r#   r$   r%   __hash__r&   r   r   UnhashableExceptionrW   h   s    Hr   rY   )	Exceptionsysexc_info)r   rY   s     r   _unhashable_exception_infoz8FormatUnhashableExceptionTest._unhashable_exception_infog   s7    	) 		"%''" 	"<<>!	"s    44c           	          | j                         }t        j                  dt        j                  dddg |      }t	        j
                  |      }| j                  |       y )Ntestr   test message)r]   logging	LogRecordERRORr   _get_error_summary
assertTrue)r   r\   recorderr_summarys       r   test_error_summaryz0FormatUnhashableExceptionTest.test_error_summaryp   sP    224""67==&!#12xA 33F;$r   c                     | j                         }t        j                         }dj                  |j	                  |            }| j                  |       y )N )r]   r   JSONFormatterjoinformatExceptionre   r   r\   	formattertbs       r   test_json_format_exceptionz8FormatUnhashableExceptionTest.test_json_format_exceptionw   sC    224,,.	WWY..x89r   c                     | j                         }t        j                         }|j                  |      }| j	                  |       y r   )r]   r   FluentFormatterrm   re   rn   s       r   test_fluent_format_exceptionz:FormatUnhashableExceptionTest.test_fluent_format_exception}   s:    224..0	&&x0r   c                     | j                         }t        j                  | j                        }|j	                  |      }| j                  |       y )Nconfig)r]   r   ContextFormatterrS   rm   re   rn   s       r   &test_context_format_exception_norecordzDFormatUnhashableExceptionTest.test_context_format_exception_norecord   s@    224//tyyA	&&x0r   c           	          | j                         }t        j                  | j                        }t	        j
                  dt        j                  dddg |      }|j                  |      }| j                  |       y )Nrv   r_   r   r`   )	r]   r   rx   rS   ra   rb   rc   formatre   )r   r\   ro   rf   rp   s        r   test_context_format_exceptionz;FormatUnhashableExceptionTest.test_context_format_exception   sd    224//tyyA	""67==&!#12xAf%r   )r#   r$   r%   r+   r]   rh   rq   rt   ry   r|   rJ   rK   s   @r   rM   rM   _   s&    ("%r   rM   )__doc__ra   r[   unittestr   oslo_configr   r   rP   oslo_contextr   oslotestr   	test_baseoslo_logr   r	   r   objectr   BaseTestCaser(   rM   r&   r   r   <module>r      s]    (  
   1   &  ' '(KI** (KX0I$:$: 0r   