Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacarniato committed Jan 29, 2025
1 parent e682133 commit 2be0221
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
13 changes: 4 additions & 9 deletions meshkernel/meshkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1648,40 +1648,35 @@ def mesh2d_get_orthogonality(self) -> GeometryList:

return geometry_list_out

def mesh2d_get_property(self, property: Mesh2d.Property) -> GeometryList:
def mesh2d_get_property(
self, mesh2dLocation: Mesh2dLocation, property: Mesh2d.Property
) -> GeometryList:
"""Gets the polygons matching the metric value within the minimum and maximum value.
Args:
property (Mesh2d.Property): The property to retrieve
Returns:
GeometryList: The resulting geometry list containing the value of the properties
"""

c_geometry_list_dimension = c_int()

self._execute_function(
self.lib.mkernel_mesh2d_get_property_dimension,
self._meshkernelid,
c_int(property),
byref(c_geometry_list_dimension),
)

n_coordinates = c_geometry_list_dimension.value
x_coordinates = np.empty(n_coordinates, dtype=np.double)
y_coordinates = np.empty(n_coordinates, dtype=np.double)
values = np.empty(n_coordinates, dtype=np.double)

property_list = GeometryList(
x_coordinates=x_coordinates, y_coordinates=y_coordinates, values=values
)
c_property_list = CGeometryList.from_geometrylist(property_list)

self._execute_function(
self.lib.mkernel_mesh2d_get_property,
self._meshkernelid,
c_int(property),
c_int(mesh2dLocation.value),
byref(c_property_list),
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_curvilinear_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ def test_curvilinear_line_attraction_repulsion():
# Get the result
curvilinear_grid = mk.curvilineargrid_get()

# Test a node on the third grid line was shifted from 20 to 15
assert curvilinear_grid.node_x[2] == 15.0
# Test a node on the third grid line was shifted from 20 to 25
assert curvilinear_grid.node_x[2] == 25.0


def test_curvilinear_line_mirror():
Expand Down
11 changes: 7 additions & 4 deletions tests/test_mesh2d_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,8 @@ def test_mesh2d_make_global():
mk.mesh2d_make_global(num_longitude_nodes, num_latitude_nodes)
mesh2d = mk.mesh2d_get()

assert mesh2d.edge_x.size == 1233
assert mesh2d.node_x.size == 629
assert mesh2d.edge_x.size == 1225
assert mesh2d.node_x.size == 621


def test_mesh2d_make_global_with_cartesian_coordinates_should_throw():
Expand Down Expand Up @@ -2311,6 +2311,7 @@ def test_mesh2d_deletion_and_get_orthogonality(
cases_get_property = [
(
Mesh2d.Property.ORTHOGONALITY,
Mesh2dLocation.EDGES,
np.array(
[
-999.0,
Expand Down Expand Up @@ -2343,6 +2344,7 @@ def test_mesh2d_deletion_and_get_orthogonality(
),
(
Mesh2d.Property.EDGE_LENGTHS,
Mesh2dLocation.EDGES,
np.array(
[
100.0,
Expand Down Expand Up @@ -2377,20 +2379,21 @@ def test_mesh2d_deletion_and_get_orthogonality(


@pytest.mark.parametrize(
"property, expected_values",
"property, location, expected_values",
cases_get_property,
)
def test_mesh2d_get_property(
meshkernel_with_mesh2d: MeshKernel,
property: Mesh2d.Property,
location: Mesh2dLocation,
expected_values: ndarray,
):
"""Test mesh2d_get_property,
getting the mesh2d property values
"""
mk = meshkernel_with_mesh2d(rows=3, columns=3, spacing_x=50.0, spacing_y=100.0)

property_list = mk.mesh2d_get_property(property)
property_list = mk.mesh2d_get_property(location, property)

assert property_list.values == approx(expected_values, abs=1e-6)

Expand Down

0 comments on commit 2be0221

Please sign in to comment.