當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。