Skip to content

Commit 2a404fb

Browse files
HelioGuilherme66NyralHelio Guilherme
authored
Nyral/fix encodings (#2217)
* Refactored how text econding is done in _AppendText * Separates AppendText for MessagesLog. Adds process memory limit on MessagesLog. * Adds psutil to requirements. * Closes and reopens Messages Log window when process memory exceeds 80% * Windows: Log fixed, Output broken. More Debug Outputs. * Stops log when memory exceeds limit. * Correct output, when set PYTHONIOENCODING=utf-8 on Windows Co-authored-by: Nyral <[email protected]> Co-authored-by: Helio Guilherme <[email protected]>
1 parent ec7ea57 commit 2a404fb

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/robotide/contrib/testrunner/testrunnerplugin.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -564,17 +564,22 @@ def _AppendText(self, textctrl, string, source="stdout", enc=True):
564564
textctrl.SetReadOnly(False)
565565
try:
566566
if enc:
567-
textctrl.AppendText(string.encode(encoding['SYSTEM']))
567+
if IS_WINDOWS:
568+
textctrl.AppendText(string.encode('mbcs'))
569+
else:
570+
textctrl.AppendText(string.encode(encoding['SYSTEM'])) # string.encode('UTF-8')) # DEBUG removed bytes
568571
else:
569-
textctrl.AppendText(string)
570-
except UnicodeDecodeError:
572+
textctrl.AppendText(string.encode(encoding['OUTPUT']))
573+
except UnicodeDecodeError as e:
571574
# I'm not sure why I sometimes get this, and I don't know what I
572575
# can do other than to ignore it.
573-
textctrl.AppendTextRaw(bytes(string, encoding['SYSTEM']))
574-
except UnicodeEncodeError:
576+
# print(f"DEBUG: Console print UnicodeDecodeError string is {string}")
577+
textctrl.AppendTextRaw(string) # DEBUG removed bytes
578+
except UnicodeEncodeError as e:
575579
# I'm not sure why I sometimes get this, and I don't know what I
576580
# can do other than to ignore it.
577-
textctrl.AppendText(string.encode('utf-8'))
581+
# print(f"DEBUG: Console print UnicodeEncodeError string is {string}")
582+
textctrl.AppendTextRaw(string.encode(encoding['CONSOLE'])) # .encode('mbcs'))
578583

579584
new_text_end = textctrl.GetLength()
580585

@@ -603,7 +608,7 @@ def _AppendTextMessageLog(self, textctrl, string, source="stdout", enc=True):
603608
textctrl.SetReadOnly(False)
604609
try:
605610
if enc:
606-
textctrl.AppendText(string.encode(encoding['OUTPUT']))
611+
textctrl.AppendText(string.encode(encoding['SYSTEM']))
607612
else:
608613
textctrl.AppendText(string)
609614
except UnicodeDecodeError as e:
@@ -873,16 +878,16 @@ def _post_result(self, event, *args):
873878
self._append_to_message_log('<< CONTINUE >>')
874879

875880
def _handle_start_test(self, args):
876-
longname = args[1]['longname']
877-
self._append_to_message_log('Starting test: %s' % longname)
881+
longname = args[1]['longname'].encode('utf-8')
882+
self._append_to_message_log(f"Starting test: {longname.decode(encoding['OUTPUT'], 'backslashreplace')}")
878883

879884
def _append_to_message_log(self, text):
880885
if self.show_message_log:
881886
self._messages_log_texts.put(text)
882887

883888
def _handle_end_test(self, args):
884-
longname = args[1]['longname']
885-
self._append_to_message_log('Ending test: %s\n' % longname)
889+
longname = args[1]['longname'].encode('utf-8')
890+
self._append_to_message_log(f"Ending test: {longname.decode(encoding['OUTPUT'], 'backslashreplace')}\n")
886891
if args[1]['status'] == 'PASS':
887892
self._progress_bar.add_pass()
888893
else:

0 commit comments

Comments
 (0)