Add a test setup helper function

Add a function to set up a skimage test

Switch to new test helper function

Import local packages that raise warnings in test setup function

More fixes to doctests

Fix regionprops doc test

Try and fix the test_rank failure.

Remove no longer needed RectangleSelector shim

Skip more doctests in _regionprops

Try importing another scipy subpackage
This commit is contained in:
Steven Silvester
2014-12-21 15:43:23 -06:00
parent f72882fbd2
commit 4680f30466
24 changed files with 57 additions and 72 deletions
+7
View File
@@ -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')
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+3 -3
View File
@@ -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:
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+1 -1
View File
@@ -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
'''
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+3 -3
View File
@@ -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]]
+4 -4
View File
@@ -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)
"""
+3 -2
View File
@@ -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():
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()
+2 -8
View File
@@ -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"""
+2 -3
View File
@@ -1,3 +1,2 @@
import warnings
from scipy import ndimage, special, optimize
warnings.simplefilter('error')
from skimage._shared.testing import setup_test
setup_test()