Coverage for src/robotide/context/logger.py: 50%

52 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-06 10:40 +0100

1# Copyright 2008-2015 Nokia Networks 

2# Copyright 2016- Robot Framework Foundation 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15 

16import re 1ab

17import sys 1ab

18 

19import wx 1ab

20 

21from ..publish import RideParserLogMessage 1ab

22from ..widgets import RIDEDialog 1ab

23 

24 

25class Logger(object): 1ab

26 empty_suite_init_file_warn = re.compile("Test suite directory initialization " 1ab

27 "file '.*' contains no test data.") 

28 

29 def __init__(self): 1ab

30 self._messages = [] 1ab

31 

32 def report_parsing_errors(self): 1ab

33 errors = [m[0] for m in self._messages] 

34 if errors: 34 ↛ 35line 34 didn't jump to line 35 because the condition on line 34 was never true

35 errors = set(errors) 

36 msg = '\n'.join(self._format_parsing_error_line(line) for line in errors) 

37 # print("DEBUG: logger: %s" % msg) 

38 self._messages = [] 

39 RideParserLogMessage(msg, level='PARSER').publish() 

40 # Warnings from robot.variables.Variables.set_from_variable_tablems 

41 # are present multiple times, issue 486. 

42 """ 

43 errors = set(errors) 

44 dlg = ParsingErrorDialog('\n'.join(self._format_parsing_error_line(line) 

45 for line in errors)) 

46 dlg.ShowModal() 

47 dlg.Destroy()  

48 """ 

49 self._messages = [] 

50 

51 def _format_parsing_error_line(self, line): 1ab

52 if ':' not in line: 

53 return line 

54 index = line.index(':') + 1 

55 return line[:index] + '\n\t' + line[index:] 

56 

57 def warn(self, msg=''): 1ab

58 self._write(msg, 'WARN') 

59 

60 def error(self, msg=''): 1ab

61 self._write(msg, 'ERROR') 

62 

63 def message(self, msg): 1ab

64 message, level = msg.message, msg.level.upper() 2a c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBbCbDbEbFbGb

65 if self._is_logged(level): 2a c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBbCbDbEbFbGb

66 self._messages.append((message, level)) 1ac

67 

68 def _write(self, msg, level): 1ab

69 level = level.upper() 

70 if self._is_logged(level) and not self._is_ignored_warning(msg): 

71 self._show_message(msg, level) 

72 

73 def _is_logged(self, level): 1ab

74 return level.upper() in ['ERROR', 'WARN'] 2a c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBbCbDbEbFbGb

75 

76 def _is_ignored_warning(self, msg): 1ab

77 return self.empty_suite_init_file_warn.search(msg) 

78 

79 def _show_message(self, msg, level): 1ab

80 try: 

81 icon = level == 'ERROR' and wx.ICON_ERROR or wx.ICON_WARNING 

82 message_box = RIDEDialog(title=level, message=msg, style=icon) 

83 message_box.ShowModal() 

84 except wx.PyNoAppError: 

85 sys.stderr.write('%s: %s\n' % (level, msg)) 

86 

87 

88class ParsingErrorDialog(RIDEDialog): 1ab

89 

90 def __init__(self, message): 1ab

91 RIDEDialog.__init__(self, title='Parsing errors', size=(700, 400), 

92 style=wx.DEFAULT_FRAME_STYLE) 

93 # set Left to Right direction (while we don't have localization) 

94 self.SetLayoutDirection(wx.Layout_LeftToRight) 

95 area = wx.TextCtrl(self, size=(700,400), style=wx.TE_MULTILINE|wx.TE_DONTWRAP|wx.TE_READONLY|wx.TE_NOHIDESEL) 

96 area.SetValue(message)