11from typing
import Optional, Sequence
17if "___HasLoadedMessageFilters" not in globals():
19 ___HasLoadedMessageFilters =
True
21 STRIP_HTML_TAGS_REGEXP = re.compile(
"<[^>]*>")
35 Base class to implement filters for specific log messages, allowing e.g. to expect or ignore errors.
38 _typeIdentifiers: Sequence[str] = ()
39 _messageType: MessageType
41 def __init__(self, handling: MessageHandling, regEx: Optional[str]):
42 if isinstance(regEx, str):
43 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
60 def __isMatch(self, messageText: str) -> bool:
62 strippedMessageText = STRIP_HTML_TAGS_REGEXP.sub(
"", messageText)
68 Returns the suitable postfix shown in the test report for the message type based on
74 postFix =
" (ignored)"
75 elif self.
__handling == MessageHandling.EXPECT:
76 postFix =
" (expected)"
82 and self.
__regEx == other.__regEx
94 Returns True if any of the classes' type identifiers (e.g. 'cerr') occurs in the given typeString.
95 Note that the check is case insensitive.
98 if t
in typeString.lower():
104 Filter for error messages
107 _typeIdentifiers = (
"error",
"cerr")
108 _messageType = MessageType.ERROR
110 def __init__(self, handling: MessageHandling, regEx: Optional[str]):
115 Filter for warning messages
118 _typeIdentifiers = (
"warning",)
119 _messageType = MessageType.WARNING
121 def __init__(self, handling: MessageHandling, regEx: Optional[str]):
126 Filter for info messages
129 _typeIdentifiers = (
"info",
"cout",
"other")
130 _messageType = MessageType.INFO
132 def __init__(self, handling: MessageHandling, regEx: Optional[str], allowUnexpectedMessages: bool):
Filter for error messages.
__init__(self, MessageHandling handling, Optional[str] regEx)
Filter for info messages.
__init__(self, MessageHandling handling, Optional[str] regEx, bool allowUnexpectedMessages)
Base class to implement filters for specific log messages, allowing e.g.
MessageType GetMessageType(cls)
str getTypePostfix(self)
Returns the suitable postfix shown in the test report for the message type based on self....
bool IsTypeMatch(cls, str typeString)
Returns True if any of the classes' type identifiers (e.g.
bool __isMatch(self, str messageText)
__init__(self, MessageHandling handling, Optional[str] regEx)
bool match(self, str messageText)
Returns True if the given messageText matches the regex, and also updates the fields hadMatch and had...
Filter for warning messages.
__init__(self, MessageHandling handling, Optional[str] regEx)