mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-13 17:45:20 +08:00
Add decorator to test parallel execution of unit test
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
import functools
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from numpy import testing
|
||||
@@ -201,6 +203,37 @@ def teardown_test():
|
||||
warnings.simplefilter('default')
|
||||
|
||||
|
||||
def test_parallel(num_threads=2):
|
||||
"""Decorator to run the same function multiple times in parallel.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
num_threads : int, optional
|
||||
The number of times the function is run in parallel.
|
||||
|
||||
Notes
|
||||
-----
|
||||
This decorator does not pass the return value of the decorated function.
|
||||
|
||||
"""
|
||||
|
||||
assert num_threads > 0
|
||||
|
||||
def wrapper(func):
|
||||
@functools.wraps(func)
|
||||
def inner(*args, **kwargs):
|
||||
threads = []
|
||||
for i in range(num_threads):
|
||||
thread = threading.Thread(target=func, args=args, kwargs=kwargs)
|
||||
threads.append(thread)
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
return inner
|
||||
return wrapper
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
color_check('pil')
|
||||
mono_check('pil')
|
||||
|
||||
@@ -197,7 +197,7 @@ def test_swirl():
|
||||
image = img_as_float(data.checkerboard())
|
||||
|
||||
swirl_params = {'radius': 80, 'rotation': 0, 'order': 2, 'mode': 'reflect'}
|
||||
|
||||
|
||||
with expected_warnings(['Bi-quadratic.*bug']):
|
||||
swirled = tf.swirl(image, strength=10, **swirl_params)
|
||||
unswirled = tf.swirl(swirled, strength=-10, **swirl_params)
|
||||
|
||||
Reference in New Issue
Block a user