6767from robotide .pluginapi import Plugin , ActionInfo
6868from robotide .widgets import Label , ImageProvider
6969from robotide .robotapi import LOG_LEVELS
70- from robotide .utils import robottime , is_unicode , PY2 , PY3
70+ from robotide .utils import robottime , is_unicode , PY2
7171from sys import getfilesystemencoding
72- try :
73- from robotide .lib .robot .utils import encoding
74- except ImportError :
75- encoding = None
76- # if encoding:
77- # encoding.CONSOLE_ENCODING = getfilesystemencoding()
78-
79- if PY3 :
80- from robotide .utils import unicode
81-
82- # print("DEBUG: TestRunnerPlugin encoding=%s" % encoding)
72+ from robotide .lib .robot .utils .encodingsniffer import (get_console_encoding ,
73+ get_system_encoding )
74+ CONSOLE_ENCODING = get_console_encoding ()
75+ if PY2 and IS_WINDOWS :
76+ SYSTEM_ENCODING = 'mbcs'
77+ else :
78+ SYSTEM_ENCODING = get_system_encoding ()
79+ OUTPUT_ENCODING = getfilesystemencoding ()
80+ encoding = {'CONSOLE' : CONSOLE_ENCODING ,
81+ 'SYSTEM' : SYSTEM_ENCODING ,
82+ 'OUTPUT' : OUTPUT_ENCODING }
83+
84+ #print("DEBUG: TestRunnerPlugin encoding=%s" % encoding)
8385
8486ID_RUN = wx .NewId ()
8587ID_RUNDEBUG = wx .NewId ()
@@ -300,12 +302,16 @@ def OnRun(self, event):
300302 return
301303 self ._initialize_ui_for_running ()
302304 command = self ._create_command ()
303- self ._output ("command: %s\n " % command ) # DEBUG encode
305+ if PY2 :
306+ self ._output ("command: %s\n " % command ) # DEBUG encode
307+ else :
308+ self ._output ("command: %s\n " % command , enc = False ) # DEBUG on Py3 it not shows correct if tags with latin chars
304309 try :
305- if PY2 and IS_WINDOWS :
310+ if PY2 : # and IS_WINDOWS:
306311 cwd = self ._get_current_working_dir () # DEBUG It fails if a directory has chinese or latin symbols
307- cwd = cwd .encode (encoding .SYSTEM_ENCODING )
308- self ._test_runner .run_command (command , cwd )
312+ cwd = cwd .encode (encoding ['OUTPUT' ]) # DEBUG SYSTEM_ENCODING
313+ # print("DEBUG: encoded cwd: %s" % cwd)
314+ self ._test_runner .run_command (command .encode (encoding ['OUTPUT' ]), cwd ) # --include Áçãoµ
309315 else :
310316 self ._test_runner .run_command (command , self ._get_current_working_dir ())
311317 # self._output("DEBUG: Passed test_runner.run_command\n")
@@ -489,7 +495,7 @@ def _format_command(self, argv):
489495 result = []
490496 for arg in argv :
491497 if PY2 and is_unicode (arg ):
492- arg = arg .encode (encoding . CONSOLE_ENCODING ) # DEBUG "utf-8")
498+ arg = arg .encode (encoding [ 'SYSTEM' ] ) # DEBUG "utf-8") CONSOLE_ENCODING
493499 # print("DEBUG: PY2 unicode args %s" % arg)
494500 if "'" in arg or " " in arg or "&" in arg :
495501 # for windows, if there are spaces we need to use
@@ -508,7 +514,7 @@ def _show_notebook_tab(self):
508514 self ._reload_model ()
509515 self .show_tab (self .panel )
510516
511- def _AppendText (self , textctrl , string , source = "stdout" ):
517+ def _AppendText (self , textctrl , string , source = "stdout" , enc = True ):
512518 if not self .panel or not textctrl :
513519 return
514520 textctrl .update_scroll_width (string )
@@ -520,15 +526,21 @@ def _AppendText(self, textctrl, string, source="stdout"):
520526
521527 textctrl .SetReadOnly (False )
522528 try :
523- if PY2 :
524- # textctrl.AppendText(string.encode(encoding.OUTPUT_ENCODING)) # DEBUG encoding.CONSOLE_ENCODING)) # DEBUG 'utf-8'))
525- textctrl .AppendText (string .encode (encoding .SYSTEM_ENCODING )) # encoding.SYSTEM_ENCODING)) 'utf-8'
529+ if enc :
530+ textctrl .AppendText (string .encode (encoding ['SYSTEM' ]))
526531 else :
527- textctrl .AppendText (str (string )) # DEBUG
532+ textctrl .AppendText (string )
533+ # print("DEBUG _AppendText Printed OK")
528534 except UnicodeDecodeError as e :
529535 # I'm not sure why I sometimes get this, and I don't know what I
530536 # can do other than to ignore it.
531- textctrl .AppendTextRaw (bytes (string )) # DEBUG .encode('utf-8'))
537+ if PY2 :
538+ if is_unicode (string ):
539+ textctrl .AppendTextRaw (bytes (string .encode ('utf-8' )))
540+ else :
541+ textctrl .AppendTextRaw (string )
542+ else :
543+ textctrl .AppendTextRaw (bytes (string , encoding ['SYSTEM' ])) # DEBUG .encode('utf-8'))
532544 # print(r"DEBUG UnicodeDecodeError appendtext string=%s\n" % string)
533545 pass
534546 except UnicodeEncodeError as e :
@@ -580,9 +592,9 @@ def _build_config_panel(self, parent):
580592 self .config_panel = panel
581593 return panel
582594
583- def _output (self , string , source = "stdout" ):
595+ def _output (self , string , source = "stdout" , enc = True ):
584596 """Put output to the text control"""
585- self ._AppendText (self .out , string , source )
597+ self ._AppendText (self .out , string , source , enc )
586598
587599 def _build_runner_toolbar (self ):
588600 toolbar = wx .ToolBar (self .panel , wx .ID_ANY ,
@@ -778,7 +790,7 @@ def _create_output_textctrl(self):
778790 face = font .GetFaceName ()
779791 size = font .GetPointSize ()
780792 textctrl .SetFont (font )
781- # textctrl.StyleSetFontEncoding(wx.stc.STC_STYLE_DEFAULT, wx.FONTENCODING_SYSTEM ) # DEBUG Chinese wx.FONTENCODING_CP936)
793+ # textctrl.StyleSetFontEncoding(wx.stc.STC_STYLE_DEFAULT, wx.FONTENCODING_CP936 ) # DEBUG Chinese wx.) wx.FONTENCODING_SYSTEM
782794 textctrl .StyleSetSpec (wx .stc .STC_STYLE_DEFAULT , "face:%s,size:%d" %
783795 (face , size ))
784796 textctrl .StyleSetSpec (STYLE_STDERR , "fore:#b22222" ) # firebrick
0 commit comments