Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import warnings

import numpy as np
import pytest

from xarray_subset_grid.utils import (
assign_ugrid_topology,
normalize_bbox_x_coords,
normalize_polygon_x_coords,
ray_tracing_numpy,
Expand Down Expand Up @@ -125,3 +127,23 @@ def test_ray_tracing_numpy():
result = ray_tracing_numpy(points[:, 0], points[:, 1], poly)

assert np.array_equal(result, [False, True, False])


def test_assign_ugrid_topology_warns_with_deprecation_warning(monkeypatch):
def fake_assign_ugrid_topology(*args, **kwargs):
return "ok"

monkeypatch.setattr(
"xarray_subset_grid.grids.ugrid.assign_ugrid_topology",
fake_assign_ugrid_topology,
)

with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
result = assign_ugrid_topology(None)

assert result == "ok"
assert len(caught) == 1
assert caught[0].category is DeprecationWarning
assert "assign_ugrid_topology" in str(caught[0].message)
assert os.path.basename(caught[0].filename) == "test_utils.py"
7 changes: 4 additions & 3 deletions xarray_subset_grid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ def ray_tracing_numpy(x, y, poly):
# this placeholder for backwards compatibility for a brief period
def assign_ugrid_topology(*args, **kwargs):
warnings.warn(
DeprecationWarning,
"The function `assign_grid_topology` has been moved to the "
"The function `assign_ugrid_topology` has been moved to the "
"`grids.ugrid` module. It will not be able to be called from "
"the utils `module` in the future.",
"the utils module in the future.",
category=DeprecationWarning,
stacklevel=2,
)
from .grids.ugrid import assign_ugrid_topology

Expand Down