当前位置: 首页>>代码示例>>Python>>正文


Python tools.make_decorator方法代码示例

本文整理汇总了Python中nose.tools.make_decorator方法的典型用法代码示例。如果您正苦于以下问题:Python tools.make_decorator方法的具体用法?Python tools.make_decorator怎么用?Python tools.make_decorator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nose.tools的用法示例。


在下文中一共展示了tools.make_decorator方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: assert_raises_cudnn_disabled

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import make_decorator [as 别名]
def assert_raises_cudnn_disabled():
    def test_helper(orig_test):
        @make_decorator(orig_test)
        def test_new(*args, **kwargs):
            cudnn_disabled = (os.getenv('CUDNN_OFF_TEST_ONLY') == "true")
            if not cudnn_disabled or mx.context.current_context().device_type == 'cpu':
                orig_test(*args, **kwargs)
            else:
                errors = (MXNetError, RuntimeError)
                assert_raises(errors, orig_test, *args, **kwargs)
        return test_new
    return test_helper 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:14,代码来源:common.py

示例2: transplant_func

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import make_decorator [as 别名]
def transplant_func(func, module):
    """
    Make a function imported from module A appear as if it is located
    in module B.

    >>> from pprint import pprint
    >>> pprint.__module__
    'pprint'
    >>> pp = transplant_func(pprint, __name__)
    >>> pp.__module__
    'nose.util'

    The original function is not modified.

    >>> pprint.__module__
    'pprint'

    Calling the transplanted function calls the original.

    >>> pp([1, 2])
    [1, 2]
    >>> pprint([1,2])
    [1, 2]

    """
    from nose.tools import make_decorator
    if isgenerator(func):
        def newfunc(*arg, **kw):
            for v in func(*arg, **kw):
                yield v
    else:
        def newfunc(*arg, **kw):
            return func(*arg, **kw)

    newfunc = make_decorator(func)(newfunc)
    newfunc.__module__ = module
    return newfunc 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:39,代码来源:util.py

示例3: try_gpu

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import make_decorator [as 别名]
def try_gpu(gpu_id=0):
    """Try execute on gpu, if not fallback to cpu"""
    def test_helper(orig_test):
        @make_decorator(orig_test)
        def test_wrapper(*args, **kwargs):
            try:
                a = mx.nd.zeros((1,), ctx=mx.gpu(gpu_id))
                ctx = mx.gpu(gpu_id)
            except Exception:
                ctx = mx.cpu()
            with ctx:
                orig_test(*args, **kwargs)
        return test_wrapper
    return test_helper 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:16,代码来源:common.py

示例4: with_cpu

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import make_decorator [as 别名]
def with_cpu(cpu_id=0):
    """Try execute on gpu, if not fallback to cpu"""
    def test_helper(orig_test):
        @make_decorator(orig_test)
        def test_wrapper(*args, **kwargs):
            try:
                a = mx.nd.zeros((1,), ctx=mx.cpu(cpu_id))
                ctx = mx.cpu(cpu_id)
            except Exception:
                ctx = mx.cpu(0)
            with ctx:
                orig_test(*args, **kwargs)
        return test_wrapper
    return test_helper 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:16,代码来源:common.py

示例5: regex_related

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import make_decorator [as 别名]
def regex_related(test):
    def skip_test(*args):
        raise SkipTest("Regex not supported")
    if not is_regex_supported():
        return make_decorator(test)(skip_test)
    return test 
开发者ID:italia,项目名称:daf-recipes,代码行数:8,代码来源:__init__.py

示例6: transplant_func

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import make_decorator [as 别名]
def transplant_func(func, module):
    """
    Make a function imported from module A appear as if it is located
    in module B.

    >>> from pprint import pprint
    >>> pprint.__module__
    'pprint'
    >>> pp = transplant_func(pprint, __name__)
    >>> pp.__module__
    'nose.util'

    The original function is not modified.

    >>> pprint.__module__
    'pprint'

    Calling the transplanted function calls the original.

    >>> pp([1, 2])
    [1, 2]
    >>> pprint([1,2])
    [1, 2]

    """
    from nose.tools import make_decorator
    def newfunc(*arg, **kw):
        return func(*arg, **kw)

    newfunc = make_decorator(func)(newfunc)
    newfunc.__module__ = module
    return newfunc 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:34,代码来源:util.py

示例7: python3only

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import make_decorator [as 别名]
def python3only(func):
    name = func.__name__

    def newfunc(*arg, **kw):
        if sys.version_info[0] == 3:
            func(*arg, **kw)
    newfunc = make_decorator(func)(newfunc)
    return newfunc 
开发者ID:FFIG,项目名称:ffig,代码行数:10,代码来源:test_type_hints_in_bindings.py

示例8: mock_actions

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import make_decorator [as 别名]
def mock_actions(func):
    '''
    Decorator that mocks actions used by these tests
    Based on ckan.test.helpers.mock_action
    '''
    def wrapper(*args, **kwargs):
        # Mock CKAN's resource_show API
        from ckan.logic import get_action as original_get_action

        def side_effect(called_action_name):
            if called_action_name == 'resource_show':
                def mock_resource_show(context, data_dict):
                    return {
                       'id': data_dict['id'],
                       'name': 'short name',
                       'url': SOURCE_URL,
                       'format': '',
                       'package_id': 'test-pkg',
                    }
                return mock_resource_show
            elif called_action_name == 'package_show':
                def mock_package_show(context, data_dict):
                    return {
                       'id': data_dict['id'],
                       'name': 'pkg-name',
                    }
                return mock_package_show
            else:
                return original_get_action(called_action_name)
        try:
            with mock.patch('ckanext.xloader.jobs.get_action') as mock_get_action:
                mock_get_action.side_effect = side_effect

                return_value = func(*args, **kwargs)
        finally:
            pass
            # Make sure to stop the mock, even with an exception
            # mock_action.stop()
        return return_value

    return make_decorator(func)(wrapper) 
开发者ID:ckan,项目名称:ckanext-xloader,代码行数:43,代码来源:test_jobs.py

示例9: remove_logdir

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import make_decorator [as 别名]
def remove_logdir():
    def test_helper(orig_test):
        @make_decorator(orig_test)
        def test_new(*args, **kwargs):
            _remove_logdir_impl()
            try:
                orig_test(*args, **kwargs)
            except:
                raise
        return test_new
    return test_helper 
开发者ID:awslabs,项目名称:mxboard,代码行数:13,代码来源:test_logging.py


注:本文中的nose.tools.make_decorator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。