diff --git a/skimage/graph/tests/test_mcp.py b/skimage/graph/tests/test_mcp.py index 1f62915262b..6bf8f97466d 100644 --- a/skimage/graph/tests/test_mcp.py +++ b/skimage/graph/tests/test_mcp.py @@ -11,10 +11,10 @@ a[1:-1, 1] = 0 a[1, 1:-1] = 0 +warning_optional = r'|\A\Z' def test_basic(): - optional = r'|\A\Z' - with expected_warnings(['Upgrading NumPy' + optional]): + with expected_warnings(['Upgrading NumPy' + warning_optional]): m = mcp.MCP(a, fully_connected=True) costs, traceback = m.find_costs([(1, 6)]) return_path = m.traceback((7, 2)) @@ -56,15 +56,13 @@ def test_neg_inf(): (6, 1)] test_neg = np.where(a == 1, -1, 0) test_inf = np.where(a == 1, np.inf, 0) - optional = r'|\A\Z' - with expected_warnings(['Upgrading NumPy' + optional]): + with expected_warnings(['Upgrading NumPy' + warning_optional]): m = mcp.MCP(test_neg, fully_connected=True) costs, traceback = m.find_costs([(1, 6)]) return_path = m.traceback((6, 1)) assert_array_equal(costs, expected_costs) assert_array_equal(return_path, expected_path) - optional = r'|\A\Z' - with expected_warnings(['Upgrading NumPy' + optional]): + with expected_warnings(['Upgrading NumPy' + warning_optional]): m = mcp.MCP(test_inf, fully_connected=True) costs, traceback = m.find_costs([(1, 6)]) return_path = m.traceback((6, 1)) @@ -73,8 +71,7 @@ def test_neg_inf(): def test_route(): - optional = r'|\A\Z' - with expected_warnings(['Upgrading NumPy' + optional]): + with expected_warnings(['Upgrading NumPy' + warning_optional]): return_path, cost = mcp.route_through_array(a, (1, 6), (7, 2), geometric=True) assert_almost_equal(cost, np.sqrt(2) / 2) @@ -93,8 +90,7 @@ def test_route(): def test_no_diagonal(): - optional = r'|\A\Z' - with expected_warnings(['Upgrading NumPy' + optional]): + with expected_warnings(['Upgrading NumPy' + warning_optional]): m = mcp.MCP(a, fully_connected=False) costs, traceback = m.find_costs([(1, 6)]) return_path = m.traceback((7, 2)) @@ -125,8 +121,7 @@ def test_no_diagonal(): def test_offsets(): offsets = [(1, i) for i in range(10)] + [(1, -i) for i in range(1, 10)] - optional = r'|\A\Z' - with expected_warnings(['Upgrading NumPy' + optional]): + with expected_warnings(['Upgrading NumPy' + warning_optional]): m = mcp.MCP(a, offsets=offsets) costs, traceback = m.find_costs([(1, 6)]) assert_array_equal(traceback, @@ -152,8 +147,7 @@ def _test_random(shape): (np.random.rand(len(shape)) * shape).astype(int)] ends = [(np.random.rand(len(shape)) * shape).astype(int) for i in range(4)] - optional = r'|\A\Z' - with expected_warnings(['Upgrading NumPy' + optional]): + with expected_warnings(['Upgrading NumPy' + warning_optional]): m = mcp.MCP(a, fully_connected=True) costs, offsets = m.find_costs(starts) for point in [(np.random.rand(len(shape)) * shape).astype(int)