python类nottest()的实例源码

parameterized.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def expand(cls, input):
        """ A "brute force" method of parameterizing test cases. Creates new
            test cases and injects them into the namespace that the wrapped
            function is being defined in. Useful for parameterizing tests in
            subclasses of 'UnitTest', where Nose test generators don't work.

            >>> @parameterized.expand([("foo", 1, 2)])
            ... def test_add1(name, input, expected):
            ...     actual = add1(input)
            ...     assert_equal(actual, expected)
            ...
            >>> locals()
            ... 'test_add1_foo_0': <function ...> ...
            >>>
            """

        def parameterized_expand_wrapper(f):
            stack = inspect.stack()
            frame = stack[1]
            frame_locals = frame[0].f_locals

            base_name = f.__name__
            get_input = cls.input_as_callable(input)
            for num, args in enumerate(get_input()):
                p = param.from_decorator(args)
                name_suffix = "_%s" %(num, )
                if len(p.args) > 0 and isinstance(p.args[0], six.string_types):
                    name_suffix += "_" + cls.to_safe_name(p.args[0])
                name = base_name + name_suffix
                frame_locals[name] = cls.param_as_standalone_func(p, f, name)
            return nottest(f)
        return parameterized_expand_wrapper
graphics.py 文件源码 项目:pecos 作者: sandialabs 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _nottest(afunction):
        return afunction
io.py 文件源码 项目:pecos 作者: sandialabs 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _nottest(afunction):
        return afunction


问题


面经


文章

微信
公众号

扫码关注公众号