#NEWLINE# @ mock . patch ( 'gettext.translation' ) #NEWLINE# def test_emit_translated_message_with_named_args( self , mock_translation ) : #NEWLINE# #INDENT# log_message = 'A message to be logged %(arg1)s $(arg2)s' #NEWLINE# log_message_translation = 'Chinese msg to be logged %(arg1)s $(arg2)s' #NEWLINE# log_arg_1 = 'Arg1 to be logged' #NEWLINE# log_arg_1_translation = 'Arg1 to be logged in Chinese' #NEWLINE# log_arg_2 = 'Arg2 to be logged' #NEWLINE# log_arg_2_translation = 'Arg2 to be logged in Chinese' #NEWLINE# translations = { #NEWLINE# #INDENT# log_message : log_message_translation , #NEWLINE# log_arg_1 : log_arg_1_translation , #NEWLINE# log_arg_2 : log_arg_2_translation , #NEWLINE# #UNINDENT# } #NEWLINE# translations_map = { #NEWLINE# #INDENT# 'zh_CN' : translations , #NEWLINE# #UNINDENT# } #NEWLINE# translator = fakes . FakeTranslations . translator ( translations_map ) #NEWLINE# mock_translation . side_effect = translator #NEWLINE# msg = _message . Message ( log_message ) #NEWLINE# arg_1 = _message . Message ( log_arg_1 ) #NEWLINE# arg_2 = _message . Message ( log_arg_2 ) #NEWLINE# self . logger . info ( msg , { #NEWLINE# #INDENT# 'arg1' : arg_1 , #NEWLINE# 'arg2' : arg_2 , #NEWLINE# #UNINDENT# } ) #NEWLINE# translation = ( log_message_translation % { #NEWLINE# #INDENT# 'arg1' : log_arg_1_translation , #NEWLINE# 'arg2' : log_arg_2_translation , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertIn ( translation , self . stream . getvalue ( ) )