diff --git a/skimage/_shared/_warnings.py b/skimage/_shared/_warnings.py index cf9df84a..fd2c06a0 100644 --- a/skimage/_shared/_warnings.py +++ b/skimage/_shared/_warnings.py @@ -1,4 +1,4 @@ -__all__ = ['all_warnings'] +__all__ = ['all_warnings', 'expected_warnings'] from contextlib import contextmanager import sys @@ -90,14 +90,16 @@ def expected_warnings(matching): """ with all_warnings() as w: yield w - remaining = matching + remaining = [m for m in matching] for warn in w: found = False for match in matching: if re.search(match, str(warn.message)) is not None: found = True - remaining.remove(match) + if match in remaining: + remaining.remove(match) if not found: raise ValueError('Unexpected warning: %s' % str(warn.message)) if len(remaining) > 0: - raise ValueError('No warning raised matching: "%s"' % remaining[0]) + msg = 'No warning raised matching:\n%s' % '\n'.join(remaining) + raise ValueError(msg) diff --git a/skimage/_shared/testing.py b/skimage/_shared/testing.py index 6b09a7bd..e5ca2f87 100644 --- a/skimage/_shared/testing.py +++ b/skimage/_shared/testing.py @@ -9,7 +9,7 @@ from skimage import ( data, io, img_as_uint, img_as_float, img_as_int, img_as_ubyte) from numpy import testing import numpy as np -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings import warnings @@ -117,24 +117,24 @@ def color_check(plugin, fmt='png'): testing.assert_allclose(img2.astype(np.uint8), r2) img3 = img_as_float(img) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): r3 = roundtrip(img3, plugin, fmt) testing.assert_allclose(r3, img) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): img4 = img_as_int(img) if fmt.lower() in (('tif', 'tiff')): img4 -= 100 - with all_warnings(): # sign loss + with expected_warnings(['sign loss']): r4 = roundtrip(img4, plugin, fmt) testing.assert_allclose(r4, img4) else: - with all_warnings(): # sign loss + with expected_warnings(['sign loss']): r4 = roundtrip(img4, plugin, fmt) testing.assert_allclose(r4, img_as_ubyte(img4)) img5 = img_as_uint(img) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): r5 = roundtrip(img5, plugin, fmt) testing.assert_allclose(r5, img) @@ -154,22 +154,22 @@ def mono_check(plugin, fmt='png'): testing.assert_allclose(img2.astype(np.uint8), r2) img3 = img_as_float(img) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): r3 = roundtrip(img3, plugin, fmt) if r3.dtype.kind == 'f': testing.assert_allclose(img3, r3) else: testing.assert_allclose(r3, img_as_uint(img)) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): img4 = img_as_int(img) if fmt.lower() in (('tif', 'tiff')): img4 -= 100 - with all_warnings(): # sign loss + with expected_warnings(['sign loss']): r4 = roundtrip(img4, plugin, fmt) testing.assert_allclose(r4, img4) else: - with all_warnings(): # sign loss + with expected_warnings(['sign loss']): r4 = roundtrip(img4, plugin, fmt) testing.assert_allclose(r4, img_as_uint(img4)) @@ -188,9 +188,7 @@ def setup_test(): warnings.simplefilter('default') from scipy import signal, ndimage, special, optimize, linalg from scipy.io import loadmat - from skimage import filter, viewer, data - # trigger PIL warnings - data.moon() + from skimage import viewer, filter np.random.seed(0) warnings.simplefilter('error') diff --git a/skimage/_shared/tests/__init__.py b/skimage/_shared/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/_shared/tests/__init__.py +++ b/skimage/_shared/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/color/tests/__init__.py b/skimage/color/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/color/tests/__init__.py +++ b/skimage/color/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/color/tests/test_adapt_rgb.py b/skimage/color/tests/test_adapt_rgb.py index f4da0e58..9e97b6b6 100644 --- a/skimage/color/tests/test_adapt_rgb.py +++ b/skimage/color/tests/test_adapt_rgb.py @@ -5,7 +5,7 @@ import numpy as np from skimage import img_as_float, img_as_uint from skimage import color, data, filters from skimage.color.adapt_rgb import adapt_rgb, each_channel, hsv_value -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings # Down-sample image for quicker testing. COLOR_IMAGE = data.astronaut()[::5, ::5] @@ -38,7 +38,7 @@ def smooth_hsv(image, sigma): @adapt_rgb(hsv_value) def edges_hsv_uint(image): - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): return img_as_uint(filters.sobel(image)) diff --git a/skimage/color/tests/test_colorconv.py b/skimage/color/tests/test_colorconv.py index c61a67b2..094873ae 100644 --- a/skimage/color/tests/test_colorconv.py +++ b/skimage/color/tests/test_colorconv.py @@ -40,12 +40,10 @@ from skimage.color import (rgb2hsv, hsv2rgb, ) from skimage import data_dir -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings import colorsys -np.random.seed(0) - def test_guess_spatial_dimensions(): im1 = np.zeros((5, 5)) @@ -157,7 +155,7 @@ class TestColorconv(TestCase): # RGB<->HED roundtrip with ubyte image def test_hed_rgb_roundtrip(self): img_rgb = img_as_ubyte(self.img_rgb) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): new = img_as_ubyte(hed2rgb(rgb2hed(img_rgb))) assert_equal(new, img_rgb) diff --git a/skimage/color/tests/test_colorlabel.py b/skimage/color/tests/test_colorlabel.py index 4daf3a66..277cec5b 100644 --- a/skimage/color/tests/test_colorlabel.py +++ b/skimage/color/tests/test_colorlabel.py @@ -3,7 +3,7 @@ import itertools import numpy as np from numpy import testing from skimage.color.colorlabel import label2rgb -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings from numpy.testing import (assert_array_almost_equal as assert_close, assert_array_equal, assert_warns) @@ -125,10 +125,9 @@ def test_avg(): def test_negative_intensity(): - with all_warnings(): - labels = np.arange(100).reshape(10, 10) - image = -1 * np.ones((10, 10)) - assert_warns(UserWarning, label2rgb, labels, image) + labels = np.arange(100).reshape(10, 10) + image = -1 * np.ones((10, 10)) + assert_warns(UserWarning, label2rgb, labels, image) if __name__ == '__main__': diff --git a/skimage/data/tests/__init__.py b/skimage/data/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/data/tests/__init__.py +++ b/skimage/data/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/draw/tests/__init__.py b/skimage/draw/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/draw/tests/__init__.py +++ b/skimage/draw/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/exposure/tests/__init__.py b/skimage/exposure/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/exposure/tests/__init__.py +++ b/skimage/exposure/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/exposure/tests/test_exposure.py b/skimage/exposure/tests/test_exposure.py index bb047195..5a3d3dba 100644 --- a/skimage/exposure/tests/test_exposure.py +++ b/skimage/exposure/tests/test_exposure.py @@ -11,7 +11,7 @@ from skimage import exposure from skimage.exposure.exposure import intensity_range from skimage.color import rgb2gray from skimage.util.dtype import dtype_range -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings # Test integer histograms @@ -53,7 +53,7 @@ def test_equalize_uint8_approx(): def test_equalize_ubyte(): - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): img = skimage.img_as_ubyte(test_img) img_eq = exposure.equalize_hist(img) @@ -211,7 +211,7 @@ def test_adapthist_grayscale(): img = skimage.img_as_float(data.astronaut()) img = rgb2gray(img) img = np.dstack((img, img, img)) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): adapted = exposure.equalize_adapthist(img, 10, 9, clip_limit=0.01, nbins=128) assert_almost_equal = np.testing.assert_almost_equal @@ -229,7 +229,7 @@ def test_adapthist_color(): warnings.simplefilter('always') hist, bin_centers = exposure.histogram(img) assert len(w) > 0 - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): adapted = exposure.equalize_adapthist(img, clip_limit=0.01) assert_almost_equal = np.testing.assert_almost_equal @@ -248,7 +248,7 @@ def test_adapthist_alpha(): img = skimage.img_as_float(data.astronaut()) alpha = np.ones((img.shape[0], img.shape[1]), dtype=float) img = np.dstack((img, alpha)) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): adapted = exposure.equalize_adapthist(img) assert adapted.shape != img.shape img = img[:, :, :3] diff --git a/skimage/feature/tests/__init__.py b/skimage/feature/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/feature/tests/__init__.py +++ b/skimage/feature/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/filters/tests/test_gaussian.py b/skimage/filters/tests/test_gaussian.py index 01e1c12e..c88ee1f8 100644 --- a/skimage/filters/tests/test_gaussian.py +++ b/skimage/filters/tests/test_gaussian.py @@ -1,6 +1,6 @@ import numpy as np from skimage.filters._gaussian import gaussian_filter -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings def test_null_sigma(): @@ -26,7 +26,7 @@ def test_multichannel(): assert np.allclose([a[..., i].mean() for i in range(3)], [gaussian_rgb_a[..., i].mean() for i in range(3)]) # Test multichannel = None - with all_warnings(): # multichannel + with expected_warnings(['multichannel']): gaussian_rgb_a = gaussian_filter(a, sigma=1, mode='reflect') # Check that the mean value is conserved in each channel # (color channels are not mixed together) diff --git a/skimage/graph/tests/__init__.py b/skimage/graph/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/graph/tests/__init__.py +++ b/skimage/graph/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/io/_plugins/pil_plugin.py b/skimage/io/_plugins/pil_plugin.py index cdaea687..9f9118cf 100644 --- a/skimage/io/_plugins/pil_plugin.py +++ b/skimage/io/_plugins/pil_plugin.py @@ -7,7 +7,6 @@ from PIL import Image from skimage.util import img_as_ubyte, img_as_uint from skimage.external.tifffile import ( imread as tif_imread, imsave as tif_imsave) -from skimage._shared._warnings import expected_warnings def imread(fname, dtype=None, img_num=None, **kwargs): @@ -48,8 +47,7 @@ def imread(fname, dtype=None, img_num=None, **kwargs): im = Image.open(fname) try: # this will raise an IOError if the file is not readable - with expected_warnings(['unclosed file']): - im.getdata()[0] + im.getdata()[0] except IOError: site = "http://pillow.readthedocs.org/en/latest/installation.html#external-libraries" raise ValueError('Could not load "%s"\nPlease see documentation at: %s' % (fname, site)) diff --git a/skimage/io/tests/__init__.py b/skimage/io/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/io/tests/__init__.py +++ b/skimage/io/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/io/tests/test_pil.py b/skimage/io/tests/test_pil.py index 832ea13e..2d58e3e9 100644 --- a/skimage/io/tests/test_pil.py +++ b/skimage/io/tests/test_pil.py @@ -10,16 +10,18 @@ from skimage import data_dir from skimage.io import (imread, imsave, use_plugin, reset_plugins, Image as ioImage) from skimage._shared.testing import mono_check, color_check -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings from six import BytesIO from PIL import Image from skimage.io._plugins.pil_plugin import ( pil_to_ndarray, ndarray_to_pil, _palette_is_grayscale) -use_plugin('pil') -np.random.seed(0) + + +def setup(): + use_plugin('pil') def teardown(): @@ -144,7 +146,7 @@ def test_imsave_filelike(): s = BytesIO() # save to file-like object - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): imsave(s, image) # read from file-like object @@ -157,7 +159,7 @@ def test_imsave_filelike(): def test_imexport_imimport(): shape = (2, 2) image = np.zeros(shape) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): pil_image = ndarray_to_pil(image) out = pil_to_ndarray(pil_image) assert out.shape == shape diff --git a/skimage/io/tests/test_plugin_util.py b/skimage/io/tests/test_plugin_util.py index 38e795f3..069622fb 100644 --- a/skimage/io/tests/test_plugin_util.py +++ b/skimage/io/tests/test_plugin_util.py @@ -1,5 +1,5 @@ from skimage.io._plugins.util import prepare_for_display, WindowManager -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings from numpy.testing import * import numpy as np @@ -9,16 +9,16 @@ np.random.seed(0) class TestPrepareForDisplay: def test_basic(self): - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): prepare_for_display(np.random.rand(10, 10)) def test_dtype(self): - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): x = prepare_for_display(np.random.rand(10, 15)) assert x.dtype == np.dtype(np.uint8) def test_grey(self): - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): tmp = np.arange(12, dtype=float).reshape((4, 3)) / 11 x = prepare_for_display(tmp) assert_array_equal(x[..., 0], x[..., 2]) @@ -26,21 +26,21 @@ class TestPrepareForDisplay: assert x[3, 2, 0] == 255 def test_colour(self): - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): prepare_for_display(np.random.rand(10, 10, 3)) def test_alpha(self): - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): prepare_for_display(np.random.rand(10, 10, 4)) @raises(ValueError) def test_wrong_dimensionality(self): - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): prepare_for_display(np.random.rand(10, 10, 1, 1)) @raises(ValueError) def test_wrong_depth(self): - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): prepare_for_display(np.random.rand(10, 10, 5)) diff --git a/skimage/measure/tests/__init__.py b/skimage/measure/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/measure/tests/__init__.py +++ b/skimage/measure/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/measure/tests/test_fit.py b/skimage/measure/tests/test_fit.py index 4305b04e..c2a71f71 100644 --- a/skimage/measure/tests/test_fit.py +++ b/skimage/measure/tests/test_fit.py @@ -3,7 +3,7 @@ from numpy.testing import assert_equal, assert_raises, assert_almost_equal from skimage.measure import LineModel, CircleModel, EllipseModel, ransac from skimage.transform import AffineTransform from skimage.measure.fit import _dynamic_max_trials -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings def test_line_model_invalid_input(): @@ -256,7 +256,7 @@ def test_deprecated_params_attribute(): model.params = (10, 1) x = np.arange(-10, 10) y = model.predict_y(x) - with all_warnings(): # deprecation + with expected_warnings(['`_params`']): assert_equal(model.params, model._params) diff --git a/skimage/measure/tests/test_regionprops.py b/skimage/measure/tests/test_regionprops.py index 830489d1..fdbabad9 100644 --- a/skimage/measure/tests/test_regionprops.py +++ b/skimage/measure/tests/test_regionprops.py @@ -4,7 +4,7 @@ import numpy as np import math from skimage.measure._regionprops import regionprops, PROPS, perimeter -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings SAMPLE = np.array( @@ -26,16 +26,14 @@ INTENSITY_SAMPLE[1, 9:11] = 2 def test_all_props(): region = regionprops(SAMPLE, INTENSITY_SAMPLE)[0] for prop in PROPS: - with all_warnings(): # deprecation warning - assert_equal(region[prop], getattr(region, PROPS[prop])) + assert_equal(region[prop], getattr(region, PROPS[prop])) def test_dtype(): regionprops(np.zeros((10, 10), dtype=np.int)) regionprops(np.zeros((10, 10), dtype=np.uint)) - with all_warnings(): # deprecation on dtype - assert_raises((TypeError, RuntimeError), regionprops, - np.zeros((10, 10), dtype=np.double)) + assert_raises((TypeError, RuntimeError), regionprops, + np.zeros((10, 10), dtype=np.double)) def test_ndim(): @@ -128,13 +126,13 @@ def test_equiv_diameter(): def test_euler_number(): - with all_warnings(): # deprecation warning + with expected_warnings(['`background`']): en = regionprops(SAMPLE)[0].euler_number assert en == 0 SAMPLE_mod = SAMPLE.copy() SAMPLE_mod[7, -3] = 0 - with all_warnings(): # deprecation warning + with expected_warnings(['`background`']): en = regionprops(SAMPLE_mod)[0].euler_number assert en == -1 @@ -374,7 +372,7 @@ def test_equals(): r2 = regions[0] r3 = regions[1] - with all_warnings(): # deprecation warning + with expected_warnings(['`background`']): assert_equal(r1 == r2, True, "Same regionprops are not equal") assert_equal(r1 != r3, True, "Different regionprops are equal") diff --git a/skimage/morphology/tests/__init__.py b/skimage/morphology/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/morphology/tests/__init__.py +++ b/skimage/morphology/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/morphology/tests/test_binary.py b/skimage/morphology/tests/test_binary.py index 3a3abf97..d52f92bb 100644 --- a/skimage/morphology/tests/test_binary.py +++ b/skimage/morphology/tests/test_binary.py @@ -4,7 +4,7 @@ from numpy import testing from skimage import data, color from skimage.util import img_as_bool from skimage.morphology import binary, grey, selem -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings from scipy import ndimage @@ -15,7 +15,7 @@ bw_img = img > 100 def test_non_square_image(): strel = selem.square(3) binary_res = binary.binary_erosion(bw_img[:100, :200], strel) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): grey_res = img_as_bool(grey.erosion(bw_img[:100, :200], strel)) testing.assert_array_equal(binary_res, grey_res) @@ -23,7 +23,7 @@ def test_non_square_image(): def test_binary_erosion(): strel = selem.square(3) binary_res = binary.binary_erosion(bw_img, strel) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): grey_res = img_as_bool(grey.erosion(bw_img, strel)) testing.assert_array_equal(binary_res, grey_res) @@ -31,7 +31,7 @@ def test_binary_erosion(): def test_binary_dilation(): strel = selem.square(3) binary_res = binary.binary_dilation(bw_img, strel) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): grey_res = img_as_bool(grey.dilation(bw_img, strel)) testing.assert_array_equal(binary_res, grey_res) @@ -39,7 +39,7 @@ def test_binary_dilation(): def test_binary_closing(): strel = selem.square(3) binary_res = binary.binary_closing(bw_img, strel) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): grey_res = img_as_bool(grey.closing(bw_img, strel)) testing.assert_array_equal(binary_res, grey_res) @@ -47,7 +47,7 @@ def test_binary_closing(): def test_binary_opening(): strel = selem.square(3) binary_res = binary.binary_opening(bw_img, strel) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): grey_res = img_as_bool(grey.opening(bw_img, strel)) testing.assert_array_equal(binary_res, grey_res) @@ -57,7 +57,7 @@ def test_selem_overflow(): img = np.zeros((20, 20)) img[2:19, 2:19] = 1 binary_res = binary.binary_erosion(img, strel) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): grey_res = img_as_bool(grey.erosion(img, strel)) testing.assert_array_equal(binary_res, grey_res) diff --git a/skimage/morphology/tests/test_ccomp.py b/skimage/morphology/tests/test_ccomp.py index 569b0e38..901a18b9 100644 --- a/skimage/morphology/tests/test_ccomp.py +++ b/skimage/morphology/tests/test_ccomp.py @@ -1,22 +1,16 @@ import numpy as np from numpy.testing import assert_array_equal, run_module_suite -from skimage.morphology import label as _label +from skimage.measure import label import skimage.measure._ccomp as ccomp -from skimage._shared.utils import all_warnings -np.random.seed(0) +from skimage._shared._warnings import expected_warnings + # The background label value # is supposed to be changed to 0 soon BG = -1 -def label(*args, **kwargs): - """Wrap the label function to avoid deprecation warning""" - with all_warnings(): - return _label(*args, **kwargs) - - class TestConnectedComponents: def setup(self): self.x = np.array([[0, 0, 3, 2, 1, 9], @@ -30,7 +24,8 @@ class TestConnectedComponents: [6, 5, 5, 7, 8, 9]]) def test_basic(self): - assert_array_equal(label(self.x), self.labels) + with expected_warnings(['`background`']): + assert_array_equal(label(self.x), self.labels) # Make sure data wasn't modified assert self.x[0, 2] == 3 @@ -38,7 +33,7 @@ class TestConnectedComponents: def test_random(self): x = (np.random.rand(20, 30) * 5).astype(np.int) - with all_warnings(): + with expected_warnings(['`background`']): labels = label(x) n = labels.max() @@ -50,13 +45,13 @@ class TestConnectedComponents: x = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) - with all_warnings(): + with expected_warnings(['`background`']): assert_array_equal(label(x), x) def test_4_vs_8(self): x = np.array([[0, 1], [1, 0]], dtype=int) - with all_warnings(): + with expected_warnings(['`background`']): assert_array_equal(label(x, 4), [[0, 1], [2, 3]]) @@ -69,7 +64,7 @@ class TestConnectedComponents: [1, 1, 5], [0, 0, 0]]) - with all_warnings(): + with expected_warnings(['`background`']): assert_array_equal(label(x), [[0, 1, 1], [0, 0, 2], [3, 3, 3]]) @@ -105,7 +100,7 @@ class TestConnectedComponents: [0, 0, 6], [5, 5, 5]]) - with all_warnings(): + with expected_warnings(['`background`']): assert_array_equal(label(x, return_num=True)[1], 4) assert_array_equal(label(x, background=0, return_num=True)[1], 3) @@ -147,7 +142,8 @@ class TestConnectedComponents3d: [10, 5, 7, 7, 7]]) def test_basic(self): - labels = label(self.x) + with expected_warnings(['`background`']): + labels = label(self.x) assert_array_equal(labels, self.labels) assert self.x[0, 0, 2] == 2, \ @@ -156,7 +152,7 @@ class TestConnectedComponents3d: def test_random(self): x = (np.random.rand(20, 30) * 5).astype(np.int) - with all_warnings(): + with expected_warnings(['`background`']): labels = label(x) n = labels.max() @@ -169,7 +165,7 @@ class TestConnectedComponents3d: x[0, 2, 2] = 1 x[1, 1, 1] = 1 x[2, 0, 0] = 1 - with all_warnings(): + with expected_warnings(['`background`']): assert_array_equal(label(x), x) def test_4_vs_8(self): @@ -178,7 +174,7 @@ class TestConnectedComponents3d: x[1, 0, 0] = 1 label4 = x.copy() label4[1, 0, 0] = 2 - with all_warnings(): + with expected_warnings(['`background`']): assert_array_equal(label(x, 4), label4) assert_array_equal(label(x, 8), x) @@ -206,7 +202,7 @@ class TestConnectedComponents3d: [BG, 0, 1], [BG, BG, BG]]) - with all_warnings(): + with expected_warnings(['`background`']): assert_array_equal(label(x), lnb) assert_array_equal(label(x, background=0), lb) @@ -244,7 +240,7 @@ class TestConnectedComponents3d: [0, 0, 6], [5, 5, 5]]) - with all_warnings(): + with expected_warnings(['`background`']): assert_array_equal(label(x, return_num=True)[1], 4) assert_array_equal(label(x, background=0, return_num=True)[1], 3) @@ -258,7 +254,8 @@ class TestConnectedComponents3d: (1, xlen, 1), (xlen, 1, 1), (1, 1, xlen)) for reshape in reshapes: x2 = x.reshape(reshape) - labelled = label(x2) + with expected_warnings(['`background`']): + labelled = label(x2) assert_array_equal(y, labelled.flatten()) def test_nd(self): diff --git a/skimage/morphology/tests/test_grey.py b/skimage/morphology/tests/test_grey.py index 9c978105..9961b985 100644 --- a/skimage/morphology/tests/test_grey.py +++ b/skimage/morphology/tests/test_grey.py @@ -7,7 +7,7 @@ from scipy import ndimage import skimage from skimage import data_dir from skimage.morphology import grey, selem -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings lena = np.load(os.path.join(data_dir, 'lena_GRAY_U8.npy')) @@ -172,10 +172,10 @@ def test_3d_fallback_white_tophat(): image[3, 2:5, 2:5] = 1 image[4, 3:5, 3:5] = 1 - with all_warnings(): # scipy upstream warning + with expected_warnings(['operator.*deprecated']): new_image = grey.white_tophat(image) footprint = ndimage.generate_binary_structure(3,1) - with all_warnings(): # scipy upstream warning + with expected_warnings(['operator.*deprecated']): image_expected = ndimage.white_tophat(image,footprint=footprint) testing.assert_array_equal(new_image, image_expected) @@ -185,10 +185,10 @@ def test_3d_fallback_black_tophat(): image[3, 2:5, 2:5] = 0 image[4, 3:5, 3:5] = 0 - with all_warnings(): # scipy upstream warning + with expected_warnings(['operator.*deprecated']): new_image = grey.black_tophat(image) footprint = ndimage.generate_binary_structure(3,1) - with all_warnings(): # scipy upstream warning + with expected_warnings(['operator.*deprecated']): image_expected = ndimage.black_tophat(image,footprint=footprint) testing.assert_array_equal(new_image, image_expected) @@ -223,11 +223,11 @@ class TestDTypes(): self.expected_closing = np.load(fname_closing)[arrname] def _test_image(self, image): - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): result_opening = grey.opening(image, self.disk) testing.assert_equal(result_opening, self.expected_opening) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): result_closing = grey.closing(image, self.disk) testing.assert_equal(result_closing, self.expected_closing) diff --git a/skimage/restoration/tests/__init__.py b/skimage/restoration/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/restoration/tests/__init__.py +++ b/skimage/restoration/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/restoration/tests/test_unwrap.py b/skimage/restoration/tests/test_unwrap.py index 4819ea24..e628f4fe 100644 --- a/skimage/restoration/tests/test_unwrap.py +++ b/skimage/restoration/tests/test_unwrap.py @@ -7,7 +7,7 @@ from numpy.testing import (run_module_suite, assert_array_almost_equal_nulp, import warnings from skimage.restoration import unwrap_phase -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings def assert_phase_almost_equal(a, b, *args, **kwargs): @@ -133,7 +133,7 @@ def test_mask(): assert_array_almost_equal_nulp(image_unwrapped[:, -1], image[i, -1]) # Same tests, but forcing use of the 3D unwrapper by reshaping - with all_warnings(): # 1 dimension + with expected_warnings(['length 1 dimension']): shape = (1,) + image_wrapped.shape image_wrapped_3d = image_wrapped.reshape(shape) image_unwrapped_3d = unwrap_phase(image_wrapped_3d) diff --git a/skimage/segmentation/tests/__init__.py b/skimage/segmentation/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/segmentation/tests/__init__.py +++ b/skimage/segmentation/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/segmentation/tests/test_random_walker.py b/skimage/segmentation/tests/test_random_walker.py index ed68cb0f..5877a817 100644 --- a/skimage/segmentation/tests/test_random_walker.py +++ b/skimage/segmentation/tests/test_random_walker.py @@ -1,7 +1,14 @@ import numpy as np from skimage.segmentation import random_walker from skimage.transform import resize -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings +from skimage._shared.version_requirements import is_installed + + +if is_installed('pyamg'): + PYAMG_EXPECTED_WARNING = [] +else: + PYAMG_EXPECTED_WARNING = ['pyamg'] def make_2d_syntheticdata(lx, ly=None): @@ -75,11 +82,11 @@ def test_2d_cg(): lx = 70 ly = 100 data, labels = make_2d_syntheticdata(lx, ly) - with all_warnings(): # cg mode + with expected_warnings(['"cg" mode']): labels_cg = random_walker(data, labels, beta=90, mode='cg') assert (labels_cg[25:45, 40:60] == 2).all() assert data.shape == labels.shape - with all_warnings(): # cg mode + with expected_warnings(['"cg" mode']): full_prob = random_walker(data, labels, beta=90, mode='cg', return_full_prob=True) assert (full_prob[1, 25:45, 40:60] >= @@ -92,11 +99,11 @@ def test_2d_cg_mg(): lx = 70 ly = 100 data, labels = make_2d_syntheticdata(lx, ly) - with all_warnings(): # pyamg optional + with expected_warnings(PYAMG_EXPECTED_WARNING): labels_cg_mg = random_walker(data, labels, beta=90, mode='cg_mg') assert (labels_cg_mg[25:45, 40:60] == 2).all() assert data.shape == labels.shape - with all_warnings(): # pyamg optional + with expected_warnings(PYAMG_EXPECTED_WARNING): full_prob = random_walker(data, labels, beta=90, mode='cg_mg', return_full_prob=True) assert (full_prob[1, 25:45, 40:60] >= @@ -111,7 +118,7 @@ def test_types(): data, labels = make_2d_syntheticdata(lx, ly) data = 255 * (data - data.min()) // (data.max() - data.min()) data = data.astype(np.uint8) - with all_warnings(): # pyamg optional + with expected_warnings(PYAMG_EXPECTED_WARNING): labels_cg_mg = random_walker(data, labels, beta=90, mode='cg_mg') assert (labels_cg_mg[25:45, 40:60] == 2).all() assert data.shape == labels.shape @@ -145,7 +152,7 @@ def test_3d(): n = 30 lx, ly, lz = n, n, n data, labels = make_3d_syntheticdata(lx, ly, lz) - with all_warnings(): # cg mode + with expected_warnings(['"cg" mode']): labels = random_walker(data, labels, mode='cg') assert (labels.reshape(data.shape)[13:17, 13:17, 13:17] == 2).all() assert data.shape == labels.shape @@ -159,7 +166,7 @@ def test_3d_inactive(): old_labels = np.copy(labels) labels[5:25, 26:29, 26:29] = -1 after_labels = np.copy(labels) - with all_warnings(): # cg mode + with expected_warnings(['"cg" mode']): labels = random_walker(data, labels, mode='cg') assert (labels.reshape(data.shape)[13:17, 13:17, 13:17] == 2).all() assert data.shape == labels.shape @@ -170,11 +177,11 @@ def test_multispectral_2d(): lx, ly = 70, 100 data, labels = make_2d_syntheticdata(lx, ly) data = data[..., np.newaxis].repeat(2, axis=-1) # Expect identical output - with all_warnings(): # cg mode + with expected_warnings(['"cg" mode']): multi_labels = random_walker(data, labels, mode='cg', multichannel=True) assert data[..., 0].shape == labels.shape - with all_warnings(): # cg mode + with expected_warnings(['"cg" mode']): single_labels = random_walker(data[..., 0], labels, mode='cg') assert (multi_labels.reshape(labels.shape)[25:45, 40:60] == 2).all() assert data[..., 0].shape == labels.shape @@ -186,11 +193,11 @@ def test_multispectral_3d(): lx, ly, lz = n, n, n data, labels = make_3d_syntheticdata(lx, ly, lz) data = data[..., np.newaxis].repeat(2, axis=-1) # Expect identical output - with all_warnings(): # cg mode + with expected_warnings(['"cg" mode']): multi_labels = random_walker(data, labels, mode='cg', multichannel=True) assert data[..., 0].shape == labels.shape - with all_warnings(): # cg mode + with expected_warnings(['"cg" mode']): single_labels = random_walker(data[..., 0], labels, mode='cg') assert (multi_labels.reshape(labels.shape)[13:17, 13:17, 13:17] == 2).all() assert (single_labels.reshape(labels.shape)[13:17, 13:17, 13:17] == 2).all() @@ -217,7 +224,7 @@ def test_spacing_0(): lz // 4 - small_l // 8] = 2 # Test with `spacing` kwarg - with all_warnings(): # cg mode + with expected_warnings(['"cg" mode']): labels_aniso = random_walker(data_aniso, labels_aniso, mode='cg', spacing=(1., 1., 0.5)) @@ -245,7 +252,7 @@ def test_spacing_1(): # Test with `spacing` kwarg # First, anisotropic along Y - with all_warnings(): # using cg mode + with expected_warnings(['"cg" mode']): labels_aniso = random_walker(data_aniso, labels_aniso, mode='cg', spacing=(1., 2., 1.)) assert (labels_aniso[13:17, 26:34, 13:17] == 2).all() @@ -265,7 +272,7 @@ def test_spacing_1(): lz // 2 - small_l // 4] = 2 # Anisotropic along X - with all_warnings(): # cg mode + with expected_warnings(['"cg" mode']): labels_aniso2 = random_walker(data_aniso, labels_aniso2, mode='cg', spacing=(2., 1., 1.)) @@ -277,7 +284,7 @@ def test_trivial_cases(): img = np.ones((10, 10)) labels = np.ones((10, 10)) - with all_warnings(): # using provided labels + with expected_warnings(["Returning provided labels"]): pass_through = random_walker(img, labels) np.testing.assert_array_equal(pass_through, labels) @@ -285,7 +292,7 @@ def test_trivial_cases(): labels[:, :5] = 3 expected = np.concatenate(((labels == 1)[..., np.newaxis], (labels == 3)[..., np.newaxis]), axis=2) - with all_warnings(): # using provided labels + with expected_warnings(["Returning provided labels"]): test = random_walker(img, labels, return_full_prob=True) np.testing.assert_array_equal(test, expected) diff --git a/skimage/transform/tests/__init__.py b/skimage/transform/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/transform/tests/__init__.py +++ b/skimage/transform/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/transform/tests/test_geometric.py b/skimage/transform/tests/test_geometric.py index b6e0597f..125faf6c 100644 --- a/skimage/transform/tests/test_geometric.py +++ b/skimage/transform/tests/test_geometric.py @@ -7,7 +7,7 @@ from skimage.transform import (estimate_transform, matrix_transform, SimilarityTransform, AffineTransform, ProjectiveTransform, PolynomialTransform, PiecewiseAffineTransform) -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings SRC = np.array([ @@ -252,11 +252,11 @@ def test_invalid_input(): def test_deprecated_params_attributes(): for t in ('projective', 'affine', 'similarity'): tform = estimate_transform(t, SRC, DST) - with all_warnings(): # _matrix is deprecated + with expected_warnings(['`_matrix`.*deprecated']): assert_equal(tform._matrix, tform.params) tform = estimate_transform('polynomial', SRC, DST, order=3) - with all_warnings(): # _params is deprecated + with expected_warnings(['`_params`.*deprecated']): assert_equal(tform._params, tform.params) diff --git a/skimage/transform/tests/test_hough_transform.py b/skimage/transform/tests/test_hough_transform.py index ae6e0cf6..884d7957 100644 --- a/skimage/transform/tests/test_hough_transform.py +++ b/skimage/transform/tests/test_hough_transform.py @@ -3,7 +3,7 @@ from numpy.testing import assert_almost_equal, assert_equal import skimage.transform as tf from skimage.draw import line, circle_perimeter, ellipse_perimeter -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings def append_desc(func, description): @@ -68,7 +68,7 @@ def test_hough_line_peaks(): out, angles, d = tf.hough_line(img) - with all_warnings(): # _ccomp deprecation + with expected_warnings(['`background`']): out, theta, dist = tf.hough_line_peaks(out, angles, d) assert_equal(len(dist), 1) @@ -81,7 +81,7 @@ def test_hough_line_peaks_dist(): img[:, 30] = True img[:, 40] = True hspace, angles, dists = tf.hough_line(img) - with all_warnings(): # _ccomp deprecation + with expected_warnings(['`background`']): assert len(tf.hough_line_peaks(hspace, angles, dists, min_distance=5)[0]) == 2 assert len(tf.hough_line_peaks(hspace, angles, dists, @@ -89,7 +89,7 @@ def test_hough_line_peaks_dist(): def test_hough_line_peaks_angle(): - with all_warnings(): # _ccomp deprecation + with expected_warnings(['`background`']): check_hough_line_peaks_angle() @@ -124,7 +124,7 @@ def test_hough_line_peaks_num(): img[:, 30] = True img[:, 40] = True hspace, angles, dists = tf.hough_line(img) - with all_warnings(): # _ccomp deprecation + with expected_warnings(['`background`']): assert len(tf.hough_line_peaks(hspace, angles, dists, min_distance=0, min_angle=0, num_peaks=1)[0]) == 1 diff --git a/skimage/transform/tests/test_warps.py b/skimage/transform/tests/test_warps.py index b0c58281..115f0e6f 100644 --- a/skimage/transform/tests/test_warps.py +++ b/skimage/transform/tests/test_warps.py @@ -10,7 +10,7 @@ from skimage.transform import (warp, warp_coords, rotate, resize, rescale, downscale_local_mean) from skimage import transform as tf, data, img_as_float from skimage.color import rgb2gray -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings np.random.seed(0) @@ -198,7 +198,7 @@ def test_swirl(): swirl_params = {'radius': 80, 'rotation': 0, 'order': 2, 'mode': 'reflect'} - with all_warnings(): # deprecation warning + with expected_warnings(['Bi-quadratic.*bug']): swirled = tf.swirl(image, strength=10, **swirl_params) unswirled = tf.swirl(swirled, strength=-10, **swirl_params) diff --git a/skimage/util/tests/__init__.py b/skimage/util/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/util/tests/__init__.py +++ b/skimage/util/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/util/tests/test_dtype.py b/skimage/util/tests/test_dtype.py index 50ad3fc4..4c1f2a43 100644 --- a/skimage/util/tests/test_dtype.py +++ b/skimage/util/tests/test_dtype.py @@ -3,7 +3,7 @@ from numpy.testing import assert_equal, assert_raises from skimage import img_as_int, img_as_float, \ img_as_uint, img_as_ubyte from skimage.util.dtype import convert -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings dtype_range = {np.uint8: (0, 255), @@ -29,9 +29,13 @@ def test_range(): (img_as_float, np.float64), (img_as_uint, np.uint16), (img_as_ubyte, np.ubyte)]: - - with all_warnings(): # precision loss - y = f(x) + + try: + with expected_warnings(['precision loss|sign loss']): + y = f(x) + except ValueError as e: + if not 'No warning raised' in str(e): + raise omin, omax = dtype_range[dt] @@ -62,8 +66,14 @@ def test_range_extra_dtypes(): for dtype_in, dt in dtype_pairs: imin, imax = dtype_range_extra[dtype_in] x = np.linspace(imin, imax, 10).astype(dtype_in) - with all_warnings(): # sign loss - y = convert(x, dt) + + try: + with expected_warnings(['precision loss|sign loss']): + y = convert(x, dt) + except ValueError as e: + if not 'No warning raised' in str(e): + raise + omin, omax = dtype_range_extra[dt] yield (_verify_range, "From %s to %s" % (np.dtype(dtype_in), np.dtype(dt)), diff --git a/skimage/util/tests/test_shape.py b/skimage/util/tests/test_shape.py index ee897e7c..38127df8 100644 --- a/skimage/util/tests/test_shape.py +++ b/skimage/util/tests/test_shape.py @@ -3,7 +3,7 @@ from nose.tools import raises from numpy.testing import assert_equal, assert_warns from skimage.util.shape import view_as_blocks, view_as_windows -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings @raises(TypeError) @@ -153,9 +153,8 @@ def test_views_non_contiguous(): A = np.arange(16).reshape((4, 4)) A = A[::2, :] - with all_warnings(): - assert_warns(RuntimeWarning, view_as_blocks, A, (2, 2)) - assert_warns(RuntimeWarning, view_as_windows, A, (2, 2)) + assert_warns(RuntimeWarning, view_as_blocks, A, (2, 2)) + assert_warns(RuntimeWarning, view_as_windows, A, (2, 2)) if __name__ == '__main__': diff --git a/skimage/viewer/tests/__init__.py b/skimage/viewer/tests/__init__.py index c098c64d..9c11267a 100644 --- a/skimage/viewer/tests/__init__.py +++ b/skimage/viewer/tests/__init__.py @@ -1,2 +1,9 @@ -from skimage._shared.testing import setup_test -setup_test() +from skimage._shared.testing import setup_test, teardown_test + + +def setup(): + setup_test() + + +def tearDown(): + teardown_test() diff --git a/skimage/viewer/tests/test_plugins.py b/skimage/viewer/tests/test_plugins.py index 6ad180fb..528df8f4 100644 --- a/skimage/viewer/tests/test_plugins.py +++ b/skimage/viewer/tests/test_plugins.py @@ -12,7 +12,7 @@ from skimage.viewer.plugins import ( PlotPlugin) from skimage.viewer.plugins.base import Plugin from skimage.viewer.widgets import Slider -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings def setup_line_profile(image, limits='image'): @@ -67,7 +67,7 @@ def test_line_profile_dynamic(): assert_almost_equal(np.std(line), 0.229, 3) assert_almost_equal(np.max(line) - np.min(line), 0.725, 1) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): viewer.image = skimage.img_as_float(median(image, selem=disk(radius=3))) @@ -161,7 +161,7 @@ def test_plugin(): viewer = ImageViewer(img) def median_filter(img, radius=3): - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): return median(img, selem=disk(radius=radius)) plugin = Plugin(image_filter=median_filter) diff --git a/skimage/viewer/tests/test_viewer.py b/skimage/viewer/tests/test_viewer.py index 553a8be3..1604ca6d 100644 --- a/skimage/viewer/tests/test_viewer.py +++ b/skimage/viewer/tests/test_viewer.py @@ -8,7 +8,7 @@ from skimage.filters import sobel from numpy.testing import assert_equal from numpy.testing.decorators import skipif from skimage._shared.version_requirements import is_installed -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings @skipif(not viewer_available) @@ -68,7 +68,7 @@ def test_viewer_with_overlay(): ov.color = 3 assert_equal(ov.color, 'yellow') - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): viewer.save_to_file(filename) ov.display_filtered_image(img) assert_equal(ov.overlay, img) diff --git a/skimage/viewer/tests/test_widgets.py b/skimage/viewer/tests/test_widgets.py index 439454f3..170c186c 100644 --- a/skimage/viewer/tests/test_widgets.py +++ b/skimage/viewer/tests/test_widgets.py @@ -8,7 +8,7 @@ from skimage.viewer.plugins.base import Plugin from skimage.viewer.qt import QtGui, QtCore from numpy.testing import assert_almost_equal, assert_equal from numpy.testing.decorators import skipif -from skimage._shared.utils import all_warnings +from skimage._shared._warnings import expected_warnings def get_image_viewer(): @@ -100,12 +100,12 @@ def test_save_buttons(): timer.singleShot(100, QtGui.QApplication.quit) sv.save_to_stack() - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): sv.save_to_file(filename) img = data.imread(filename) - with all_warnings(): # precision loss + with expected_warnings(['precision loss']): assert_almost_equal(img, img_as_uint(viewer.image)) img = io.pop()