matcher.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:sinon 作者: note35 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号