本文整理汇总了Python中nose.tools.make_decorator函数的典型用法代码示例。如果您正苦于以下问题:Python make_decorator函数的具体用法?Python make_decorator怎么用?Python make_decorator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_decorator函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: needs_reflink_fs
def needs_reflink_fs(test):
def no_support(*args):
raise SkipTest("btrfs not supported")
def not_reflink_fs(*args):
raise SkipTest("testdir is not on reflink-capable filesystem")
if not has_feature('btrfs-support'):
return make_decorator(test)(no_support)
elif not is_on_reflink_fs(TESTDIR_NAME):
return make_decorator(test)(not_reflink_fs)
else:
return test
开发者ID:sahib,项目名称:rmlint,代码行数:13,代码来源:test_dedupe.py
示例2: decorator
def decorator(func):
def timed_out(_signum, frame):
raise TestTimedOut(time_limit, frame)
def newfunc(*args, **kwargs):
try:
# Will only work on unix systems
orig_handler = signal.signal(signal.SIGALRM, timed_out)
signal.alarm(time_limit)
except AttributeError:
pass
try:
rc = func(*args, **kwargs)
finally:
try:
# Will only work on unix systems
signal.alarm(0)
signal.signal(signal.SIGALRM, orig_handler)
except AttributeError:
pass
return rc
newfunc = make_decorator(func)(newfunc)
return newfunc
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:25,代码来源:base.py
示例3: dec
def dec(in_func):
if cond:
def wrapper():
raise nose.SkipTest(msg)
return make_decorator(in_func)(wrapper)
else:
return in_func
开发者ID:vivekthampy,项目名称:scikit-beam,代码行数:7,代码来源:decorators.py
示例4: transplant_func
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:jpellerin,项目名称:nose,代码行数:32,代码来源:util.py
示例5: regex_related
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:MrkGrgsn,项目名称:ckan,代码行数:7,代码来源:__init__.py
示例6: dec
def dec(in_func):
# make the wrapper function
# if the condition is True
if cond:
def inner_wrap():
# try the test anywoy
try:
in_func()
# when in fails, raises KnownFailureTest
# which is registered with nose and it will be marked
# as K in the results
except Exception:
raise KnownFailureTest()
# if it does not fail, raise KnownFailureDidNotFailTest which
# is a normal exception. This may seem counter-intuitive
# but knowing when tests that _should_ fail don't can be useful
else:
raise KnownFailureDidNotFailTest()
# use `make_decorator` from nose to make sure that the meta-data on
# the function is forwarded properly (name, teardown, setup, etc)
return make_decorator(in_func)(inner_wrap)
# if the condition is false, don't make a wrapper function
# this is effectively a no-op
else:
return in_func
开发者ID:iTerminate,项目名称:scikit-xray,代码行数:28,代码来源:decorators.py
示例7: decorator
def decorator(func):
# Wrap the test function to call, but with a timeout
def wrapper(*args, **kwargs):
# First, install the SIGALRM signal handler
prev_hndlr = signal.signal(signal.SIGALRM, handler)
try:
# Set up the alarm
signal.alarm(timeout)
# Run the test function
result = func(*args, **kwargs)
finally:
# Stop the alarm
signal.alarm(0)
# Restore the signal handler
signal.signal(signal.SIGALRM, prev_hndlr)
# Return the result
return result
# Replace func with wrapper
wrapper = tools.make_decorator(func)(wrapper)
return wrapper
开发者ID:Cerberus98,项目名称:backfire,代码行数:25,代码来源:adaptor_nose.py
示例8: decorate
def decorate(func):
def newfunc(*arg, **kwargs):
timer = Timer(limit, handler)
try:
log.debug('starting timer in %s for %s',
str(datetime.datetime.now()), str(limit))
timer.start()
ret = func(*arg, **kwargs)
except KeyboardInterrupt:
if timer.isAlive:
timer.cancel()
raise
except:
if timer.isAlive():
timer.cancel()
log.debug('canceled timer in %s because of failure',
str(datetime.datetime.now()))
raise
else:
raise TimeExpired, 'Time expired ( and test raised: ' \
+ str(sys.exc_info()) + ')', sys.exc_info()[2]
if timer.isAlive():
timer.cancel()
log.debug('canceled timer in %s', str(datetime.datetime.now()))
else:
log.debug('timer has expired', str(datetime.datetime.now()))
raise TimeExpired("time limit exceeded")
return ret
newfunc = make_decorator(func)(newfunc)
return newfunc
开发者ID:snua12,项目名称:zlomekfs,代码行数:30,代码来源:timeoutPlugin.py
示例9: decorate
def decorate(func):
def newfunc(*arg, **kwargs):
mvpa2.seed(mvpa2._random_seed)
return func(*arg, **kwargs)
newfunc = make_decorator(func)(newfunc)
return newfunc
开发者ID:schoeke,项目名称:PyMVPA,代码行数:7,代码来源:tools.py
示例10: decorate
def decorate(func):
def newfunc(*arg, **kw):
port = random.randint(8000, 8500)
# TODO: ATM we are relying on path being local so we could
# start HTTP server in the same directory. FIX IT!
SocketServer.TCPServer.allow_reuse_address = True
httpd = SocketServer.TCPServer(("", port), SilentHTTPHandler)
server_thread = Thread(target=httpd.serve_forever)
arg, path = arg[:-1], arg[-1]
# There is a problem with Haskell on wheezy trying to
# fetch via IPv6 whenever there is a ::1 localhost entry in
# /etc/hosts. Apparently fixing that docker image reliably
# is not that straightforward, although see
# http://jasonincode.com/customizing-hosts-file-in-docker/
# so we just force to use 127.0.0.1 while on wheezy
hostname = '127.0.0.1' if on_debian_wheezy else 'localhost'
url = 'http://%s:%d/%s/' % (hostname, port, path)
lgr.debug("HTTP: serving %s under %s", path, url)
server_thread.start()
#time.sleep(1) # just give it few ticks
try:
func(*(arg + (path, url,)), **kw)
finally:
lgr.debug("HTTP: stopping server")
httpd.shutdown()
server_thread.join()
newfunc = make_decorator(func)(newfunc)
return newfunc
开发者ID:jgors,项目名称:datalad,代码行数:29,代码来源:utils.py
示例11: snapshot
def snapshot(f):
"Takes an MD5 snapshot of video for test acceptance"
@wraps(f)
def wrapper(*args, **kwargs):
filename = f(*args, **kwargs)
snapshot_name = f.func_name
print "snapshot:", snapshot_name
snapshot_filename = os.path.join(snapshot_dir, snapshot_name)
snapshot_md5_filename = snapshot_filename + '.md5'
snapshot_mov_filename = snapshot_filename + '.mov'
# Do we have an existing snapshot in snapshots directory?
if not os.path.exists(snapshot_md5_filename):
prompt_compare(snapshot_mov_filename, snapshot_md5_filename,
filename)
else:
# otherwise we have a snapshot
sample_md5 = md5sum(filename)
snapshot_md5 = file(snapshot_md5_filename).read()
if sample_md5 == snapshot_md5:
print "snapshot: success, they are the same!"
else:
prompt_compare(snapshot_mov_filename,
snapshot_md5_filename, filename)
if os.path.exists(filename):
print "snapshot: removing", filename
os.remove(filename)
wrapper = make_decorator(f)(wrapper)
return wrapper
开发者ID:kornelpro51,项目名称:nsextreme,代码行数:28,代码来源:util.py
示例12: hash_setup
def hash_setup(test):
def hash_test():
sys.stdout = output = io.BytesIO()
test_hash = test()
output.seek(0)
test_hash = hashlib.md5(output.read()).hexdigest()
output.close()
# Get the true hash
try:
true_hash_file = open(test.__name__ + '.hash', 'r')
except IOError:
# File doesn't exist because it's a new test and there's no
# true hash file
true_hash_file = open(test.__name__ + '.hash', 'w')
true_hash_file.write(test_hash + '\n')
true_hash_file.close()
true_hash_file = open(test.__name__ + '.hash', 'r')
raise NewTestError("New test found. Run again.")
true_hash = true_hash_file.read().strip()
true_hash_file.close()
assert true_hash == test_hash, 'Test "{}" failed with hash {}'.format(
test.__name__, test_hash)
return make_decorator(test)(hash_test)
开发者ID:dmcdougall,项目名称:mpl_binutils,代码行数:29,代码来源:test.py
示例13: search_related
def search_related(test):
def skip_test(*args):
raise SkipTest("Search not supported")
if not is_search_supported():
return make_decorator(test)(skip_test)
return test
开发者ID:netconstructor,项目名称:ckan,代码行数:7,代码来源:__init__.py
示例14: skip
def skip(f):
""" Decorator to indicate a test should be skipped.
"""
def g(*args, **kw):
raise SkipTest()
return make_decorator(f)(g)
开发者ID:enthought,项目名称:traits,代码行数:8,代码来源:nose_tools.py
示例15: deprecated
def deprecated(f):
""" Decorator to indicate a test is deprecated.
"""
def g(*args, **kw):
raise DeprecatedTest()
return make_decorator(f)(g)
开发者ID:enthought,项目名称:traits,代码行数:8,代码来源:nose_tools.py
示例16: requires_login
def requires_login(fn):
def __requires_login(*args, **kwargs):
cls = args[0]
cls.relogin()
fn(*args, **kwargs)
__requires_login = make_decorator(fn)(__requires_login)
return __requires_login
开发者ID:happz,项目名称:settlers,代码行数:8,代码来源:__init__.py
示例17: use_tdb
def use_tdb(func):
def new_func(*a, **kw):
connect_to_test_db()
flush_mongo()
func(*a, **kw)
flush_mongo()
return make_decorator(func)(new_func)
开发者ID:RomanAnikienko,项目名称:django-mongo-comments,代码行数:8,代码来源:test.py
示例18: compare_images_decorator
def compare_images_decorator(func):
import inspect
_file = inspect.getfile(func)
def decorated():
func()
for fignum, baseline in zip(plt.get_fignums(), baseline_images):
figure = plt.figure(fignum)
_assert_same_figure_images(figure, baseline, _file, tol=tol)
# also use the cleanup decorator!
return make_decorator(cleanup(func))(decorated)
开发者ID:janschulz,项目名称:ggplot,代码行数:10,代码来源:__init__.py
示例19: elapsed
def elapsed(func):
"""
Useful decorator to print out the elapsed time for a unit test.
"""
def call_elapsed(*args, **kwargs):
start_time = time.time()
func(*args, **kwargs)
sys.__stdout__.write('Time elapsed: %s'
% (time.time() - start_time,))
return make_decorator(func)(call_elapsed)
开发者ID:BigData-Tools,项目名称:everest,代码行数:10,代码来源:testing.py
示例20: decorate
def decorate(func):
def newfunc(*arg, **kw):
import time
start = time.time()
ret = func(*arg, **kw)
end = time.time()
sys.stderr.write('%s took %2fs\n' % (func.__name__, end - start))
return ret
newfunc = make_decorator(func)(newfunc)
return newfunc
开发者ID:jdp,项目名称:taxon,代码行数:10,代码来源:context.py
注:本文中的nose.tools.make_decorator函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论