2023-02-19 23:41:16 +00:00
|
|
|
import random
|
|
|
|
import re
|
|
|
|
import string
|
|
|
|
|
|
|
|
ONLY_ASCII_LETTERS = string.ascii_letters
|
|
|
|
DIGITS_AND_ASCII_LETTERS = string.ascii_letters + string.digits
|
2023-03-06 16:39:03 +00:00
|
|
|
NON_DIGITS_AND_LETTERS = string.punctuation
|
2023-02-19 23:41:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def random_string(length: int = 5, source: str = ONLY_ASCII_LETTERS):
|
|
|
|
"""
|
|
|
|
Generate random string from source letters list
|
|
|
|
|
|
|
|
Args:
|
|
|
|
length: length for generated string
|
|
|
|
source: source string with letters for generate random string
|
|
|
|
Returns:
|
|
|
|
(str): random string with len == length
|
|
|
|
"""
|
|
|
|
|
2023-03-06 16:39:03 +00:00
|
|
|
return "".join(random.choice(source) for i in range(length))
|
2023-02-19 23:41:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def is_str_match_pattern(error: Exception, status_pattern: str) -> bool:
|
|
|
|
"""
|
|
|
|
Determines whether exception matches specified status pattern.
|
|
|
|
|
|
|
|
We use re.search() to be consistent with pytest.raises.
|
|
|
|
"""
|
|
|
|
match = re.search(status_pattern, str(error))
|
|
|
|
|
|
|
|
return match is not None
|