From 2be0221a288bd21e7a9601193a76287d95f0dba7 Mon Sep 17 00:00:00 2001 From: Luca Carniato Date: Wed, 29 Jan 2025 16:09:46 +0100 Subject: [PATCH] Fix unit tests --- meshkernel/meshkernel.py | 13 ++++--------- tests/test_curvilinear_basics.py | 4 ++-- tests/test_mesh2d_basics.py | 11 +++++++---- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/meshkernel/meshkernel.py b/meshkernel/meshkernel.py index 6098d4bb..9f28f97d 100644 --- a/meshkernel/meshkernel.py +++ b/meshkernel/meshkernel.py @@ -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), ) diff --git a/tests/test_curvilinear_basics.py b/tests/test_curvilinear_basics.py index 71038cea..81b10153 100644 --- a/tests/test_curvilinear_basics.py +++ b/tests/test_curvilinear_basics.py @@ -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(): diff --git a/tests/test_mesh2d_basics.py b/tests/test_mesh2d_basics.py index 06a38f7a..a47fc043 100644 --- a/tests/test_mesh2d_basics.py +++ b/tests/test_mesh2d_basics.py @@ -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(): @@ -2311,6 +2311,7 @@ def test_mesh2d_deletion_and_get_orthogonality( cases_get_property = [ ( Mesh2d.Property.ORTHOGONALITY, + Mesh2dLocation.EDGES, np.array( [ -999.0, @@ -2343,6 +2344,7 @@ def test_mesh2d_deletion_and_get_orthogonality( ), ( Mesh2d.Property.EDGE_LENGTHS, + Mesh2dLocation.EDGES, np.array( [ 100.0, @@ -2377,12 +2379,13 @@ 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, @@ -2390,7 +2393,7 @@ def test_mesh2d_get_property( """ 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)