mock.py 文件源码

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

项目:napalm-base 作者: napalm-automation 项目源码 文件源码
def mocked_method(path, name, count):
    parent_method = getattr(NetworkDriver, name)
    parent_method_args = inspect.getargspec(parent_method)
    modifier = 0 if 'self' not in parent_method_args.args else 1

    def _mocked_method(*args, **kwargs):
        # Check len(args)
        if len(args) + len(kwargs) + modifier > len(parent_method_args.args):
            raise TypeError(
                "{}: expected at most {} arguments, got {}".format(
                    name, len(parent_method_args.args), len(args) + modifier))

        # Check kwargs
        unexpected = [x for x in kwargs if x not in parent_method_args.args]
        if unexpected:
            raise TypeError("{} got an unexpected keyword argument '{}'".format(name,
                                                                                unexpected[0]))
        return mocked_data(path, name, count)

    return _mocked_method
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号