(glob=None, regex=None, match_case=None)
| 69 | |
| 70 | |
| 71 | def get_pattern(glob=None, regex=None, match_case=None): |
| 72 | assert glob is not None or regex is not None |
| 73 | |
| 74 | if glob is not None and regex is not None: |
| 75 | raise ValueError( |
| 76 | "You should specify at most one of `glob` and `regex` parameters but not both" |
| 77 | ) |
| 78 | |
| 79 | if glob is not None: |
| 80 | pattern = glob_to_regex(glob) |
| 81 | else: # regex is not None |
| 82 | if match_case is not None and not isinstance(regex, str): |
| 83 | raise ValueError( |
| 84 | "Regex must be a string if `match_case` is specified when " |
| 85 | "calling assert_raises_pattern" |
| 86 | ) |
| 87 | pattern = regex |
| 88 | |
| 89 | if isinstance(pattern, str) and not match_case: # ignore case by default |
| 90 | pattern = re.compile(pattern, re.IGNORECASE) |
| 91 | |
| 92 | return pattern |
| 93 | |
| 94 | |
| 95 | def assert_raises(exception, *args, glob=None, regex=None, match_case=None, **kwargs): |
no test coverage detected