mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-01 12:50:48 +08:00
Update docstring and fix pyamg warning check
This commit is contained in:
@@ -84,9 +84,16 @@ def expected_warnings(matching):
|
||||
-----
|
||||
Uses `all_warnings` to ensure all warnings are raised.
|
||||
Upon exiting, it checks the recorded warnings for the desired matching
|
||||
string. Raises a warning if the match was not found or an Unexpected
|
||||
warning is found. You can pass an empty regex as on of the matches
|
||||
to allow for no matches: "\A\Z".
|
||||
pattern(s).
|
||||
Raises a ValueError if any match was not found or an unexpected
|
||||
warning was raised.
|
||||
Allows for three types of behaviors: "and", "or", and "optional" matches.
|
||||
This is done to accomodate different build enviroments or loop conditions
|
||||
that may produce different warnings. The behaviors can be combined.
|
||||
If you pass multiple patterns, you get an orderless "and", where all of the
|
||||
warnings must be raised.
|
||||
If you use the "|" operator in a pattern, you can catch one of several warnings.
|
||||
Finally, you can use "|\A\Z" in a pattern to signify it as optional.
|
||||
|
||||
"""
|
||||
with all_warnings() as w:
|
||||
|
||||
@@ -2,13 +2,8 @@ import numpy as np
|
||||
from skimage.segmentation import random_walker
|
||||
from skimage.transform import resize
|
||||
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']
|
||||
PYAMG_EXPECTED_WARNING = 'pyamg|\A\Z'
|
||||
|
||||
|
||||
def make_2d_syntheticdata(lx, ly=None):
|
||||
@@ -99,11 +94,11 @@ def test_2d_cg_mg():
|
||||
lx = 70
|
||||
ly = 100
|
||||
data, labels = make_2d_syntheticdata(lx, ly)
|
||||
with expected_warnings('%s|\A\Z' % PYAMG_EXPECTED_WARNING):
|
||||
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 expected_warnings(PYAMG_EXPECTED_WARNING):
|
||||
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] >=
|
||||
@@ -118,7 +113,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 expected_warnings(PYAMG_EXPECTED_WARNING):
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user