11 from typing
import Optional, Sequence
17 if "___HasLoadedMessageFilters" not in globals():
19 ___HasLoadedMessageFilters =
True
21 STRIP_HTML_TAGS_REGEXP = re.compile(
'<[^>]*>')
36 Base class to implement filters for specific log messages, allowing e.g. to expect or ignore errors.
39 _typeIdentifiers:Sequence[str] = ()
40 _messageType:MessageType
42 def __init__( self, handling:MessageHandling, regEx:Optional[str] ):
43 if isinstance( regEx, str ):
44 regEx = re.compile( regEx )
50 def match( self, messageText:str ) -> bool:
52 Returns True if the given messageText matches the regex, and also updates the fields
53 hadMatch and hadNonMatch
55 match = self.
__isMatch__isMatch( messageText )
60 def __isMatch( self, messageText:str ) -> bool:
62 strippedMessageText = STRIP_HTML_TAGS_REGEXP.sub(
'', messageText)
63 return ( self.
__regEx__regEx.
match( strippedMessageText ) !=
None )
68 Returns the suitable postfix shown in the test report for the message type based on
73 if self.
__handling__handling == MessageHandling.IGNORE:
74 postFix =
" (ignored)"
75 elif self.
__handling__handling == MessageHandling.EXPECT:
76 postFix =
" (expected)"
80 return isinstance( other, self.__class__ )
and \
81 self.
__regEx__regEx == other.__regEx
and \
82 self.
_messageType_messageType == other._messageType
and \
93 Returns True if any of the classes' type identifiers (e.g. 'cerr') occurs in the given typeString.
94 Note that the check is case insensitive.
96 for t
in cls._typeIdentifiers:
97 if t
in typeString.lower():
104 Filter for error messages
106 _typeIdentifiers = (
"error",
"cerr" )
107 _messageType = MessageType.ERROR
108 def __init__( self, handling:MessageHandling, regEx:Optional[str] ):
113 Filter for warning messages
115 _typeIdentifiers = (
"warning", )
116 _messageType = MessageType.WARNING
117 def __init__( self, handling:MessageHandling, regEx:Optional[str] ):
122 Filter for info messages
124 _typeIdentifiers = (
"info",
"cout",
"other")
125 _messageType = MessageType.INFO
126 def __init__( self, handling:MessageHandling, regEx:Optional[str] ):
def __init__(self, MessageHandling handling, Optional[str] regEx)
def __init__(self, MessageHandling handling, Optional[str] regEx)
MessageType GetMessageType(cls)
bool IsTypeMatch(cls, str typeString)
bool __isMatch(self, str messageText)
def __init__(self, MessageHandling handling, Optional[str] regEx)
bool match(self, str messageText)
def __init__(self, MessageHandling handling, Optional[str] regEx)