def __new__(cls, expectation=None, strcmp=None, is_custom_func=False):
"""
Args:
anything (expectation: the object you want to compare)
"substring", "regex" (strcmp: the type of string comparsion)
Boolean (is_custom_func: set True is object is a test function of Matcher
Return:
Matcher
"""
options = {}
if is_custom_func:
if isinstance(expectation, (FunctionType, BuiltinFunctionType, MethodType)):
options["is_custom_func"] = True
else:
# Todo: customized error exception
raise TypeError("[{}] is not callable".format(expectation))
if strcmp:
if isinstance(expectation, (str, unicode)):
if strcmp.upper() == "DEFAULT" or strcmp.upper() == "SUBSTRING":
options["is_substring"] = True
elif strcmp.upper() == "REGEX":
options["is_regex"] = True
else:
raise TypeError("[{}] is not a string".format(expectation))
return Matcher(expectation, options)
评论列表
文章目录