本文整理汇总了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
示例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
示例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
示例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
示例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
示例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
示例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
示例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)
示例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