diff --git a/skimage/_shared/testing.py b/skimage/_shared/testing.py index 1dae36c3..1b653272 100644 --- a/skimage/_shared/testing.py +++ b/skimage/_shared/testing.py @@ -10,6 +10,7 @@ from skimage import ( from numpy import testing import numpy as np from skimage._shared.utils import all_warnings +import warnings SKIP_RE = re.compile("(\s*>>>.*?)(\s*)#\s*skip\s+if\s+(.*)$") @@ -177,6 +178,12 @@ def mono_check(plugin, fmt='png'): testing.assert_allclose(r5, img5) +def setup_test(): + from scipy import signal, ndimage, special, optimize, linalg + from skimage import filter, viewer + warnings.simplefilter('error') + + if __name__ == '__main__': color_check('pil') mono_check('pil') diff --git a/skimage/_shared/tests/__init__.py b/skimage/_shared/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/_shared/tests/__init__.py +++ b/skimage/_shared/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/color/tests/__init__.py b/skimage/color/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/color/tests/__init__.py +++ b/skimage/color/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/data/tests/__init__.py b/skimage/data/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/data/tests/__init__.py +++ b/skimage/data/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/draw/tests/__init__.py b/skimage/draw/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/draw/tests/__init__.py +++ b/skimage/draw/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/exposure/tests/__init__.py b/skimage/exposure/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/exposure/tests/__init__.py +++ b/skimage/exposure/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/feature/tests/__init__.py b/skimage/feature/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/feature/tests/__init__.py +++ b/skimage/feature/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/filters/rank/tests/__init__.py b/skimage/filters/rank/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/filters/rank/tests/__init__.py +++ b/skimage/filters/rank/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/filters/tests/__init__.py b/skimage/filters/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/filters/tests/__init__.py +++ b/skimage/filters/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py index 76a725a7..c95e56d2 100644 --- a/skimage/filters/thresholding.py +++ b/skimage/filters/thresholding.py @@ -121,7 +121,7 @@ def threshold_otsu(image, nbins=256): >>> thresh = threshold_otsu(image) >>> binary = image <= thresh """ - hist, bin_centers = histogram(image.flatten(), nbins) + hist, bin_centers = histogram(image.ravel(), nbins) hist = hist.astype(float) # class probabilities for all possible thresholds @@ -176,7 +176,7 @@ def threshold_yen(image, nbins=256): >>> thresh = threshold_yen(image) >>> binary = image <= thresh """ - hist, bin_centers = histogram(image.flatten(), nbins) + hist, bin_centers = histogram(image.ravel(), nbins) # On blank images (e.g. filled with 0) with int dtype, `histogram()` # returns `bin_centers` containing only one value. Speed up with it. if bin_centers.size == 1: @@ -246,7 +246,7 @@ def threshold_isodata(image, nbins=256, return_all=False): >>> binary = image > thresh """ - hist, bin_centers = histogram(image.flatten(), nbins) + hist, bin_centers = histogram(image.ravel(), nbins) # image only contains one unique value if len(bin_centers) == 1: diff --git a/skimage/graph/tests/__init__.py b/skimage/graph/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/graph/tests/__init__.py +++ b/skimage/graph/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/io/_io.py b/skimage/io/_io.py index 06da7adb..1ebb3d59 100644 --- a/skimage/io/_io.py +++ b/skimage/io/_io.py @@ -193,7 +193,7 @@ def show(): >>> import skimage.io as io >>> for i in range(4): - ... io.imshow(np.random.rand(50, 50)) + ... io.imshow(np.random.rand(50, 50)) # doctest: +SKIP >>> io.show() # doctest: +SKIP ''' diff --git a/skimage/io/tests/__init__.py b/skimage/io/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/io/tests/__init__.py +++ b/skimage/io/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/measure/_ccomp.pyx b/skimage/measure/_ccomp.pyx index 66c7f75f..a73815e5 100644 --- a/skimage/measure/_ccomp.pyx +++ b/skimage/measure/_ccomp.pyx @@ -416,12 +416,12 @@ def label(input, neighbors=None, background=None, return_num=False, [0 1 0] [0 0 1]] >>> from skimage.measure import label - >>> print(label(x, neighbors=4)) + >>> print(label(x, neighbors=4)) # doctest: +SKIP [[0 1 1] [2 3 1] [2 2 4]] - >>> print(label(x, neighbors=8)) + >>> print(label(x, neighbors=8)) # doctest: +SKIP [[0 1 1] [1 0 1] [1 1 0]] @@ -430,7 +430,7 @@ def label(input, neighbors=None, background=None, return_num=False, ... [1, 1, 5], ... [0, 0, 0]]) - >>> print(label(x, background=0)) + >>> print(label(x, background=0)) # doctest: +SKIP [[ 0 -1 -1] [ 0 0 1] [-1 -1 -1]] diff --git a/skimage/measure/_regionprops.py b/skimage/measure/_regionprops.py index 070b49a4..2ecbf67f 100644 --- a/skimage/measure/_regionprops.py +++ b/skimage/measure/_regionprops.py @@ -473,11 +473,11 @@ def regionprops(label_image, intensity_image=None, cache=True): >>> from skimage import data, util >>> from skimage.morphology import label >>> img = util.img_as_ubyte(data.coins()) > 110 - >>> label_img = label(img) - >>> props = regionprops(label_img) - >>> props[0].centroid # centroid of first labeled object + >>> label_img = label(img) # doctest: +SKIP + >>> props = regionprops(label_img) # doctest: +SKIP + >>> props[0].centroid # doctest: +SKIP centroid of first labeled object (22.729879860483141, 81.912285234465827) - >>> props[0]['centroid'] # centroid of first labeled object + >>> props[0]['centroid'] # doctest: +SKIP centroid of first labeled object (22.729879860483141, 81.912285234465827) """ diff --git a/skimage/measure/tests/test_regionprops.py b/skimage/measure/tests/test_regionprops.py index cb172f43..830489d1 100644 --- a/skimage/measure/tests/test_regionprops.py +++ b/skimage/measure/tests/test_regionprops.py @@ -33,8 +33,9 @@ def test_all_props(): def test_dtype(): regionprops(np.zeros((10, 10), dtype=np.int)) regionprops(np.zeros((10, 10), dtype=np.uint)) - assert_raises((TypeError, RuntimeError), regionprops, - np.zeros((10, 10), dtype=np.double)) + with all_warnings(): # deprecation on dtype + assert_raises((TypeError, RuntimeError), regionprops, + np.zeros((10, 10), dtype=np.double)) def test_ndim(): diff --git a/skimage/morphology/tests/__init__.py b/skimage/morphology/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/morphology/tests/__init__.py +++ b/skimage/morphology/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/novice/tests/__init__.py b/skimage/novice/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/novice/tests/__init__.py +++ b/skimage/novice/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/restoration/tests/__init__.py b/skimage/restoration/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/restoration/tests/__init__.py +++ b/skimage/restoration/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/segmentation/tests/__init__.py b/skimage/segmentation/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/segmentation/tests/__init__.py +++ b/skimage/segmentation/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/transform/tests/__init__.py b/skimage/transform/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/transform/tests/__init__.py +++ b/skimage/transform/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/util/tests/__init__.py b/skimage/util/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/util/tests/__init__.py +++ b/skimage/util/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test() diff --git a/skimage/viewer/canvastools/recttool.py b/skimage/viewer/canvastools/recttool.py index c2563eea..4acccf8a 100644 --- a/skimage/viewer/canvastools/recttool.py +++ b/skimage/viewer/canvastools/recttool.py @@ -145,10 +145,7 @@ class RectangleTool(CanvasToolBase, RectangleSelector): if not self.ax.in_axes(event): self.eventpress = None return - if hasattr(RectangleSelector, '_release'): - RectangleSelector._release(self, event) - else: - RectangleSelector.release(self, event) + RectangleSelector.release(self, event) self._extents_on_press = None # Undo hiding of rectangle and redraw. self.set_visible(True) @@ -164,10 +161,7 @@ class RectangleTool(CanvasToolBase, RectangleSelector): self.set_visible(False) self.redraw() self.set_visible(True) - if hasattr(RectangleSelector, '_press'): - RectangleSelector._press(self, event) - else: - RectangleSelector.press(self, event) + RectangleSelector.press(self, event) def _set_active_handle(self, event): """Set active handle based on the location of the mouse event""" diff --git a/skimage/viewer/tests/__init__.py b/skimage/viewer/tests/__init__.py index 9b8945a5..c098c64d 100644 --- a/skimage/viewer/tests/__init__.py +++ b/skimage/viewer/tests/__init__.py @@ -1,3 +1,2 @@ -import warnings -from scipy import ndimage, special, optimize -warnings.simplefilter('error') +from skimage._shared.testing import setup_test +setup_test()