fatf.utils.testing.warnings.handle_warnings_filter_pattern

fatf.utils.testing.warnings.handle_warnings_filter_pattern(warning_filter_pattern: Union[None, str, Pattern[AnyStr]], ignore_case: bool = False) → Pattern[AnyStr][source]

Converts a patter within a warning filter into a regex pattern.

If the input pattern is None an empty (string) regex pattern is returned. A string pattern is complied directly into a regex pattern. If the input pattern is already a regex pattern it is returned without any modifications.

Parameters
warning_filter_patternUnion[None, str, Pattern]

A pattern (None, string or a regex pattern) extracted from a warning filter.

ignore_caseboolean, optional (default=False)

Should re.IGNORECASE flag be compiled into the module pattern? Defaults to False.

Returns
filter_module_regexPattern

A regular expression pattern corresponding to the input warning filter module pattern.

Raises
TypeError

The warning_filter_pattern input variable is neither of the following types: string, Pattern (re.compile) or None.

ValueError

The warning_filter_pattern input variable is a Pattern but its status of re.IGNORECASE flag does not agree with the requirement specified by the ignore_case input variable.